Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Availability refactor #97

Merged
merged 4 commits into from Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions dist/hawkular-ui-components-accounts.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions dist/hawkular-ui-components-alerts.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/hawkular-ui-components-directives.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/hawkular-ui-components-inventory.js

Large diffs are not rendered by default.

81 changes: 34 additions & 47 deletions dist/hawkular-ui-components-metrics.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions plugins/metrics/plugins/metrics/html/availability.html
Expand Up @@ -10,7 +10,7 @@ <h1>Availability</h1>
<span class="item">Availability</span>
</div>
<div class="col-md-3 summary-item">
<span class="data">{{vm.downtimeDuration / 1000 | number:0}}s</span>
<span class="data">{{vm.downtimeDuration / 1000 | number:0}} s</span>
<span class="item">Total Downtime Duration</span>
</div>
<div class="col-md-3 summary-item">
Expand All @@ -25,17 +25,17 @@ <h1>Availability</h1>
</div>
</div>

<div class="panel panel-default graph">
<div class="update pull-right" ng-show="vm.availabilityDataPoints.length > 0" >
<i class="fa fa-clock-o"></i><a ng-click="vm.refreshAvailPageNow(vm.getRawMetricId())"><strong>Last update</strong> 20 seconds ago</a>
</div>
<!--<div class="panel panel-default graph">-->
<!--<div class="update pull-right" ng-show="vm.availabilityDataPoints.length > 0" >-->
<!--<i class="fa fa-clock-o"></i><a ng-click="vm.refreshAvailPageNow(vm.getRawMetricId())"><strong>Last update</strong> 20 seconds ago</a>-->
<!--</div>-->

<h3>Chart Placeholder</h3>
<!--<hawkular-chart-->
<!--<h2>Avail points: {{vm.availabilityDataPoints.length}}</h2>-->
<!--<availability-chart-->
<!--data="{{vm.availabilityDataPoints}}"-->
<!--chart-type="availability"-->
<!--chart-height="250">-->
<!--</hawkular-chart>-->
</div>
<!--</availability-chart>-->
<!--</div>-->

</section>
1 change: 0 additions & 1 deletion plugins/metrics/plugins/metrics/ts/addUrlPage.ts
Expand Up @@ -81,7 +81,6 @@ module HawkularMetrics {

this.$log.info('Adding new Resource Url to Hawkular-inventory: ' + url);

globalChartTimeRange = new ChartTimeRange(1);
var metricId: string;
var defaultEmail = this.$rootScope['user_email'] ? this.$rootScope['user_email'] : 'myemail@company.com';
var err = (error: any, msg: string): void => this.HawkularErrorManager.errorHandler(error, msg);
Expand Down
58 changes: 27 additions & 31 deletions plugins/metrics/plugins/metrics/ts/metricsAvailabilityPage.ts
Expand Up @@ -13,12 +13,16 @@
/// See the License for the specific language governing permissions and
/// limitations under the License.

/// <reference path="metricsTypes.ts"/>
/// <reference path="metricsPlugin.ts"/>
/// <reference path="../../includes.ts"/>

module HawkularMetrics {


//


export interface IAvailabilitySummary {
start: number;
end: number;
Expand All @@ -29,7 +33,6 @@ module HawkularMetrics {
empty:boolean;
}


export class MetricsAvailabilityController {
/// for minification only
public static $inject = ['$scope', '$interval', '$log', 'HawkularMetric', '$routeParams'];
Expand All @@ -39,47 +42,47 @@ module HawkularMetrics {
private $log:ng.ILogService,
private HawkularMetric:any,
private $routeParams:any,
public startTimeStamp:number,
public endTimeStamp:number) {
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis) {
$scope.vm = this;

this.startTimeStamp = +moment().subtract(1, 'hours');
this.endTimeStamp = +moment();

this.metricId = $scope.hkParams.resourceId;
this.resourceId = $scope.hkParams.resourceId;

$scope.$watch('hkParams.resourceId', (resourceId) => {
$scope.$watch('hkParams.resourceId', (resourceId:ResourceId) => {
/// made a selection from url switcher
if (resourceId) {
this.metricId = resourceId;
this.refreshAvailPageNow(this.getRawMetricId());
this.resourceId = resourceId;
this.refreshAvailPageNow(this.getResourceId());
}
});

$scope.$on('RefreshAvailabilityChart', (event) => {
this.refreshAvailPageNow(this.getRawMetricId());
this.refreshAvailPageNow(this.getResourceId());
});

this.autoRefreshAvailability(20);
}

private availabilityDataPoints:IChartDataPoint[] = [];
private autoRefreshPromise:ng.IPromise<number>;
private metricId;
private resourceId:ResourceId;

uptimeRatio = 0;
downtimeDuration = 0;
lastDowntime:Date;
downtimeCount = 0;
empty = true;

refreshAvailPageNow(rawMetricId:string, startTime?:number):void {
refreshAvailPageNow(resourceId:ResourceId, startTime?:number):void {
this.$scope.hkEndTimestamp = +moment();
var adjStartTimeStamp:number = +moment().subtract(this.$scope.hkParams.timeOffset, 'milliseconds');
this.endTimeStamp = this.$scope.hkEndTimestamp;
if (rawMetricId) {
this.refreshSummaryAvailabilityData(rawMetricId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
this.refreshAvailDataForTimestamp(rawMetricId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
if (resourceId) {
this.refreshSummaryAvailabilityData(resourceId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
this.refreshAvailDataForTimestamp(resourceId, startTime ? startTime : adjStartTimeStamp, this.endTimeStamp);
}
}

Expand All @@ -88,18 +91,17 @@ module HawkularMetrics {
toastr.info('Canceling Auto Refresh Availability');
}

autoRefreshAvailability(intervalInSeconds:number):void {
autoRefreshAvailability(intervalInSeconds:TimestampInMillis):void {
this.endTimeStamp = this.$scope.hkEndTimestamp;
this.startTimeStamp = this.$scope.hkStartTimestamp;
this.$log.debug("first time through Availability page raw metricId is: " + this.getRawMetricId());
this.refreshAvailPageNow(this.getRawMetricId());
this.refreshAvailPageNow(this.getResourceId());
this.autoRefreshPromise = this.$interval(() => {
console.info('Autorefresh Availabilty for: ' + this.getRawMetricId());
console.info('Autorefresh Availabilty for: ' + this.getResourceId());
this.$scope.hkEndTimestamp = +moment();
this.endTimeStamp = this.$scope.hkEndTimestamp;
this.$scope.hkStartTimestamp = +moment().subtract(this.$scope.hkParams.timeOffset, 'milliseconds');
this.startTimeStamp = this.$scope.hkStartTimestamp;
this.refreshAvailPageNow(this.getRawMetricId());
this.refreshAvailPageNow(this.getResourceId());
}, intervalInSeconds * 1000);

this.$scope.$on('$destroy', () => {
Expand All @@ -112,7 +114,7 @@ module HawkularMetrics {
///toastr.warning('No Data found for id: ' + id);
}

refreshSummaryAvailabilityData(metricId:string, startTime:number, endTime:number):void {
refreshSummaryAvailabilityData(metricId:MetricId, startTime:TimestampInMillis, endTime:TimestampInMillis):void {

if (metricId) {
this.HawkularMetric.AvailabilityMetricData.query({
Expand Down Expand Up @@ -144,32 +146,26 @@ module HawkularMetrics {
}


getRawMetricId():string {
return this.metricId;
getResourceId():ResourceId {
return this.resourceId;
}


refreshAvailDataForTimestamp(metricId:string, startTime:number, endTime:number):void {
refreshAvailDataForTimestamp(metricId:MetricId, startTime:TimestampInMillis, endTime:TimestampInMillis):void {

if (metricId) {
this.HawkularMetric.AvailabilityMetricData.query({
tenantId: globalTenantId,
availabilityId: metricId,
start: startTime,
end: endTime,
buckets: 60
distinct: true
}).$promise
.then((response) => {

console.info("Availability Data: ");
console.log("Availability Data: ");
console.dir(response);

if (this.availabilityDataPoints.length) {
this.availabilityDataPoints = response;

} else {
this.noDataFoundForId(this.getRawMetricId());
}
this.availabilityDataPoints = response;

}, (error) => {
this.$log.error('Error Loading Avail data');
Expand Down
18 changes: 0 additions & 18 deletions plugins/metrics/plugins/metrics/ts/metricsGlobals.ts
Expand Up @@ -32,22 +32,4 @@ module HawkularMetrics {

export var globalEnvironmentId = "test";

export var globalChartTimeRange:ChartTimeRange;

export class ChartTimeRange {
startTimestamp:number;
endTimestamp:number;

constructor(private initialHoursDifference:number) {
/// just set a default if no ctors given
this.init();
}

init() {
this.endTimestamp = moment().valueOf();
this.startTimestamp = moment().subtract(this.initialHoursDifference, 'hours').valueOf();
}

}

}
34 changes: 19 additions & 15 deletions plugins/metrics/plugins/metrics/ts/metricsResponsePage.ts
Expand Up @@ -13,6 +13,7 @@
/// See the License for the specific language governing permissions and
/// limitations under the License.

/// <reference path="metricsTypes.ts"/>
/// <reference path="metricsPlugin.ts"/>
/// <reference path="../../includes.ts"/>

Expand Down Expand Up @@ -59,23 +60,23 @@ module HawkularMetrics {
private HawkularMetric:any,
private HawkularAlert:any,
private $routeParams:any,
public startTimeStamp:number,
public endTimeStamp:number) {
public startTimeStamp:TimestampInMillis,
public endTimeStamp:TimestampInMillis) {
$scope.vm = this;

this.startTimeStamp = moment().subtract(1, 'hours').valueOf();
this.endTimeStamp = +moment();

this.metricId = $scope.hkParams.resourceId;
this.resourceId = $scope.hkParams.resourceId;

$scope.$on('RefreshChart', (event) => {
this.refreshChartDataNow(this.getMetricId());
});

$scope.$watch('hkParams.resourceId', (resourceId) => {
$scope.$watch('hkParams.resourceId', (resourceId:ResourceId) => {
/// made a selection from url switcher
if (resourceId) {
this.metricId = resourceId;
this.resourceId = resourceId;
this.refreshChartDataNow(this.getMetricId());
}
});
Expand All @@ -88,7 +89,7 @@ module HawkularMetrics {
private chartData:any;
private autoRefreshPromise:ng.IPromise<number>;

private metricId:string;
private resourceId:ResourceId;
threshold = 5000; // default to 5 seconds some high number

median = 0;
Expand Down Expand Up @@ -117,13 +118,13 @@ module HawkularMetrics {
});
}

private noDataFoundForId(id:string):void {
this.$log.warn('No Data found for id: ' + id);
private noDataFoundForId(resourceId:ResourceId):void {
this.$log.warn('No Data found for id: ' + resourceId);
///toastr.warning('No Data found for id: ' + id);
}


refreshChartDataNow(metricId:string, startTime?:number):void {
refreshChartDataNow(metricId:string, startTime?:TimestampInMillis):void {
this.$scope.hkEndTimestamp = +moment();
var adjStartTimeStamp:number = moment().subtract(this.$scope.hkParams.timeOffset, 'milliseconds').valueOf();
this.endTimeStamp = this.$scope.hkEndTimestamp;
Expand All @@ -132,24 +133,26 @@ module HawkularMetrics {
this.retrieveThreshold();
}

getMetricId():string {
return this.metricId + '.status.duration';
getMetricId():ResourceId {
return this.resourceId + '.status.duration';
}


retrieveThreshold() {
this.HawkularAlert.Condition.query({triggerId: this.$routeParams.resourceId + '_trigger_thres'}).$promise
.then((response) => {

this.threshold = response[0].threshold;
if (response[0]) {
this.threshold = response[0].threshold;
}

}, (error) => {
this.$log.error('Error Loading Threshold data');
toastr.error('Error Loading Threshold Data: ' + error);
});
}

refreshSummaryData(metricId:string, startTime?:number, endTime?:number):void {
refreshSummaryData(metricId:string, startTime?:TimestampInMillis, endTime?:TimestampInMillis):void {
var dataPoints:IChartDataPoint[];
// calling refreshChartData without params use the model values
if (!endTime) {
Expand Down Expand Up @@ -185,7 +188,7 @@ module HawkularMetrics {
}


refreshHistoricalChartDataForTimestamp(metricId:string, startTime?:number, endTime?:number):void {
refreshHistoricalChartDataForTimestamp(metricId:string, startTime?:TimestampInMillis, endTime?:TimestampInMillis):void {
// calling refreshChartData without params use the model values
if (!endTime) {
endTime = this.endTimeStamp;
Expand All @@ -194,13 +197,14 @@ module HawkularMetrics {
startTime = this.startTimeStamp;
}


if (metricId) {
this.HawkularMetric.NumericMetricData.queryMetrics({
tenantId: globalTenantId,
numericId: metricId,
start: startTime,
end: endTime,
buckets: 60
buckets: 120
}).$promise
.then((response) => {

Expand Down
32 changes: 32 additions & 0 deletions plugins/metrics/plugins/metrics/ts/metricsTypes.ts
@@ -0,0 +1,32 @@
/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.

/// <reference path="metricsPlugin.ts"/>
/// <reference path="../../includes.ts"/>
/// <reference path="errorManager.ts"/>


module HawkularMetrics {

/// Typescript 1.4 introduces type aliases: http://blogs.msdn.com/b/typescript/archive/2015/01/16/announcing-typescript-1-4.aspx
/// Some Type aliases to make things more type safe than just string or number. Implies how it is being used and is especially useful for refactoring.

export type TenantId = string;
export type ResourceId = string;
export type MetricId = string;
export type TimestampInMillis = number;


}