You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/08 17:03:22 UTC
[GitHub] csantanapr closed pull request #136: disable a throttled alarms trigger if retries are exhausted
csantanapr closed pull request #136: disable a throttled alarms trigger if retries are exhausted
URL: https://github.com/apache/incubator-openwhisk-package-alarms/pull/136
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index 75125d8..ba38adf 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -79,7 +79,7 @@ module.exports = function(logger, triggerDB, redisClient) {
});
};
- this.postTrigger = function(dataTrigger, auth, retryCount) {
+ this.postTrigger = function(dataTrigger, auth, retryCount, throttleCount) {
var method = 'postTrigger';
return new Promise(function(resolve, reject) {
@@ -103,11 +103,14 @@ module.exports = function(logger, triggerDB, redisClient) {
logger.info(method, triggerIdentifier, 'http post request, STATUS:', response ? response.statusCode : undefined);
if (error || response.statusCode >= 400) {
+ logger.error(method, 'there was an error invoking', triggerIdentifier, response ? response.statusCode : error);
+ var throttleCounter = throttleCount || 0;
+
// only manage trigger fires if they are not infinite
if (dataTrigger.maxTriggers && dataTrigger.maxTriggers !== -1) {
dataTrigger.triggersLeft++;
}
- logger.error(method, 'there was an error invoking', triggerIdentifier, response ? response.statusCode : error);
+
if (!error && utils.shouldDisableTrigger(response.statusCode)) {
//disable trigger
var message = 'Automatically disabled after receiving a ' + response.statusCode + ' status code when firing the trigger';
@@ -116,18 +119,26 @@ module.exports = function(logger, triggerDB, redisClient) {
}
else {
if (retryCount < retryAttempts) {
+ throttleCounter = response && response.statusCode === HttpStatus.TOO_MANY_REQUESTS ? throttleCounter + 1 : throttleCounter;
logger.info(method, 'attempting to fire trigger again', triggerIdentifier, 'Retry Count:', (retryCount + 1));
setTimeout(function () {
- utils.postTrigger(dataTrigger, auth, (retryCount + 1))
+ utils.postTrigger(dataTrigger, auth, (retryCount + 1), throttleCounter)
.then(triggerId => {
resolve(triggerId);
})
.catch(err => {
reject(err);
});
- }, retryDelay);
+ }, Math.max(retryDelay, 1000 * Math.pow(throttleCounter, 2)));
} else {
- reject('Unable to reach server to fire trigger ' + triggerIdentifier);
+ if (throttleCounter === retryAttempts) {
+ var msg = 'Automatically disabled after continuously receiving a 429 status code when firing the trigger';
+ utils.disableTrigger(triggerIdentifier, 429, msg);
+ reject('Disabled trigger ' + triggerIdentifier + ' due to status code: 429');
+ }
+ else {
+ reject('Unable to reach server to fire trigger ' + triggerIdentifier);
+ }
}
}
} else {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services