Skip to content

Commit

Permalink
add fallback
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Jul 18, 2023
1 parent 78966d8 commit a88a8b6
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,29 @@ func (c *ResourceGroupsController) IsBackgroundRequest(ctx context.Context,

gc.metaLock.RLock()
defer gc.metaLock.RUnlock()
if bg := gc.meta.BackgroundSettings; bg != nil {
if len(requestResource) == 0 || len(bg.JobTypes) == 0 {
return c.checkBackgroundSettings(ctx, gc.meta.BackgroundSettings, requestResource)
}

func (c *ResourceGroupsController) checkBackgroundSettings(ctx context.Context, bg *rmpb.BackgroundSettings, requestResource string) bool {
// fallback to default resource group.
if bg == nil {
resourceGroupName := "default"
gc, err := c.tryGetResourceGroup(ctx, resourceGroupName)
if err != nil {
failedRequestCounter.WithLabelValues(resourceGroupName).Inc()
return false

Check warning on line 499 in client/resource_group/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

client/resource_group/controller/controller.go#L498-L499

Added lines #L498 - L499 were not covered by tests
}
if idx := strings.LastIndex(requestResource, "_"); idx != -1 {
return slices.Contains(bg.JobTypes, requestResource[idx+1:])
}
bg = gc.meta.BackgroundSettings
}

if bg == nil || len(requestResource) == 0 || len(bg.JobTypes) == 0 {
return false

Check warning on line 505 in client/resource_group/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

client/resource_group/controller/controller.go#L505

Added line #L505 was not covered by tests
}

if idx := strings.LastIndex(requestResource, "_"); idx != -1 {
return slices.Contains(bg.JobTypes, requestResource[idx+1:])
}

return false

Check warning on line 512 in client/resource_group/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

client/resource_group/controller/controller.go#L512

Added line #L512 was not covered by tests
}

Expand Down

0 comments on commit a88a8b6

Please sign in to comment.