Skip to content

Commit

Permalink
Retry Options (#699)
Browse files Browse the repository at this point in the history
* Add RetryOption property on Cluster

* Pass RetryOptions to Requester factory

* Linter fixes

* Retry on timeout

* Disable recording videos on e2e

* Add documentation
  • Loading branch information
adrianmroz-allegro authored Feb 2, 2021
1 parent 8e3d6e7 commit 5d6a844
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"video": false,
"viewportWidth": 1280,
"viewportHeight": 1024
}
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ Define this to override the automatic version detection.

The timeout to set on the queries in ms.

**retry** (object)

Options for retries on Druid native queries. If no object is provided Turnilo will not retry failed queries.
Object should have following structure:

```yaml
retry:
maxAttempts: 10
delay: 1000
```
* `maxAttempts` is count of maximum attempts for retry. Default values is 5
* `delay` is time in ms between each attempt.

**healthCheckTimeout** (number), default: 1000

The timeout for the cluster health checking request in ms. See [Checking health of Turnilo instance](health-checking.md)
Expand Down
3 changes: 3 additions & 0 deletions src/common/models/cluster/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BackCompat, BaseImmutable, Property } from "immutable-class";
import { External } from "plywood";
import { URL } from "url";
import { RequestDecorator, RequestDecoratorJS } from "../../../server/utils/request-decorator/request-decorator";
import { RetryOptions } from "../../../server/utils/retry-options/retry-options";
import { isNil, isTruthy, verifyUrlSafeName } from "../../utils/general/general";

export type SourceListScan = "disable" | "auto";
Expand Down Expand Up @@ -115,6 +116,7 @@ export class Cluster extends BaseImmutable<ClusterValue, ClusterJS> {
{ name: "title", defaultValue: "" },
{ name: "version", defaultValue: null },
{ name: "timeout", defaultValue: Cluster.DEFAULT_TIMEOUT },
{ name: "retry", defaultValue: null, immutableClass: RetryOptions },
{ name: "healthCheckTimeout", defaultValue: Cluster.DEFAULT_HEALTH_CHECK_TIMEOUT },
{ name: "sourceListScan", defaultValue: Cluster.DEFAULT_SOURCE_LIST_SCAN, possibleValues: Cluster.SOURCE_LIST_SCAN_VALUES },
{ name: "sourceListRefreshOnLoad", defaultValue: Cluster.DEFAULT_SOURCE_LIST_REFRESH_ON_LOAD },
Expand Down Expand Up @@ -160,6 +162,7 @@ export class Cluster extends BaseImmutable<ClusterValue, ClusterJS> {
public title: string;
public version: string;
public timeout: number;
public retry: RetryOptions;
public healthCheckTimeout: number;
public sourceListScan: SourceListScan;
public sourceListRefreshOnLoad: boolean;
Expand Down
14 changes: 9 additions & 5 deletions src/server/utils/requester/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { DruidRequestDecorator, druidRequesterFactory } from "plywood-druid-requ
import { URL } from "url";
import { Cluster } from "../../../common/models/cluster/cluster";
import { threadConditionally } from "../../../common/utils/functional/functional";
import { RetryOptions } from "../retry-options/retry-options";

export interface ProperRequesterOptions {
cluster: Cluster;
retry?: number;
verbose?: boolean;
concurrentLimit?: number;
druidRequestDecorator?: DruidRequestDecorator;
Expand Down Expand Up @@ -63,8 +63,12 @@ function createDruidRequester(cluster: Cluster, requestDecorator?: DruidRequestD
return druidRequesterFactory({ host, timeout, requestDecorator, protocol });
}

function setRetryOptions(retry: number) {
return (requester: PlywoodRequester<any>) => retryRequesterFactory({ requester, retry, delay: 500, retryOnTimeout: false });
function setRetryOptions({ maxAttempts, delay }: RetryOptions) {
return (requester: PlywoodRequester<any>) => retryRequesterFactory({
requester,
retry: maxAttempts,
delay,
retryOnTimeout: true });
}

function setVerbose(requester: PlywoodRequester<any>) {
Expand All @@ -76,10 +80,10 @@ function setConcurrencyLimit(concurrentLimit: number) {
}

export function properRequesterFactory(options: ProperRequesterOptions): PlywoodRequester<any> {
const { cluster, druidRequestDecorator, retry, verbose, concurrentLimit } = options;
const { cluster, druidRequestDecorator, verbose, concurrentLimit } = options;
return threadConditionally(
createDruidRequester(cluster, druidRequestDecorator),
retry && setRetryOptions(retry),
cluster.retry && setRetryOptions(cluster.retry),
verbose && setVerbose,
concurrentLimit && setConcurrencyLimit(concurrentLimit)
);
Expand Down
42 changes: 42 additions & 0 deletions src/server/utils/retry-options/retry-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2017-2021 Allegro.pl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { BaseImmutable, Property } from "immutable-class";

interface RetryOptionsValue {
maxAttempts: number;
delay: number;
}

interface RetryOptionsJS {
maxAttempts: number;
delay: number;
}

export class RetryOptions extends BaseImmutable<RetryOptionsValue, RetryOptionsJS> {

static PROPERTIES: Property[] = [
{ name: "maxAttempts", defaultValue: 5 },
{ name: "delay", defaultValue: 5000 }
];

static fromJS(options: RetryOptionsJS): RetryOptions {
return new RetryOptions(BaseImmutable.jsToValue(RetryOptions.PROPERTIES, options));
}

public maxAttempts: number;
public delay: number;
}

0 comments on commit 5d6a844

Please sign in to comment.