Skip to content

Commit

Permalink
No retry option should disable retry policy (#1064)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Apr 24, 2023
1 parent 61f6792 commit 97e1fef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/common/models/cluster/cluster.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { expect, use } from "chai";
import equivalent from "../../../client/utils/test-utils/equivalent";
import { RequestDecorator } from "../../../server/utils/request-decorator/request-decorator";
import { RetryOptions } from "../../../server/utils/retry-options/retry-options";
import { RetryOptions, RetryOptionsJS } from "../../../server/utils/retry-options/retry-options";
import { NOOP_LOGGER } from "../../logger/logger";
import { ClusterAuthJS } from "../cluster-auth/cluster-auth";
import { Cluster, ClusterJS, fromConfig } from "./cluster";
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("Cluster", () => {
healthCheckTimeout: 1000,
introspectionStrategy: "segment-metadata-fallback",
requestDecorator: null,
retry: new RetryOptions(),
retry: undefined,
sourceListRefreshInterval: 0,
sourceListRefreshOnLoad: false,
sourceListScan: "auto",
Expand Down Expand Up @@ -119,6 +119,16 @@ describe("Cluster", () => {
expect(cluster.retry).to.be.equivalent(new RetryOptions({ maxAttempts: 1, delay: 42 }));
});

it("should read partial retry options", () => {
const cluster = buildCluster({
retry: {
delay: 42
} as RetryOptionsJS
});

expect(cluster.retry).to.be.equivalent(new RetryOptions({ maxAttempts: 5, delay: 42 }));
});

it("should read request decorator", () => {
const cluster = buildCluster({
name: "foobar",
Expand Down Expand Up @@ -185,7 +195,7 @@ describe("Cluster", () => {
version: "new-version",
type: "druid",
requestDecorator: null,
retry: new RetryOptions(),
retry: undefined,
auth: undefined
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/common/models/cluster/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ function readRequestDecorator(cluster: any, logger: Logger): RequestDecorator |
return null;
}

function readRetryOptions(options: RetryOptionsJS | undefined): RetryOptions | undefined {
if (isNil(options)) return undefined;
return new RetryOptions(options);
}

const DEFAULT_HEALTH_CHECK_TIMEOUT = 1000;
export const DEFAULT_SOURCE_LIST_SCAN: SourceListScan = "auto";
const SOURCE_LIST_SCAN_VALUES: SourceListScan[] = ["disable", "auto"];
Expand Down Expand Up @@ -167,7 +172,7 @@ export function fromConfig(params: ClusterJS, logger: Logger): Cluster {
const sourceReintrospectInterval = readInterval(params.sourceReintrospectInterval, DEFAULT_SOURCE_REINTROSPECT_INTERVAL);
const sourceListRefreshInterval = readInterval(params.sourceListRefreshInterval, DEFAULT_SOURCE_LIST_REFRESH_INTERVAL);
const sourceTimeBoundaryRefreshInterval = readInterval(params.sourceTimeBoundaryRefreshInterval, DEFAULT_SOURCE_TIME_BOUNDARY_REFRESH_INTERVAL);
const retry = RetryOptions.fromJS(params.retry);
const retry = readRetryOptions(params.retry);
const requestDecorator = readRequestDecorator(params, logger);
const auth = readClusterAuth(params.auth);

Expand Down
3 changes: 2 additions & 1 deletion src/server/utils/requester/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function setRetryOptions({ maxAttempts, delay }: RetryOptions) {
requester,
retry: maxAttempts,
delay,
retryOnTimeout: true });
retryOnTimeout: true
});
}

function setVerbose(requester: PlywoodRequester<any>) {
Expand Down

0 comments on commit 97e1fef

Please sign in to comment.