Commit e4de6332 by Mitsuhiro Tanda

refactor cloudwatch frontend code

parent ea704306
...@@ -141,7 +141,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot ...@@ -141,7 +141,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
}); });
} }
this.getRegions = function () { this.doMetricQueryRequest = function (subtype, parameters) {
var range = timeSrv.timeRange(); var range = timeSrv.timeRange();
return backendSrv.post('/api/tsdb/query', { return backendSrv.post('/api/tsdb/query', {
from: range.from, from: range.from,
...@@ -153,142 +153,58 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot ...@@ -153,142 +153,58 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
maxDataPoints: 1, // dummy maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id, datasourceId: this.instanceSettings.id,
type: 'metricFindQuery', type: 'metricFindQuery',
subtype: 'regions' subtype: subtype,
parameters: parameters
} }
] ]
}).then(function (r) { return transformSuggestDataFromTable(r); }); }).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getRegions = function () {
return this.doMetricQueryRequest('regions', null);
};
this.getNamespaces = function() { this.getNamespaces = function() {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('namespaces', null);
return backendSrv.post('/api/tsdb/query', {
from: range.from,
to: range.to,
queries: [
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'namespaces'
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getMetrics = function (namespace, region) { this.getMetrics = function (namespace, region) {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('metrics', {
return backendSrv.post('/api/tsdb/query', { region: region,
from: range.from, namespace: templateSrv.replace(namespace)
to: range.to, });
queries: [
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'metrics',
parameters: {
region: region,
namespace: templateSrv.replace(namespace)
}
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getDimensionKeys = function(namespace, region) { this.getDimensionKeys = function(namespace, region) {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('dimension_keys', {
return backendSrv.post('/api/tsdb/query', { region: region,
from: range.from, namespace: templateSrv.replace(namespace)
to: range.to, });
queries: [
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'dimension_keys',
parameters: {
region: region,
namespace: templateSrv.replace(namespace)
}
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) { this.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('dimension_values', {
return backendSrv.post('/api/tsdb/query', { region: region,
from: range.from, namespace: templateSrv.replace(namespace),
to: range.to, metricName: templateSrv.replace(metricName),
queries: [ dimensionKey: templateSrv.replace(dimensionKey),
{ dimensions: this.convertDimensionFormat(filterDimensions, {}),
refId: 'metricFindQuery', });
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'dimension_values',
parameters: {
region: region,
namespace: templateSrv.replace(namespace),
metricName: templateSrv.replace(metricName),
dimensionKey: templateSrv.replace(dimensionKey),
dimensions: this.convertDimensionFormat(filterDimensions, {}),
}
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getEbsVolumeIds = function(region, instanceId) { this.getEbsVolumeIds = function(region, instanceId) {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('ebs_volume_ids', {
return backendSrv.post('/api/tsdb/query', { region: region,
from: range.from, instanceId: instanceId
to: range.to, });
queries: [
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'ebs_volume_ids',
parameters: {
region: region,
instanceId: instanceId
}
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.getEc2InstanceAttribute = function(region, attributeName, filters) { this.getEc2InstanceAttribute = function(region, attributeName, filters) {
var range = timeSrv.timeRange(); return this.doMetricQueryRequest('ec2_instance_attribute', {
return backendSrv.post('/api/tsdb/query', { region: region,
from: range.from, attributeName: attributeName,
to: range.to, filters: filters
queries: [ });
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'ec2_instance_attribute',
parameters: {
region: region,
attributeName: attributeName,
filters: filters
}
}
]
}).then(function (r) { return transformSuggestDataFromTable(r); });
}; };
this.metricFindQuery = function(query) { this.metricFindQuery = function(query) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment