Skip to content

Commit

Permalink
fix(parallel_best): set typeName to "random" when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Nov 19, 2023
1 parent 2c3f36b commit 3a47cc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions resolver/parallel_best_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ func newParallelBestResolver(
resolverStatuses = append(resolverStatuses, newUpstreamResolverStatus(r))
}

typeName := "parallel_best"
resolverCount := parallelBestResolverCount
retryWithDifferentResolver := false

if config.GetConfig().Upstreams.Strategy == config.UpstreamStrategyRandom {
typeName = "random"
resolverCount = 1
retryWithDifferentResolver = true
}

r := ParallelBestResolver{
configurable: withConfig(&cfg),
typed: withType(parallelResolverType),
typed: withType(typeName),

groupName: cfg.Name,
resolvers: resolverStatuses,
Expand All @@ -144,8 +146,7 @@ func (r *ParallelBestResolver) String() string {
result[i] = fmt.Sprintf("%s", s.resolver)
}

return fmt.Sprintf("%s (resolverCount: %d, retryWithDifferentResolver: %t) upstreams '%s (%s)'",
parallelResolverType, r.resolverCount, r.retryWithDifferentResolver, r.groupName, strings.Join(result, ","))
return fmt.Sprintf("%s upstreams '%s (%s)'", r.Type(), r.groupName, strings.Join(result, ","))
}

// Resolve sends the query request to multiple upstream resolvers and returns the fastest result
Expand All @@ -164,7 +165,6 @@ func (r *ParallelBestResolver) Resolve(request *model.Request) (*model.Response,
if r.resolverCount == 1 {
var cancel context.CancelFunc

logger = log.WithPrefix(logger, "random")
timeout := config.GetConfig().Upstreams.Timeout

ctx, cancel = context.WithTimeout(ctx, time.Duration(timeout))
Expand Down
2 changes: 1 addition & 1 deletion resolver/parallel_best_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
Describe("Name", func() {
It("should contain correct resolver", func() {
Expect(sut.Name()).ShouldNot(BeEmpty())
Expect(sut.Name()).Should(ContainSubstring(parallelResolverType))
Expect(sut.Name()).Should(ContainSubstring(randomResolverType))
})
})

Expand Down

0 comments on commit 3a47cc2

Please sign in to comment.