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

Commit

Permalink
HAWKULAR-466 : Resuming implementation of Datasource alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
ammendonca committed Aug 25, 2015
1 parent e2981f6 commit 4964bdf
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<div ng-switch-when="GARBA">
<strong>Garbage collection</strong>: The garbage collection took more than {{alert.avg | number:2}} ms.
</div>
<div ng-switch-when="DSCONN">
<strong>Available Connections</strong>: The number of available connections was {{alert.avg}}.
</div>
<div ng-switch-when="DSRESP">
<strong>Responsiveness</strong>: The connection {{alert.condition}} was {{alert.avg}}ms.
</div>
<div ng-switch-default>
<strong>Alert</strong>: <code>{{alert}}</code>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4 class="modal-title">Datasource Alert Settings</h4>
</div>
<div class="col-sm-4">
<hk-switch hk-model="das.adm.conn.conditionEnabled"
id="usage-greater-switch" class="pull-right"></hk-switch>
id="dsc-connections-switch" class="pull-right"></hk-switch>
</div>
</div>
</fieldset>
Expand All @@ -45,29 +45,29 @@ <h4 class="modal-title">Datasource Alert Settings</h4>
<fieldset>
<legend>Wait Time</legend>
<div class="form-group">
<label class="col-sm-3 control-label" for="dsc-connections">Less than</label>
<label class="col-sm-3 control-label" for="dsc-wait">Greater than</label>
<div class="col-sm-5">
<input ng-model="das.adm.resp.waitTimeThreshold"
type="number" min="0" value="200" class="form-control hk-input-small" id="dsc-connections">
<input ng-model="das.adm.resp.waitTimeThreshold" ng-disabled="!das.adm.resp.waitTimeEnabled"
type="number" min="0" value="200" class="form-control hk-input-small" id="dsc-wait">
</div>
<div class="col-sm-4">
<hk-switch hk-model="das.adm.resp.waitTimeEnabled"
id="usage-greater-switch" class="pull-right"></hk-switch>
id="dsc-wait-switch" class="pull-right"></hk-switch>
</div>
</div>
</fieldset>

<fieldset>
<legend>Creation Time</legend>
<div class="form-group">
<label class="col-sm-3 control-label" for="dsc-connections">Less than</label>
<label class="col-sm-3 control-label" for="dsc-creation">Greater than</label>
<div class="col-sm-5">
<input ng-model="das.adm.resp.creationTimeThreshold"
type="number" min="0" value="200" class="form-control hk-input-small" id="dsc-connections">
<input ng-model="das.adm.resp.creationTimeThreshold" ng-disabled="!das.adm.resp.creationTimeEnabled"
type="number" min="0" value="200" class="form-control hk-input-small" id="dsc-creation">
</div>
<div class="col-sm-4">
<hk-switch hk-model="das.adm.resp.creationTimeEnabled"
id="usage-greater-switch" class="pull-right"></hk-switch>
id="dsc-creation-switch" class="pull-right"></hk-switch>
</div>
</div>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module HawkularMetrics {

var connDefinitionPromise = this.HawkularAlertsManager.getAlertDefinition(connTriggerId)
.then((alertDefinitionData) => {
this.$log.debug('alertDefinitionData', alertDefinitionData);
this.$log.debug('alertDefinitionData', 'conn', alertDefinitionData);
this.triggerDefinition['conn'] = alertDefinitionData;

this.adm['conn'] = {};
Expand All @@ -46,25 +46,36 @@ module HawkularMetrics {
var respDefinitionPromise = this.HawkularAlertsManager.getAlertDefinition(respTriggerId)
.then((alertDefinitionData) => {

this.$log.debug('alertDefinitionData', alertDefinitionData);
this.$log.debug('alertDefinitionData', 'resp', alertDefinitionData);
this.triggerDefinition['resp'] = alertDefinitionData;

this.adm['resp'] = {};
this.adm.resp['email'] = alertDefinitionData.trigger.actions.email[0];
this.adm.resp['responseDuration'] = alertDefinitionData.dampenings[0].evalTimeSetting;

var idCreation = 0,
idWait = 1;

if (alertDefinitionData.conditions[1].dataId.indexOf('Creation') > -1) {
idCreation = 1;
idWait = 0;
if (alertDefinitionData.conditions.length > 0) {
var idCreation = 0,
idWait = 1;

if (alertDefinitionData.conditions[0].dataId.indexOf('Creation') === -1) {
idCreation = 1;
idWait = 0;
}

if (alertDefinitionData.conditions[idWait]) {
this.adm.resp['waitTimeThreshold'] = alertDefinitionData.conditions[idWait].threshold;
this.adm.resp['waitTimeEnabled'] = !!alertDefinitionData.conditions[idWait].threshold;
}
if (alertDefinitionData.conditions[idCreation]) {
this.adm.resp['creationTimeThreshold'] = alertDefinitionData.conditions[idCreation].threshold;
this.adm.resp['creationTimeEnabled'] = !!alertDefinitionData.conditions[idCreation].threshold;
}
}

this.adm.resp['waitTimeThreshold'] = alertDefinitionData.conditions[idWait].threshold;
this.adm.resp['waitTimeEnabled'] = !!alertDefinitionData.conditions[idWait].threshold;
this.adm.resp['creationTimeThreshold'] = alertDefinitionData.conditions[idCreation].threshold;
this.adm.resp['creationTimeEnabled'] = !!alertDefinitionData.conditions[idCreation].threshold;
this.adm.resp['waitTimeThreshold'] = this.adm.resp['waitTimeThreshold'] ||
AppServerDatasourcesDetailsController.DEFAULT_WAIT_THRESHOLD;
this.adm.resp['creationTimeThreshold'] = this.adm.resp['creationTimeThreshold'] ||
AppServerDatasourcesDetailsController.DEFAULT_CREA_THRESHOLD;
});


Expand All @@ -79,7 +90,7 @@ module HawkularMetrics {
if (this.adm.conn.conditionEnabled) {
connAlertDefinition.trigger.actions.email[0] = this.adm.conn.email;
connAlertDefinition.dampenings[0].evalTimeSetting = this.adm.conn.responseDuration;
connAlertDefinition.conditions[0].treshold = this.adm.conn.conditionThreshold;
connAlertDefinition.conditions[0].threshold = this.adm.conn.conditionThreshold;
}

var connSavePromise = this.HawkularAlertsManager.saveAlertDefinition(connAlertDefinition,
Expand All @@ -90,7 +101,7 @@ module HawkularMetrics {

var idCreation = 0,
idWait = 1;
if (respAlertDefinition.conditions[1].dataId.indexOf('Creation') > -1) {
if (respAlertDefinition.conditions[0] && respAlertDefinition.conditions[0].dataId.indexOf('Creation') === -1) {
idCreation = 1;
idWait = 0;
}
Expand All @@ -111,15 +122,15 @@ module HawkularMetrics {
respAlertDefinition.conditions[idWait].conditionId);

delete respAlertDefinition.conditions[idWait];
} else if (this.adm.resp.waitTimeEnabled && !this.adm.resp.waitTimeEnabled) {
} else if (this.adm.resp.waitTimeEnabled && !this.admBak.resp.waitTimeEnabled) {
// create
var resId = respTriggerId.slice(0,-8);

condWaitPromise = this.HawkularAlertsManager.createCondition(respTriggerId, {
triggerId: respTriggerId,
type: 'THRESHOLD',
dataId: 'MI~R~[' + resId + ']~MT~Datasource Pool Metrics~Average Get Time',
threshold: respAlertDefinition.conditions[idWait].treshold,
threshold: this.adm.resp.waitTimeThreshold,
operator: 'GT'
});
} else {
Expand All @@ -128,14 +139,41 @@ module HawkularMetrics {

var condCreaDefer = this.$q.defer();
var condCreaPromise = condCreaDefer.promise;
condCreaDefer.resolve();
var self = this;

// FIXME: The condition id changes if previous was added/deleted ..
if (!self.adm.resp.creationTimeEnabled && self.admBak.resp.creationTimeEnabled) {
// delete
condCreaPromise = self.HawkularAlertsManager.deleteCondition(respTriggerId,
respAlertDefinition.conditions[idCreation].conditionId);

delete respAlertDefinition.conditions[idCreation];
} else if (self.adm.resp.creationTimeEnabled && !self.admBak.resp.creationTimeEnabled) {
// create
resId = respTriggerId.slice(0,-8);

condCreaPromise = self.HawkularAlertsManager.createCondition(respTriggerId, {
triggerId: respTriggerId,
type: 'THRESHOLD',
dataId: 'MI~R~[' + resId + ']~MT~Datasource Pool Metrics~Average Creation Time',
threshold: self.adm.resp.creationTimeThreshold,
operator: 'GT'
});
} else {
condCreaDefer.resolve();
}

respAlertDefinition.conditions[idWait].treshhold = this.adm.resp.waitTimeThreshold;
respAlertDefinition.conditions[idCreation].treshhold = this.adm.resp.creationTimeThreshold;
if (respAlertDefinition.conditions[idWait]) {
respAlertDefinition.conditions[idWait].threshold = this.adm.resp.waitTimeThreshold;
}
if (respAlertDefinition.conditions[idCreation]) {
respAlertDefinition.conditions[idCreation].threshold = this.adm.resp.creationTimeThreshold;
}

var respSavePromise = this.HawkularAlertsManager.saveAlertDefinition(respAlertDefinition,
errorCallback, this.triggerDefinition.resp);

console.log('@PROMISES', connSavePromise, respSavePromise, condWaitPromise, condCreaPromise);
return [connSavePromise, respSavePromise, condWaitPromise, condCreaPromise];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ module HawkularMetrics {
public static WAIT_COLOR = '#d5d026'; /// yellow
public static CREATION_COLOR = '#95489c'; /// purple

public static DEFAULT_CONN_THRESHOLD = 200; // < 200 # connections available
public static DEFAULT_WAIT_THRESHOLD = 200; // > 200 ms average wait time
public static DEFAULT_CREA_THRESHOLD = 200; // > 200 ms average creatiion time

private autoRefreshPromise: ng.IPromise<number>;
private resourceList;
private expandedList;
Expand Down Expand Up @@ -73,6 +77,36 @@ module HawkularMetrics {
this.autoRefresh(20);
}

private getAlerts(metricIdPrefix:string, startTime:TimestampInMillis, endTime:TimestampInMillis):void {
var pheapArray: any, nheapArray: any, garbaArray:any;
var pheapPromise = this.HawkularAlertsManager.queryAlerts(metricIdPrefix + '_ds_conn', startTime, endTime)
.then((pheapData)=> {
_.forEach(pheapData.alertList, (item) => {
item['alertType']='DSCONN';
item['condition']=item['dataId'].substr(item['dataId'].lastIndexOf('~')+1);
});
pheapArray = pheapData.alertList;
}, (error) => {
//return this.ErrorsManager.errorHandler(error, 'Error fetching alerts.');
});

var nheapPromise = this.HawkularAlertsManager.queryAlerts(metricIdPrefix + '_ds_resp', startTime, endTime)
.then((nheapData)=> {
_.forEach(nheapData.alertList, (item) => {
item['alertType']='DSRESP';
item['condition']=item['dataId'].substr(item['dataId'].lastIndexOf('~')+1);
});
nheapArray = nheapData.alertList;
}, (error) => {
//return this.ErrorsManager.errorHandler(error, 'Error fetching alerts.');
});


this.$q.all([pheapPromise, nheapPromise]).finally(()=> {
this.alertList = [].concat(pheapArray, nheapArray);
});
}

public openSetup(resId):void {
// Check if trigger exists on alerts setup modal open. If not, create the trigger before opening the modal

Expand All @@ -93,7 +127,7 @@ module HawkularMetrics {
triggerId: triggerId,
type: 'THRESHOLD',
dataId: dataId,
threshold: 200,
threshold: AppServerDatasourcesDetailsController.DEFAULT_CONN_THRESHOLD,
operator: 'LT'
});
});
Expand All @@ -114,19 +148,19 @@ module HawkularMetrics {
triggerId: triggerId,
type: 'THRESHOLD',
dataId: dataId,
threshold: 200,
operator: 'GT'
});
}).then(()=> {
var triggerId:string = resId + '_ds_resp';
var dataId:string = 'MI~R~[' + resId + ']~MT~Datasource Pool Metrics~Average Creation Time';

return this.HawkularAlertsManager.createCondition(triggerId, {
triggerId: triggerId,
type: 'THRESHOLD',
dataId: dataId,
threshold: 200,
threshold: AppServerDatasourcesDetailsController.DEFAULT_WAIT_THRESHOLD,
operator: 'GT'
}).then(()=> {
var triggerId:string = resId + '_ds_resp';
var dataId:string = 'MI~R~[' + resId + ']~MT~Datasource Pool Metrics~Average Creation Time';

return this.HawkularAlertsManager.createCondition(triggerId, {
triggerId: triggerId,
type: 'THRESHOLD',
dataId: dataId,
threshold: AppServerDatasourcesDetailsController.DEFAULT_CREA_THRESHOLD,
operator: 'GT'
});
});
});

Expand Down Expand Up @@ -181,7 +215,6 @@ module HawkularMetrics {
}

public getDatasources(currentTenantId?: TenantId): any {
this.alertList = []; // FIXME: when we have alerts for app server
this.endTimeStamp = this.$routeParams.endTime || +moment();
this.startTimeStamp = this.endTimeStamp - (this.$routeParams.timeOffset || 3600000);

Expand All @@ -203,6 +236,7 @@ module HawkularMetrics {
distinct: true}, (data) => {
res.inUseCount = data[0];
}).$promise);
this.getAlerts(res.id, this.startTimeStamp, this.endTimeStamp);
}
}, this);
this.$q.all(promises).then((result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ module HawkularMetrics {
var serverAlert = serverAlerts[i];

consoleAlert.id = serverAlert.alertId;

consoleAlert.dataId = serverAlert.evalSets[0][0].condition.dataId;

consoleAlert.end = serverAlert.ctime;

var sum: number = 0.0;
Expand Down

0 comments on commit 4964bdf

Please sign in to comment.