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 #190 from vrockai/HAWKULAR-272
Browse files Browse the repository at this point in the history
HAWKULAR-272: Fixed alert settings time-related bugs
  • Loading branch information
mtho11 committed Jun 4, 2015
2 parents 64f9ff9 + ca6c749 commit 98149cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ <h4 class="modal-title">Alert Settings</h4>
<div class="col-md-6 inline-row">
<div class="input-group duration">
<input type="number" class="form-control" placeholder="Duration" ng-model="mas.downtimeDuration"
ng-change="mas.changeDowntimeTimeUnits()" id="downtimeDuration"
ng-change="mas.alertSettingTouch()">
id="downtimeDuration" ng-change="mas.alertSettingTouch()">
<select pf-select ng-model="mas.downtimeUnit" id="downtimeUnit"
ng-options="item.value as item.label for item in mas.timeUnits"
ng-change="mas.changeDowntimeTimeUnits()"></select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,12 @@ section {
}
}

.alert-settings {
.input-group-btn {
width: auto;
}
}

/* Toastr Overrides */

#toast-container > div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module HawkularMetrics {
public saveProgress: boolean = false;
public responseDuration: number;
public downtimeDuration: number;
public responseUnit: number = 60000;
public responseUnit: number = 1;
public downtimeUnit: number = 1;
public thresDampDurationEnabled = false;

Expand All @@ -133,14 +133,14 @@ module HawkularMetrics {
{value: 1, label: 'miliseconds'},
{value: 1000, label: 'seconds'},
{value: 60000, label: 'minutes'},
{value: 360000, label: 'hours'}
{value: 3600000, label: 'hours'}
];

public timeUnitsDict = {
'1': 'miliseconds',
'1000': 'seconds',
'60000': 'minutes',
'360000': 'hours'
'3600000': 'hours'
};

constructor(public $scope:any,
Expand Down Expand Up @@ -171,6 +171,7 @@ module HawkularMetrics {
this.trigger_thres_damp = data;
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.alertSetupBackup.responseDuration = angular.copy(this.responseDuration);

Expand Down Expand Up @@ -199,7 +200,11 @@ module HawkularMetrics {
}).then((data)=> {
this.trigger_avail_damp = data;
this.alertSetupBackup.trigger_avail_damp = angular.copy(this.trigger_avail_damp);
this.downtimeDuration = data[0].evalTimeSetting;

this.downtimeUnit = this.getTimeUnit(data[0].evalTimeSetting);
this.downtimeDuration = data[0].evalTimeSetting / this.downtimeUnit;
this.alertSetupBackup.downtimeDuration = angular.copy(this.downtimeDuration);

this.$log.debug('this.trigger_avail_damp', this.trigger_avail_damp);
}, (error)=> {
return this.HawkularErrorManager.errorHandler(error, 'Error fetching availability trigger dampening.');
Expand All @@ -209,14 +214,26 @@ module HawkularMetrics {
this.$log.debug('this.metricId', this.metricId);
}

// Get the most meaningful time unit (so that time value is not a very long fraction).
private getTimeUnit(timeValue: number): number {
var timeUnit = 1;

for (var i = 0; i < this.timeUnits.length; i++) {
var unit = this.timeUnits[i].value;
if (timeValue % unit === 0 && unit > timeUnit) {
timeUnit = unit;
}
}

return timeUnit;
}

public changeResponseTimeUnits():void {
this.trigger_thres_damp[0].evalTimeSetting = this.responseDuration * this.responseUnit;
this.alertSettingTouch();
this.responseDuration = this.trigger_thres_damp[0].evalTimeSetting / this.responseUnit;
}

public changeDowntimeTimeUnits():void {
this.trigger_avail_damp[0].evalTimeSetting = this.downtimeDuration * this.downtimeUnit;
this.alertSettingTouch();
this.downtimeDuration = this.trigger_avail_damp[0].evalTimeSetting / this.downtimeUnit;
}

public cancel(): void {
Expand Down Expand Up @@ -254,8 +271,6 @@ module HawkularMetrics {
}, (error)=> {
return this.HawkularErrorManager.errorHandler(error, 'Error updating threshold trigger.', errorCallback);
}).then(()=> {
this.changeResponseTimeUnits();

if (!this.thresDampDurationEnabled) {
this.trigger_thres_damp[0].evalTimeSetting = 0;
}
Expand Down Expand Up @@ -296,6 +311,8 @@ module HawkularMetrics {
}

public alertSettingTouch(): void {
this.trigger_thres_damp[0].evalTimeSetting = this.responseDuration * this.responseUnit;
this.trigger_avail_damp[0].evalTimeSetting = this.downtimeDuration * this.downtimeUnit;

if (!angular.equals(!!this.alertSetupBackup.thresDampDurationEnabled,!!this.thresDampDurationEnabled) ||
!angular.equals(this.alertSetupBackup.responseDuration, this.responseDuration) ||
Expand Down

0 comments on commit 98149cf

Please sign in to comment.