Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #257 from vrockai/HAWKULAR-367
Browse files Browse the repository at this point in the history
HAWKULAR-367: Consolidate Multiple Alert firings
  • Loading branch information
mtho11 committed Jun 25, 2015
2 parents fa7e547 + 2772762 commit eab5aa6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module HawkularMetrics {
deleteTrigger(triggerId: string): ng.IPromise<void>;
createCondition(triggerId: string, condition: any): ng.IPromise<void>;
updateCondition(triggerId: string, conditionId: string, condition: any): ng.IPromise<void>;
createDampening(triggerId: string, duration: number): ng.IPromise<void>;
createDampening(triggerId: string, duration: number, triggerMode?: string): ng.IPromise<void>;
updateDampening(triggerId: string, dampeningId: string, dampening: any): ng.IPromise<void>;
getAction(email: string): ng.IPromise<void>;
getActions(triggerId: string): ng.IPromise<void>;
Expand All @@ -57,6 +57,9 @@ module HawkularMetrics {
public createTrigger(triggerName: string, enabled: boolean, conditionType: string, email: string): ng.IPromise<void> {
// Create a trigger
var triggerId: string;
var DEFAULT_RESOLVE_THRESHOLD = 1000;
var DEFAULT_DAMPENING_INTERVAL = 7 * 60000;
var DEFAULT_AUTORESOLVE_INTERVAL = 5 * 60000;

return this.HawkularAlert.Trigger.save({
name: triggerName,
Expand All @@ -65,7 +68,7 @@ module HawkularMetrics {
firingMatch: 'ALL',
autoResolveMatch: 'ALL',
enabled: enabled,
autoResolve: false,
autoResolve: true,
actions: {email: [email]}
}).$promise.then((trigger)=> {

Expand All @@ -76,24 +79,43 @@ module HawkularMetrics {

// Create a conditions for that trigger
if (conditionType === 'THRESHOLD') {
return this.createCondition(triggerId,{
return this.createCondition(triggerId, {
type: conditionType,
triggerId: triggerId,
threshold: 1000,
threshold: DEFAULT_RESOLVE_THRESHOLD,
dataId: dataId,
operator: 'GT'
}).then(()=> {
return this.createCondition(triggerId, {
type: conditionType,
triggerId: triggerId,
triggerMode: 'AUTORESOLVE',
threshold: DEFAULT_RESOLVE_THRESHOLD,
dataId: dataId,
operator: 'LT'
});
});
} else if (conditionType === 'AVAILABILITY') {
return this.createCondition(triggerId, {
type: conditionType,
triggerId: triggerId,
dataId: trigger.name.slice(0,-14),
operator: 'DOWN'
}).then(()=> {
return this.createCondition(triggerId, {
type: conditionType,
triggerId: triggerId,
triggerMode: 'AUTORESOLVE',
dataId: trigger.name.slice(0,-14),
operator: 'UP'
});
});
}
}).then(() => {
// Create dampening for that trigger
return this.createDampening(triggerId, 7 * 60000);
return this.createDampening(triggerId, DEFAULT_DAMPENING_INTERVAL);
}).then(() => {
return this.createDampening(triggerId, DEFAULT_AUTORESOLVE_INTERVAL, 'AUTORESOLVE');
});
}

Expand Down Expand Up @@ -151,10 +173,11 @@ module HawkularMetrics {
return this.HawkularAlert.Condition.put({triggerId: triggerId, conditionId: conditionId}, condition).$promise;
}

createDampening(triggerId: string, duration: number): ng.IPromise<void> {
createDampening(triggerId: string, duration: number, triggerMode?: string): ng.IPromise<void> {
return this.HawkularAlert.Dampening.save({ triggerId: triggerId }, {
triggerId: triggerId,
evalTimeSetting: duration,
triggerMode: triggerMode || 'FIRING',
type: 'STRICT_TIME'
}).$promise;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,31 @@ module HawkularMetrics {
}, (error)=> {
return this.HawkularErrorManager.errorHandler(error, 'Error fetching threshold trigger.');
}).then((data)=> {
this.trigger_thres_damp = data;

// Make sure, the AUTORESOLVE entity is the 2nd one
this.trigger_thres_damp = [];
this.trigger_thres_damp[0] = data[data[1].triggerMode === 'AUTORESOLVE' ? 0 : 1];
this.trigger_thres_damp[1] = data[data[1].triggerMode === 'AUTORESOLVE' ? 1 : 0];

this.alertSetupBackup.trigger_thres_damp = angular.copy(this.trigger_thres_damp);

this.responseUnit = this.getTimeUnit(data[0].evalTimeSetting);
this.responseDuration = data[0].evalTimeSetting / this.responseUnit;
this.responseUnit = this.getTimeUnit(this.trigger_thres_damp[0].evalTimeSetting);
this.responseDuration = this.trigger_thres_damp[0].evalTimeSetting / this.responseUnit;
this.alertSetupBackup.responseDuration = angular.copy(this.responseDuration);

this.thresDampDurationEnabled = data[0].evalTimeSetting !== 0;
this.thresDampDurationEnabled = this.trigger_thres_damp[0].evalTimeSetting !== 0;
this.alertSetupBackup.thresDampDurationEnabled = angular.copy(this.thresDampDurationEnabled);
this.$log.debug('this.trigger_thres_damp', this.trigger_thres_damp);
return HawkularAlert.Condition.query({triggerId: $routeParams.resourceId + '_trigger_thres'}).$promise;
}, (error)=> {
return this.HawkularErrorManager.errorHandler(error, 'Error fetching threshold trigger dampening.');
}).then((data)=> {
this.trigger_thres_cond = data;

// Make sure, the AUTORESOLVE condition is the 2nd one
this.trigger_thres_cond = [];
this.trigger_thres_cond[0] = data[data[1].triggerMode === 'AUTORESOLVE' ? 0 : 1];
this.trigger_thres_cond[1] = data[data[1].triggerMode === 'AUTORESOLVE' ? 1 : 0];

this.alertSetupBackup.trigger_thres_cond = angular.copy(this.trigger_thres_cond);
this.$log.debug('this.trigger_thres_cond', this.trigger_thres_cond);
}, (error)=> {
Expand Down Expand Up @@ -299,7 +309,12 @@ module HawkularMetrics {
return this.HawkularErrorManager.errorHandler(error, 'Error updating threshold trigger dampening.', errorCallback);
}).then(()=> {
if(!angular.equals(this.alertSetupBackup.trigger_thres_cond[0], this.trigger_thres_cond[0])) {
return this.HawkularAlertsManager.updateCondition(this.trigger_thres.id, this.trigger_thres_cond[0].conditionId, this.trigger_thres_cond[0]);
return this.HawkularAlertsManager.updateCondition(this.trigger_thres.id, this.trigger_thres_cond[0].conditionId, this.trigger_thres_cond[0]).then(()=> {
// Update the threshold on AUTORESOLVE condition
var autoResolveCondition = angular.copy(this.trigger_thres_cond[1]);
autoResolveCondition.threshold = this.trigger_thres_cond[0].threshold;
return this.HawkularAlertsManager.updateCondition(this.trigger_thres.id, autoResolveCondition.conditionId, autoResolveCondition);
});
}
}, (error)=> {
return this.HawkularErrorManager.errorHandler(error, 'Error updating availability dampening.', errorCallback);
Expand Down

0 comments on commit eab5aa6

Please sign in to comment.