prettier: change to single quoting

This commit is contained in:
Torkel Ödegaard
2017-12-20 12:33:33 +01:00
parent 2a360c45a2
commit 85879a7014
304 changed files with 10558 additions and 10519 deletions

View File

@@ -1,7 +1,7 @@
///<reference path="../../../headers/common.d.ts" />
export class CloudWatchConfigCtrl {
static templateUrl = "partials/config.html";
static templateUrl = 'partials/config.html';
current: any;
accessKeyExist = false;
@@ -10,9 +10,9 @@ export class CloudWatchConfigCtrl {
/** @ngInject */
constructor($scope) {
this.current.jsonData.timeField =
this.current.jsonData.timeField || "@timestamp";
this.current.jsonData.timeField || '@timestamp';
this.current.jsonData.authType =
this.current.jsonData.authType || "credentials";
this.current.jsonData.authType || 'credentials';
this.accessKeyExist = this.current.secureJsonFields.accessKey;
this.secretKeyExist = this.current.secureJsonFields.secretKey;
@@ -27,17 +27,17 @@ export class CloudWatchConfigCtrl {
}
authTypes = [
{ name: "Access & secret key", value: "keys" },
{ name: "Credentials file", value: "credentials" },
{ name: "ARN", value: "arn" }
{ name: 'Access & secret key', value: 'keys' },
{ name: 'Credentials file', value: 'credentials' },
{ name: 'ARN', value: 'arn' },
];
indexPatternTypes = [
{ name: "No pattern", value: undefined },
{ name: "Hourly", value: "Hourly", example: "[logstash-]YYYY.MM.DD.HH" },
{ name: "Daily", value: "Daily", example: "[logstash-]YYYY.MM.DD" },
{ name: "Weekly", value: "Weekly", example: "[logstash-]GGGG.WW" },
{ name: "Monthly", value: "Monthly", example: "[logstash-]YYYY.MM" },
{ name: "Yearly", value: "Yearly", example: "[logstash-]YYYY" }
{ name: 'No pattern', value: undefined },
{ name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' },
{ name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' },
{ name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' },
{ name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' },
{ name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
];
}

View File

@@ -1,16 +1,16 @@
import "./query_parameter_ctrl";
import './query_parameter_ctrl';
import CloudWatchDatasource from "./datasource";
import { CloudWatchQueryCtrl } from "./query_ctrl";
import { CloudWatchConfigCtrl } from "./config_ctrl";
import CloudWatchDatasource from './datasource';
import { CloudWatchQueryCtrl } from './query_ctrl';
import { CloudWatchConfigCtrl } from './config_ctrl';
class CloudWatchAnnotationsQueryCtrl {
static templateUrl = "partials/annotations.editor.html";
static templateUrl = 'partials/annotations.editor.html';
}
export {
CloudWatchDatasource as Datasource,
CloudWatchQueryCtrl as QueryCtrl,
CloudWatchConfigCtrl as ConfigCtrl,
CloudWatchAnnotationsQueryCtrl as AnnotationsQueryCtrl
CloudWatchAnnotationsQueryCtrl as AnnotationsQueryCtrl,
};

View File

@@ -1,10 +1,10 @@
///<reference path="../../../headers/common.d.ts" />
import "./query_parameter_ctrl";
import { QueryCtrl } from "app/plugins/sdk";
import './query_parameter_ctrl';
import { QueryCtrl } from 'app/plugins/sdk';
export class CloudWatchQueryCtrl extends QueryCtrl {
static templateUrl = "partials/query.editor.html";
static templateUrl = 'partials/query.editor.html';
aliasSyntax: string;
@@ -12,6 +12,6 @@ export class CloudWatchQueryCtrl extends QueryCtrl {
constructor($scope, $injector) {
super($scope, $injector);
this.aliasSyntax =
"{{metric}} {{stat}} {{namespace}} {{region}} {{<dimension name>}}";
'{{metric}} {{stat}} {{namespace}} {{region}} {{<dimension name>}}';
}
}

View File

@@ -1,18 +1,18 @@
import angular from "angular";
import _ from "lodash";
import angular from 'angular';
import _ from 'lodash';
export class CloudWatchQueryParameter {
constructor() {
return {
templateUrl:
"public/app/plugins/datasource/cloudwatch/partials/query.parameter.html",
controller: "CloudWatchQueryParameterCtrl",
restrict: "E",
'public/app/plugins/datasource/cloudwatch/partials/query.parameter.html',
controller: 'CloudWatchQueryParameterCtrl',
restrict: 'E',
scope: {
target: "=",
datasource: "=",
onChange: "&"
}
target: '=',
datasource: '=',
onChange: '&',
},
};
}
}
@@ -22,31 +22,31 @@ export class CloudWatchQueryParameterCtrl {
constructor($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) {
$scope.init = function() {
var target = $scope.target;
target.namespace = target.namespace || "";
target.metricName = target.metricName || "";
target.statistics = target.statistics || ["Average"];
target.namespace = target.namespace || '';
target.metricName = target.metricName || '';
target.statistics = target.statistics || ['Average'];
target.dimensions = target.dimensions || {};
target.period = target.period || "";
target.region = target.region || "default";
target.period = target.period || '';
target.region = target.region || 'default';
$scope.regionSegment = uiSegmentSrv.getSegmentForValue(
$scope.target.region,
"select region"
'select region'
);
$scope.namespaceSegment = uiSegmentSrv.getSegmentForValue(
$scope.target.namespace,
"select namespace"
'select namespace'
);
$scope.metricSegment = uiSegmentSrv.getSegmentForValue(
$scope.target.metricName,
"select metric"
'select metric'
);
$scope.dimSegments = _.reduce(
$scope.target.dimensions,
function(memo, value, key) {
memo.push(uiSegmentSrv.newKey(key));
memo.push(uiSegmentSrv.newOperator("="));
memo.push(uiSegmentSrv.newOperator('='));
memo.push(uiSegmentSrv.newKeyValue(value));
return memo;
},
@@ -61,15 +61,15 @@ export class CloudWatchQueryParameterCtrl {
$scope.ensurePlusButton($scope.dimSegments);
$scope.removeDimSegment = uiSegmentSrv.newSegment({
fake: true,
value: "-- remove dimension --"
value: '-- remove dimension --',
});
$scope.removeStatSegment = uiSegmentSrv.newSegment({
fake: true,
value: "-- remove stat --"
value: '-- remove stat --',
});
if (_.isEmpty($scope.target.region)) {
$scope.target.region = "default";
$scope.target.region = 'default';
}
if (!$scope.onChange) {
@@ -84,7 +84,7 @@ export class CloudWatchQueryParameterCtrl {
_.map($scope.datasource.standardStatistics, function(s) {
return uiSegmentSrv.getSegmentForValue(s);
}),
uiSegmentSrv.getSegmentForValue("pNN.NN")
uiSegmentSrv.getSegmentForValue('pNN.NN'),
])
);
};
@@ -93,7 +93,7 @@ export class CloudWatchQueryParameterCtrl {
if (segment.value === $scope.removeStatSegment.value) {
$scope.statSegments.splice(index, 1);
} else {
segment.type = "value";
segment.type = 'value';
}
$scope.target.statistics = _.reduce(
@@ -115,25 +115,25 @@ export class CloudWatchQueryParameterCtrl {
var count = segments.length;
var lastSegment = segments[Math.max(count - 1, 0)];
if (!lastSegment || lastSegment.type !== "plus-button") {
if (!lastSegment || lastSegment.type !== 'plus-button') {
segments.push(uiSegmentSrv.newPlusButton());
}
};
$scope.getDimSegments = function(segment, $index) {
if (segment.type === "operator") {
if (segment.type === 'operator') {
return $q.when([]);
}
var target = $scope.target;
var query = $q.when([]);
if (segment.type === "key" || segment.type === "plus-button") {
if (segment.type === 'key' || segment.type === 'plus-button') {
query = $scope.datasource.getDimensionKeys(
$scope.target.namespace,
$scope.target.region
);
} else if (segment.type === "value") {
} else if (segment.type === 'value') {
var dimensionKey = $scope.dimSegments[$index - 2].value;
query = $scope.datasource.getDimensionValues(
target.region,
@@ -147,7 +147,7 @@ export class CloudWatchQueryParameterCtrl {
return query
.then($scope.transformToSegments(true))
.then(function(results) {
if (segment.type === "key") {
if (segment.type === 'key') {
results.splice(0, 0, angular.copy($scope.removeDimSegment));
}
return results;
@@ -159,17 +159,17 @@ export class CloudWatchQueryParameterCtrl {
if (segment.value === $scope.removeDimSegment.value) {
$scope.dimSegments.splice(index, 3);
} else if (segment.type === "plus-button") {
$scope.dimSegments.push(uiSegmentSrv.newOperator("="));
} else if (segment.type === 'plus-button') {
$scope.dimSegments.push(uiSegmentSrv.newOperator('='));
$scope.dimSegments.push(
uiSegmentSrv.newFake(
"select dimension value",
"value",
"query-segment-value"
'select dimension value',
'value',
'query-segment-value'
)
);
segment.type = "key";
segment.cssClass = "query-segment-key";
segment.type = 'key';
segment.cssClass = 'query-segment-key';
}
$scope.syncDimSegmentsWithModel();
@@ -194,9 +194,9 @@ export class CloudWatchQueryParameterCtrl {
$scope.getRegions = function() {
return $scope.datasource
.metricFindQuery("regions()")
.metricFindQuery('regions()')
.then(function(results) {
results.unshift({ text: "default" });
results.unshift({ text: 'default' });
return results;
})
.then($scope.transformToSegments(true));
@@ -204,18 +204,18 @@ export class CloudWatchQueryParameterCtrl {
$scope.getNamespaces = function() {
return $scope.datasource
.metricFindQuery("namespaces()")
.metricFindQuery('namespaces()')
.then($scope.transformToSegments(true));
};
$scope.getMetrics = function() {
return $scope.datasource
.metricFindQuery(
"metrics(" +
'metrics(' +
$scope.target.namespace +
"," +
',' +
$scope.target.region +
")"
')'
)
.then($scope.transformToSegments(true));
};
@@ -240,7 +240,7 @@ export class CloudWatchQueryParameterCtrl {
var segments = _.map(results, function(segment) {
return uiSegmentSrv.newSegment({
value: segment.text,
expandable: segment.expandable
expandable: segment.expandable,
});
});
@@ -248,9 +248,9 @@ export class CloudWatchQueryParameterCtrl {
_.each(templateSrv.variables, function(variable) {
segments.unshift(
uiSegmentSrv.newSegment({
type: "template",
value: "$" + variable.name,
expandable: true
type: 'template',
value: '$' + variable.name,
expandable: true,
})
);
});
@@ -265,8 +265,8 @@ export class CloudWatchQueryParameterCtrl {
}
angular
.module("grafana.controllers")
.directive("cloudwatchQueryParameter", CloudWatchQueryParameter);
.module('grafana.controllers')
.directive('cloudwatchQueryParameter', CloudWatchQueryParameter);
angular
.module("grafana.controllers")
.controller("CloudWatchQueryParameterCtrl", CloudWatchQueryParameterCtrl);
.module('grafana.controllers')
.controller('CloudWatchQueryParameterCtrl', CloudWatchQueryParameterCtrl);

View File

@@ -1,24 +1,24 @@
import "../datasource";
import '../datasource';
import {
describe,
beforeEach,
it,
expect,
angularMocks
} from "test/lib/common";
import helpers from "test/specs/helpers";
import CloudWatchDatasource from "../datasource";
angularMocks,
} from 'test/lib/common';
import helpers from 'test/specs/helpers';
import CloudWatchDatasource from '../datasource';
describe("CloudWatchDatasource", function() {
describe('CloudWatchDatasource', function() {
var ctx = new helpers.ServiceTestContext();
var instanceSettings = {
jsonData: { defaultRegion: "us-east-1", access: "proxy" }
jsonData: { defaultRegion: 'us-east-1', access: 'proxy' },
};
beforeEach(angularMocks.module("grafana.core"));
beforeEach(angularMocks.module("grafana.services"));
beforeEach(angularMocks.module("grafana.controllers"));
beforeEach(ctx.providePhase(["templateSrv", "backendSrv"]));
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(
angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
@@ -26,53 +26,53 @@ describe("CloudWatchDatasource", function() {
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.ds = $injector.instantiate(CloudWatchDatasource, {
instanceSettings: instanceSettings
instanceSettings: instanceSettings,
});
$httpBackend.when("GET", /\.html$/).respond("");
$httpBackend.when('GET', /\.html$/).respond('');
})
);
describe("When performing CloudWatch query", function() {
describe('When performing CloudWatch query', function() {
var requestParams;
var query = {
range: { from: "now-1h", to: "now" },
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
region: "us-east-1",
namespace: "AWS/EC2",
metricName: "CPUUtilization",
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: "i-12345678"
InstanceId: 'i-12345678',
},
statistics: ["Average"],
period: "300"
}
]
statistics: ['Average'],
period: '300',
},
],
};
var response = {
timings: [null],
results: {
A: {
error: "",
refId: "A",
error: '',
refId: 'A',
series: [
{
name: "CPUUtilization_Average",
name: 'CPUUtilization_Average',
points: [
[1, 1483228800000],
[2, 1483229100000],
[5, 1483229700000]
[5, 1483229700000],
],
tags: {
InstanceId: "i-12345678"
}
}
]
}
}
InstanceId: 'i-12345678',
},
},
],
},
},
};
beforeEach(function() {
@@ -82,12 +82,12 @@ describe("CloudWatchDatasource", function() {
};
});
it("should generate the correct query", function(done) {
it('should generate the correct query', function(done) {
ctx.ds.query(query).then(function() {
var params = requestParams.queries[0];
expect(params.namespace).to.be(query.targets[0].namespace);
expect(params.metricName).to.be(query.targets[0].metricName);
expect(params.dimensions["InstanceId"]).to.be("i-12345678");
expect(params.dimensions['InstanceId']).to.be('i-12345678');
expect(params.statistics).to.eql(query.targets[0].statistics);
expect(params.period).to.be(query.targets[0].period);
done();
@@ -95,37 +95,37 @@ describe("CloudWatchDatasource", function() {
ctx.$rootScope.$apply();
});
it("should generate the correct query with interval variable", function(done) {
it('should generate the correct query with interval variable', function(done) {
ctx.templateSrv.data = {
period: "10m"
period: '10m',
};
var query = {
range: { from: "now-1h", to: "now" },
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
region: "us-east-1",
namespace: "AWS/EC2",
metricName: "CPUUtilization",
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: "i-12345678"
InstanceId: 'i-12345678',
},
statistics: ["Average"],
period: "[[period]]"
}
]
statistics: ['Average'],
period: '[[period]]',
},
],
};
ctx.ds.query(query).then(function() {
var params = requestParams.queries[0];
expect(params.period).to.be("600");
expect(params.period).to.be('600');
done();
});
ctx.$rootScope.$apply();
});
it("should return series list", function(done) {
it('should return series list', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].target).to.be(response.results.A.series[0].name);
expect(result.data[0].datapoints[0][0]).to.be(
@@ -136,53 +136,53 @@ describe("CloudWatchDatasource", function() {
ctx.$rootScope.$apply();
});
it("should generate the correct targets by expanding template variables", function() {
it('should generate the correct targets by expanding template variables', function() {
var templateSrv = {
variables: [
{
name: "instance_id",
name: 'instance_id',
options: [
{ text: "i-23456789", value: "i-23456789", selected: false },
{ text: "i-34567890", value: "i-34567890", selected: true }
]
}
{ text: 'i-23456789', value: 'i-23456789', selected: false },
{ text: 'i-34567890', value: 'i-34567890', selected: true },
],
},
],
replace: function(target, scopedVars) {
if (
target === "$instance_id" &&
scopedVars["instance_id"]["text"] === "i-34567890"
target === '$instance_id' &&
scopedVars['instance_id']['text'] === 'i-34567890'
) {
return "i-34567890";
return 'i-34567890';
} else {
return "";
return '';
}
},
getVariableName: function(e) {
return "instance_id";
return 'instance_id';
},
variableExists: function(e) {
return true;
},
containsVariable: function(str, variableName) {
return str.indexOf("$" + variableName) !== -1;
}
return str.indexOf('$' + variableName) !== -1;
},
};
var targets = [
{
region: "us-east-1",
namespace: "AWS/EC2",
metricName: "CPUUtilization",
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: "$instance_id"
InstanceId: '$instance_id',
},
statistics: ["Average"],
period: 300
}
statistics: ['Average'],
period: 300,
},
];
var result = ctx.ds.expandTemplateVariable(targets, {}, templateSrv);
expect(result[0].dimensions.InstanceId).to.be("i-34567890");
expect(result[0].dimensions.InstanceId).to.be('i-34567890');
});
});
@@ -191,13 +191,13 @@ describe("CloudWatchDatasource", function() {
var defaultRegion = instanceSettings.jsonData.defaultRegion;
expect(ctx.ds.getActualRegion()).to.be(defaultRegion);
expect(ctx.ds.getActualRegion("")).to.be(defaultRegion);
expect(ctx.ds.getActualRegion("default")).to.be(defaultRegion);
expect(ctx.ds.getActualRegion('')).to.be(defaultRegion);
expect(ctx.ds.getActualRegion('default')).to.be(defaultRegion);
});
it("should return the specified region if specified", function() {
expect(ctx.ds.getActualRegion("some-fake-region-1")).to.be(
"some-fake-region-1"
it('should return the specified region if specified', function() {
expect(ctx.ds.getActualRegion('some-fake-region-1')).to.be(
'some-fake-region-1'
);
});
@@ -211,20 +211,20 @@ describe("CloudWatchDatasource", function() {
it('should query for the datasource region if empty or "default"', function(done) {
var query = {
range: { from: "now-1h", to: "now" },
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
region: "default",
namespace: "AWS/EC2",
metricName: "CPUUtilization",
region: 'default',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: "i-12345678"
InstanceId: 'i-12345678',
},
statistics: ["Average"],
period: 300
}
]
statistics: ['Average'],
period: 300,
},
],
};
ctx.ds.query(query).then(function(result) {
@@ -237,47 +237,47 @@ describe("CloudWatchDatasource", function() {
});
});
describe("When performing CloudWatch query for extended statistics", function() {
describe('When performing CloudWatch query for extended statistics', function() {
var query = {
range: { from: "now-1h", to: "now" },
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
region: "us-east-1",
namespace: "AWS/ApplicationELB",
metricName: "TargetResponseTime",
region: 'us-east-1',
namespace: 'AWS/ApplicationELB',
metricName: 'TargetResponseTime',
dimensions: {
LoadBalancer: "lb",
TargetGroup: "tg"
LoadBalancer: 'lb',
TargetGroup: 'tg',
},
statistics: ["p90.00"],
period: 300
}
]
statistics: ['p90.00'],
period: 300,
},
],
};
var response = {
timings: [null],
results: {
A: {
error: "",
refId: "A",
error: '',
refId: 'A',
series: [
{
name: "TargetResponseTime_p90.00",
name: 'TargetResponseTime_p90.00',
points: [
[1, 1483228800000],
[2, 1483229100000],
[5, 1483229700000]
[5, 1483229700000],
],
tags: {
LoadBalancer: "lb",
TargetGroup: "tg"
}
}
]
}
}
LoadBalancer: 'lb',
TargetGroup: 'tg',
},
},
],
},
},
};
beforeEach(function() {
@@ -286,7 +286,7 @@ describe("CloudWatchDatasource", function() {
};
});
it("should return series list", function(done) {
it('should return series list', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].target).to.be(response.results.A.series[0].name);
expect(result.data[0].datapoints[0][0]).to.be(
@@ -299,7 +299,7 @@ describe("CloudWatchDatasource", function() {
});
function describeMetricFindQuery(query, func) {
describe("metricFindQuery " + query, () => {
describe('metricFindQuery ' + query, () => {
let scenario: any = {};
scenario.setup = setupCallback => {
beforeEach(() => {
@@ -319,202 +319,202 @@ describe("CloudWatchDatasource", function() {
});
}
describeMetricFindQuery("regions()", scenario => {
describeMetricFindQuery('regions()', scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["us-east-1", "us-east-1"]] }]
}
}
tables: [{ rows: [['us-east-1', 'us-east-1']] }],
},
},
};
});
it("should call __GetRegions and return result", () => {
expect(scenario.result[0].text).to.contain("us-east-1");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("regions");
it('should call __GetRegions and return result', () => {
expect(scenario.result[0].text).to.contain('us-east-1');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('regions');
});
});
describeMetricFindQuery("namespaces()", scenario => {
describeMetricFindQuery('namespaces()', scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["AWS/EC2", "AWS/EC2"]] }]
}
}
tables: [{ rows: [['AWS/EC2', 'AWS/EC2']] }],
},
},
};
});
it("should call __GetNamespaces and return result", () => {
expect(scenario.result[0].text).to.contain("AWS/EC2");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("namespaces");
it('should call __GetNamespaces and return result', () => {
expect(scenario.result[0].text).to.contain('AWS/EC2');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('namespaces');
});
});
describeMetricFindQuery("metrics(AWS/EC2)", scenario => {
describeMetricFindQuery('metrics(AWS/EC2)', scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["CPUUtilization", "CPUUtilization"]] }]
}
}
tables: [{ rows: [['CPUUtilization', 'CPUUtilization']] }],
},
},
};
});
it("should call __GetMetrics and return result", () => {
expect(scenario.result[0].text).to.be("CPUUtilization");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("metrics");
it('should call __GetMetrics and return result', () => {
expect(scenario.result[0].text).to.be('CPUUtilization');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('metrics');
});
});
describeMetricFindQuery("dimension_keys(AWS/EC2)", scenario => {
describeMetricFindQuery('dimension_keys(AWS/EC2)', scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["InstanceId", "InstanceId"]] }]
}
}
tables: [{ rows: [['InstanceId', 'InstanceId']] }],
},
},
};
});
it("should call __GetDimensions and return result", () => {
expect(scenario.result[0].text).to.be("InstanceId");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("dimension_keys");
it('should call __GetDimensions and return result', () => {
expect(scenario.result[0].text).to.be('InstanceId');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('dimension_keys');
});
});
describeMetricFindQuery(
"dimension_values(us-east-1,AWS/EC2,CPUUtilization,InstanceId)",
'dimension_values(us-east-1,AWS/EC2,CPUUtilization,InstanceId)',
scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["i-12345678", "i-12345678"]] }]
}
}
tables: [{ rows: [['i-12345678', 'i-12345678']] }],
},
},
};
});
it("should call __ListMetrics and return result", () => {
expect(scenario.result[0].text).to.contain("i-12345678");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("dimension_values");
it('should call __ListMetrics and return result', () => {
expect(scenario.result[0].text).to.contain('i-12345678');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('dimension_values');
});
}
);
describeMetricFindQuery(
"dimension_values(default,AWS/EC2,CPUUtilization,InstanceId)",
'dimension_values(default,AWS/EC2,CPUUtilization,InstanceId)',
scenario => {
scenario.setup(() => {
scenario.requestResponse = {
results: {
metricFindQuery: {
tables: [{ rows: [["i-12345678", "i-12345678"]] }]
}
}
tables: [{ rows: [['i-12345678', 'i-12345678']] }],
},
},
};
});
it("should call __ListMetrics and return result", () => {
expect(scenario.result[0].text).to.contain("i-12345678");
expect(scenario.request.queries[0].type).to.be("metricFindQuery");
expect(scenario.request.queries[0].subtype).to.be("dimension_values");
it('should call __ListMetrics and return result', () => {
expect(scenario.result[0].text).to.contain('i-12345678');
expect(scenario.request.queries[0].type).to.be('metricFindQuery');
expect(scenario.request.queries[0].subtype).to.be('dimension_values');
});
}
);
it("should caclculate the correct period", function() {
it('should caclculate the correct period', function() {
var hourSec = 60 * 60;
var daySec = hourSec * 24;
var start = 1483196400 * 1000;
var testData: any[] = [
[
{ period: 60, namespace: "AWS/EC2" },
{ period: 60, namespace: 'AWS/EC2' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
60
60,
],
[
{ period: null, namespace: "AWS/EC2" },
{ period: null, namespace: 'AWS/EC2' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
300
300,
],
[
{ period: 60, namespace: "AWS/ELB" },
{ period: 60, namespace: 'AWS/ELB' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
60
60,
],
[
{ period: null, namespace: "AWS/ELB" },
{ period: null, namespace: 'AWS/ELB' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
60
60,
],
[
{ period: 1, namespace: "CustomMetricsNamespace" },
{ period: 1, namespace: 'CustomMetricsNamespace' },
{
range: {
from: new Date(start),
to: new Date(start + (1440 - 1) * 1000)
}
to: new Date(start + (1440 - 1) * 1000),
},
},
hourSec * 3 - 1,
1
1,
],
[
{ period: 1, namespace: "CustomMetricsNamespace" },
{ period: 1, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3 - 1,
60
60,
],
[
{ period: 60, namespace: "CustomMetricsNamespace" },
{ period: 60, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
60
60,
],
[
{ period: null, namespace: "CustomMetricsNamespace" },
{ period: null, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3 - 1,
60
60,
],
[
{ period: null, namespace: "CustomMetricsNamespace" },
{ period: null, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
hourSec * 3,
60
60,
],
[
{ period: null, namespace: "CustomMetricsNamespace" },
{ period: null, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
daySec * 15,
60
60,
],
[
{ period: null, namespace: "CustomMetricsNamespace" },
{ period: null, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
daySec * 63,
300
300,
],
[
{ period: null, namespace: "CustomMetricsNamespace" },
{ period: null, namespace: 'CustomMetricsNamespace' },
{ range: { from: new Date(start), to: new Date(start + 3600 * 1000) } },
daySec * 455,
3600
]
3600,
],
];
for (let t of testData) {
let target = t[0];