Skip to content

Commit

Permalink
fix(webhooks): addresses issue 3450 - introduce a delay before pollin…
Browse files Browse the repository at this point in the history
…g webhook (#7144)

* fix(webhooks): addresses issue 3450 - introduce a delay before polling webhook

Add additional parameters to the monitored webhook to allow:
* waiting some number of seconds before polling starts
* retrying on specific HTTP status codes

see #3450

orca counterpart (spinnaker/orca#2984)
  • Loading branch information
marchello2000 committed Jun 24, 2019
1 parent 7238d1d commit 456172b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/scripts/modules/core/src/help/help.contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ const helpContents: { [key: string]: string } = {
"Pick the status url from the JSON returned by the webhook's response call.",
'pipeline.config.webhook.statusUrlJsonPath':
"JSON path to the status url in the webhook's response JSON. (i.e. <samp>$.buildInfo.url</samp>)",
'pipeline.config.webhook.retryStatusCodes':
'Normally, webhook stages only retry on 429 and 5xx status codes. <br>You can specify additional status codes here that will cause the monitor to retry (e.g. <samp>404, 418</samp>)',
'pipeline.config.webhook.waitBeforeMonitor':
'Optional delay (in seconds) to wait before starting to poll the endpoint for monitoring status',
'pipeline.config.webhook.statusJsonPath':
"JSON path to the status information in the webhook's response JSON. (e.g. <samp>$.buildInfo.status</samp>)",
'pipeline.config.webhook.progressJsonPath':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@
</div>
</div>
</div>
<stage-config-field
label="Delay before monitoring"
help-key="pipeline.config.webhook.waitBeforeMonitor"
ng-if="$ctrl.displayField('waitBeforeMonitor')"
>
<input type="text" class="form-control input-sm" ng-model="$ctrl.stage.waitBeforeMonitor" />
</stage-config-field>
<stage-config-field
label="Retry HTTP Statuses"
help-key="pipeline.config.webhook.retryStatusCodes"
ng-if="$ctrl.displayField('retryStatusCodes')"
>
<input
type="text"
class="form-control input-sm"
ng-model="$ctrl.viewState.retryStatusCodes"
ng-change="$ctrl.retryCodesChanged()"
/>
</stage-config-field>
<stage-config-field
label="Status JsonPath"
help-key="pipeline.config.webhook.statusJsonPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IWebhookStageViewState {
waitForCompletion?: boolean;
statusUrlResolution: string;
failFastStatusCodes: string;
retryStatusCodes: string;
}

export interface IWebhookStageCommand {
Expand Down Expand Up @@ -56,6 +57,7 @@ export class WebhookStage implements IController {
waitForCompletion: this.stage.waitForCompletion || false,
statusUrlResolution: this.stage.statusUrlResolution || 'getMethod',
failFastStatusCodes: this.stage.failFastStatusCodes ? this.stage.failFastStatusCodes.join() : '',
retryStatusCodes: this.stage.retryStatusCodes ? this.stage.retryStatusCodes.join() : '',
};

this.command = {
Expand All @@ -72,6 +74,7 @@ export class WebhookStage implements IController {
stageConfig.configuration.waitForCompletion || this.viewState.waitForCompletion;
this.parameters = stageConfig.configuration.parameters || [];
this.viewState.failFastStatusCodes = this.stage.failFastStatusCodes ? this.stage.failFastStatusCodes.join() : '';
this.viewState.retryStatusCodes = this.stage.retryStatusCodes ? this.stage.retryStatusCodes.join() : '';
}

if (this.parameters.length && !this.stage.parameterValues) {
Expand Down Expand Up @@ -110,6 +113,12 @@ export class WebhookStage implements IController {
this.stage.failFastStatusCodes = failFastCodes.map(x => parseInt(x, 10)).filter(x => !isNaN(x));
}

public retryCodesChanged(): void {
const retryCodes = this.viewState.retryStatusCodes.split(',').map(x => x.trim());

this.stage.retryStatusCodes = retryCodes.map(x => parseInt(x, 10)).filter(x => !isNaN(x));
}

public customHeaderCount(): number {
return this.stage.customHeaders ? Object.keys(this.stage.customHeaders).length : 0;
}
Expand Down

0 comments on commit 456172b

Please sign in to comment.