Skip to content

Commit 0912cec

Browse files
committed
feat(cloudwatch): contining work on moving hard coded stuff to backend and cleaning up code, grafana#684
1 parent 180ba33 commit 0912cec

File tree

4 files changed

+187
-279
lines changed

4 files changed

+187
-279
lines changed

pkg/api/cloudwatch/cloudwatch.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/aws/aws-sdk-go/service/cloudwatch"
1111
"github.com/aws/aws-sdk-go/service/ec2"
1212
"github.com/grafana/grafana/pkg/middleware"
13-
"github.com/grafana/grafana/pkg/util"
1413
)
1514

1615
type actionHandler func(*cwRequest, *middleware.Context)
@@ -29,6 +28,8 @@ func init() {
2928
"ListMetrics": handleListMetrics,
3029
"DescribeInstances": handleDescribeInstances,
3130
"__GetRegions": handleGetRegions,
31+
"__GetNamespaces": handleGetNamespaces,
32+
"__GetMetrics": handleGetMetrics,
3233
}
3334
}
3435

@@ -122,20 +123,6 @@ func handleDescribeInstances(req *cwRequest, c *middleware.Context) {
122123
c.JSON(200, resp)
123124
}
124125

125-
func handleGetRegions(req *cwRequest, c *middleware.Context) {
126-
regions := []string{
127-
"us-west-2", "us-west-1", "eu-west-1", "eu-central-1", "ap-southeast-1",
128-
"ap-southeast-2", "ap-northeast-1", "sa-east-1",
129-
}
130-
131-
result := []interface{}{}
132-
for _, region := range regions {
133-
result = append(result, util.DynMap{"text": region, "value": region})
134-
}
135-
136-
c.JSON(200, result)
137-
}
138-
139126
func HandleRequest(c *middleware.Context) {
140127
var req cwRequest
141128
req.Body, _ = ioutil.ReadAll(c.Req.Request.Body)

pkg/api/cloudwatch/metrics.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package cloudwatch
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/grafana/grafana/pkg/middleware"
7+
"github.com/grafana/grafana/pkg/util"
8+
)
9+
10+
var metricsMap map[string][]string
11+
12+
func init() {
13+
metricsMap = map[string][]string{
14+
"AWS/AutoScaling": []string{"GroupMinSize", "GroupMaxSize", "GroupDesiredCapacity", "GroupInServiceInstances", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances"},
15+
"AWS/Billing": []string{"EstimatedCharges"},
16+
"AWS/EC2": []string{"CPUCreditUsage", "CPUCreditBalance", "CPUUtilization", "DiskReadOps", "DiskWriteOps", "DiskReadBytes", "DiskWriteBytes", "NetworkIn", "NetworkOut", "StatusCheckFailed", "StatusCheckFailed_Instance", "StatusCheckFailed_System"},
17+
"AWS/CloudFront": []string{"Requests", "BytesDownloaded", "BytesUploaded", "TotalErrorRate", "4xxErrorRate", "5xxErrorRate"},
18+
"AWS/CloudSearch": []string{"SuccessfulRequests", "SearchableDocuments", "IndexUtilization", "Partitions"},
19+
"AWS/DynamoDB": []string{"ConditionalCheckFailedRequests", "ConsumedReadCapacityUnits", "ConsumedWriteCapacityUnits", "OnlineIndexConsumedWriteCapacity", "OnlineIndexPercentageProgress", "OnlineIndexThrottleEvents", "ProvisionedReadCapacityUnits", "ProvisionedWriteCapacityUnits", "ReadThrottleEvents", "ReturnedItemCount", "SuccessfulRequestLatency", "SystemErrors", "ThrottledRequests", "UserErrors", "WriteThrottleEvents"},
20+
"AWS/ElastiCache": []string{
21+
"CPUUtilization", "SwapUsage", "FreeableMemory", "NetworkBytesIn", "NetworkBytesOut",
22+
"BytesUsedForCacheItems", "BytesReadIntoMemcached", "BytesWrittenOutFromMemcached", "CasBadval", "CasHits", "CasMisses", "CmdFlush", "CmdGet", "CmdSet", "CurrConnections", "CurrItems", "DecrHits", "DecrMisses", "DeleteHits", "DeleteMisses", "Evictions", "GetHits", "GetMisses", "IncrHits", "IncrMisses", "Reclaimed",
23+
"CurrConnections", "Evictions", "Reclaimed", "NewConnections", "BytesUsedForCache", "CacheHits", "CacheMisses", "ReplicationLag", "GetTypeCmds", "SetTypeCmds", "KeyBasedCmds", "StringBasedCmds", "HashBasedCmds", "ListBasedCmds", "SetBasedCmds", "SortedSetBasedCmds", "CurrItems",
24+
},
25+
"AWS/EBS": []string{"VolumeReadBytes", "VolumeWriteBytes", "VolumeReadOps", "VolumeWriteOps", "VolumeTotalReadTime", "VolumeTotalWriteTime", "VolumeIdleTime", "VolumeQueueLength", "VolumeThroughputPercentage", "VolumeConsumedReadWriteOps"},
26+
"AWS/ELB": []string{"HealthyHostCount", "UnHealthyHostCount", "RequestCount", "Latency", "HTTPCode_ELB_4XX", "HTTPCode_ELB_5XX", "HTTPCode_Backend_2XX", "HTTPCode_Backend_3XX", "HTTPCode_Backend_4XX", "HTTPCode_Backend_5XX", "BackendConnectionErrors", "SurgeQueueLength", "SpilloverCount"},
27+
}
28+
}
29+
30+
// "AWS/ElasticMapReduce": [
31+
// "CoreNodesPending", "CoreNodesRunning", "HBaseBackupFailed", "HBaseMostRecentBackupDuration", "HBaseTimeSinceLastSuccessfulBackup", "HDFSBytesRead", "HDFSBytesWritten", "HDFSUtilization", "IsIdle", "JobsFailed", "JobsRunning", "LiveDataNodes", "LiveTaskTrackers", "MapSlotsOpen", "MissingBlocks", "ReduceSlotsOpen", "RemainingMapTasks", "RemainingMapTasksPerSlot", "RemainingReduceTasks", "RunningMapTasks", "RunningReduceTasks", "S3BytesRead", "S3BytesWritten", "TaskNodesPending", "TaskNodesRunning", "TotalLoad"
32+
// ],
33+
// "AWS/Kinesis": [
34+
// "PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Success", "PutRecords.Bytes", "PutRecords.Latency", "PutRecords.Records", "PutRecords.Success", "IncomingBytes", "IncomingRecords", "GetRecords.Bytes", "GetRecords.IteratorAgeMilliseconds", "GetRecords.Latency", "GetRecords.Success"
35+
// ],
36+
// "AWS/ML": [
37+
// "PredictCount", "PredictFailureCount"
38+
// ],
39+
// "AWS/OpsWorks": [
40+
// "cpu_idle", "cpu_nice", "cpu_system", "cpu_user", "cpu_waitio", "load_1", "load_5", "load_15", "memory_buffers", "memory_cached", "memory_free", "memory_swap", "memory_total", "memory_used", "procs"
41+
// ],
42+
// "AWS/Redshift": [
43+
// "CPUUtilization", "DatabaseConnections", "HealthStatus", "MaintenanceMode", "NetworkReceiveThroughput", "NetworkTransmitThroughput", "PercentageDiskSpaceUsed", "ReadIOPS", "ReadLatency", "ReadThroughput", "WriteIOPS", "WriteLatency", "WriteThroughput"
44+
// ],
45+
// "AWS/RDS": [
46+
// "BinLogDiskUsage", "CPUUtilization", "DatabaseConnections", "DiskQueueDepth", "FreeableMemory", "FreeStorageSpace", "ReplicaLag", "SwapUsage", "ReadIOPS", "WriteIOPS", "ReadLatency", "WriteLatency", "ReadThroughput", "WriteThroughput", "NetworkReceiveThroughput", "NetworkTransmitThroughput"
47+
// ],
48+
// "AWS/Route53": [
49+
// "HealthCheckStatus", "HealthCheckPercentageHealthy"
50+
// ],
51+
// "AWS/SNS": [
52+
// "NumberOfMessagesPublished", "PublishSize", "NumberOfNotificationsDelivered", "NumberOfNotificationsFailed"
53+
// ],
54+
// "AWS/SQS": [
55+
// "NumberOfMessagesSent", "SentMessageSize", "NumberOfMessagesReceived", "NumberOfEmptyReceives", "NumberOfMessagesDeleted", "ApproximateNumberOfMessagesDelayed", "ApproximateNumberOfMessagesVisible", "ApproximateNumberOfMessagesNotVisible"
56+
// ],
57+
// "AWS/S3": [
58+
// "BucketSizeBytes", "NumberOfObjects"
59+
// ],
60+
// "AWS/SWF": [
61+
// "DecisionTaskScheduleToStartTime", "DecisionTaskStartToCloseTime", "DecisionTasksCompleted", "StartedDecisionTasksTimedOutOnClose", "WorkflowStartToCloseTime", "WorkflowsCanceled", "WorkflowsCompleted", "WorkflowsContinuedAsNew", "WorkflowsFailed", "WorkflowsTerminated", "WorkflowsTimedOut"
62+
// ],
63+
// "AWS/StorageGateway": [
64+
// "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "CloudBytesDownloaded", "CloudDownloadLatency", "CloudBytesUploaded", "UploadBufferFree", "UploadBufferPercentUsed", "UploadBufferUsed", "QueuedWrites", "ReadBytes", "ReadTime", "TotalCacheSize", "WriteBytes", "WriteTime", "WorkingStorageFree", "WorkingStoragePercentUsed", "WorkingStorageUsed", "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "ReadBytes", "ReadTime", "WriteBytes", "WriteTime", "QueuedWrites"
65+
// ],
66+
// "AWS/WorkSpaces": [
67+
// "Available", "Unhealthy", "ConnectionAttempt", "ConnectionSuccess", "ConnectionFailure", "SessionLaunchTime", "InSessionLatency", "SessionDisconnect"
68+
// ],
69+
// };
70+
71+
func handleGetRegions(req *cwRequest, c *middleware.Context) {
72+
regions := []string{
73+
"us-west-2", "us-west-1", "eu-west-1", "eu-central-1", "ap-southeast-1",
74+
"ap-southeast-2", "ap-northeast-1", "sa-east-1",
75+
}
76+
77+
result := []interface{}{}
78+
for _, region := range regions {
79+
result = append(result, util.DynMap{"text": region, "value": region})
80+
}
81+
82+
c.JSON(200, result)
83+
}
84+
85+
func handleGetNamespaces(req *cwRequest, c *middleware.Context) {
86+
result := []interface{}{}
87+
for key, _ := range metricsMap {
88+
result = append(result, util.DynMap{"text": key, "value": key})
89+
}
90+
91+
c.JSON(200, result)
92+
}
93+
94+
func handleGetMetrics(req *cwRequest, c *middleware.Context) {
95+
reqParam := &struct {
96+
Parameters struct {
97+
Namespace string `json:"namespace"`
98+
} `json:"parameters"`
99+
}{}
100+
101+
json.Unmarshal(req.Body, reqParam)
102+
103+
namespaceMetrics, exists := metricsMap[reqParam.Parameters.Namespace]
104+
if !exists {
105+
c.JsonApiErr(404, "Unable to find namespace "+reqParam.Parameters.Namespace, nil)
106+
return
107+
}
108+
109+
result := []interface{}{}
110+
for _, name := range namespaceMetrics {
111+
result = append(result, util.DynMap{"text": name, "value": name})
112+
}
113+
114+
c.JSON(200, result)
115+
}

public/app/plugins/datasource/cloudwatch/datasource.js

Lines changed: 9 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -18,197 +18,8 @@ function (angular, _) {
1818
this.supportMetrics = true;
1919
this.proxyUrl = datasource.url;
2020
this.defaultRegion = datasource.jsonData.defaultRegion;
21-
22-
/* jshint -W101 */
23-
24-
this.supportedMetrics = {
25-
'AWS/AutoScaling': [
26-
'GroupMinSize', 'GroupMaxSize', 'GroupDesiredCapacity', 'GroupInServiceInstances', 'GroupPendingInstances', 'GroupStandbyInstances', 'GroupTerminatingInstances', 'GroupTotalInstances'
27-
],
28-
'AWS/Billing': [
29-
'EstimatedCharges'
30-
],
31-
'AWS/CloudFront': [
32-
'Requests', 'BytesDownloaded', 'BytesUploaded', 'TotalErrorRate', '4xxErrorRate', '5xxErrorRate'
33-
],
34-
'AWS/CloudSearch': [
35-
'SuccessfulRequests', 'SearchableDocuments', 'IndexUtilization', 'Partitions'
36-
],
37-
'AWS/DynamoDB': [
38-
'ConditionalCheckFailedRequests', 'ConsumedReadCapacityUnits', 'ConsumedWriteCapacityUnits', 'OnlineIndexConsumedWriteCapacity', 'OnlineIndexPercentageProgress', 'OnlineIndexThrottleEvents', 'ProvisionedReadCapacityUnits', 'ProvisionedWriteCapacityUnits', 'ReadThrottleEvents', 'ReturnedItemCount', 'SuccessfulRequestLatency', 'SystemErrors', 'ThrottledRequests', 'UserErrors', 'WriteThrottleEvents'
39-
],
40-
'AWS/ElastiCache': [
41-
'CPUUtilization', 'SwapUsage', 'FreeableMemory', 'NetworkBytesIn', 'NetworkBytesOut',
42-
'BytesUsedForCacheItems', 'BytesReadIntoMemcached', 'BytesWrittenOutFromMemcached', 'CasBadval', 'CasHits', 'CasMisses', 'CmdFlush', 'CmdGet', 'CmdSet', 'CurrConnections', 'CurrItems', 'DecrHits', 'DecrMisses', 'DeleteHits', 'DeleteMisses', 'Evictions', 'GetHits', 'GetMisses', 'IncrHits', 'IncrMisses', 'Reclaimed',
43-
'CurrConnections', 'Evictions', 'Reclaimed', 'NewConnections', 'BytesUsedForCache', 'CacheHits', 'CacheMisses', 'ReplicationLag', 'GetTypeCmds', 'SetTypeCmds', 'KeyBasedCmds', 'StringBasedCmds', 'HashBasedCmds', 'ListBasedCmds', 'SetBasedCmds', 'SortedSetBasedCmds', 'CurrItems'
44-
],
45-
'AWS/EBS': [
46-
'VolumeReadBytes', 'VolumeWriteBytes', 'VolumeReadOps', 'VolumeWriteOps', 'VolumeTotalReadTime', 'VolumeTotalWriteTime', 'VolumeIdleTime', 'VolumeQueueLength', 'VolumeThroughputPercentage', 'VolumeConsumedReadWriteOps'
47-
],
48-
'AWS/EC2': [
49-
'CPUCreditUsage', 'CPUCreditBalance', 'CPUUtilization', 'DiskReadOps', 'DiskWriteOps', 'DiskReadBytes', 'DiskWriteBytes', 'NetworkIn', 'NetworkOut', 'StatusCheckFailed', 'StatusCheckFailed_Instance', 'StatusCheckFailed_System'
50-
],
51-
'AWS/ELB': [
52-
'HealthyHostCount', 'UnHealthyHostCount', 'RequestCount', 'Latency', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX', 'BackendConnectionErrors', 'SurgeQueueLength', 'SpilloverCount'
53-
],
54-
'AWS/ElasticMapReduce': [
55-
'CoreNodesPending', 'CoreNodesRunning', 'HBaseBackupFailed', 'HBaseMostRecentBackupDuration', 'HBaseTimeSinceLastSuccessfulBackup', 'HDFSBytesRead', 'HDFSBytesWritten', 'HDFSUtilization', 'IsIdle', 'JobsFailed', 'JobsRunning', 'LiveDataNodes', 'LiveTaskTrackers', 'MapSlotsOpen', 'MissingBlocks', 'ReduceSlotsOpen', 'RemainingMapTasks', 'RemainingMapTasksPerSlot', 'RemainingReduceTasks', 'RunningMapTasks', 'RunningReduceTasks', 'S3BytesRead', 'S3BytesWritten', 'TaskNodesPending', 'TaskNodesRunning', 'TotalLoad'
56-
],
57-
'AWS/Kinesis': [
58-
'PutRecord.Bytes', 'PutRecord.Latency', 'PutRecord.Success', 'PutRecords.Bytes', 'PutRecords.Latency', 'PutRecords.Records', 'PutRecords.Success', 'IncomingBytes', 'IncomingRecords', 'GetRecords.Bytes', 'GetRecords.IteratorAgeMilliseconds', 'GetRecords.Latency', 'GetRecords.Success'
59-
],
60-
'AWS/ML': [
61-
'PredictCount', 'PredictFailureCount'
62-
],
63-
'AWS/OpsWorks': [
64-
'cpu_idle', 'cpu_nice', 'cpu_system', 'cpu_user', 'cpu_waitio', 'load_1', 'load_5', 'load_15', 'memory_buffers', 'memory_cached', 'memory_free', 'memory_swap', 'memory_total', 'memory_used', 'procs'
65-
],
66-
'AWS/Redshift': [
67-
'CPUUtilization', 'DatabaseConnections', 'HealthStatus', 'MaintenanceMode', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'PercentageDiskSpaceUsed', 'ReadIOPS', 'ReadLatency', 'ReadThroughput', 'WriteIOPS', 'WriteLatency', 'WriteThroughput'
68-
],
69-
'AWS/RDS': [
70-
'BinLogDiskUsage', 'CPUUtilization', 'DatabaseConnections', 'DiskQueueDepth', 'FreeableMemory', 'FreeStorageSpace', 'ReplicaLag', 'SwapUsage', 'ReadIOPS', 'WriteIOPS', 'ReadLatency', 'WriteLatency', 'ReadThroughput', 'WriteThroughput', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput'
71-
],
72-
'AWS/Route53': [
73-
'HealthCheckStatus', 'HealthCheckPercentageHealthy'
74-
],
75-
'AWS/SNS': [
76-
'NumberOfMessagesPublished', 'PublishSize', 'NumberOfNotificationsDelivered', 'NumberOfNotificationsFailed'
77-
],
78-
'AWS/SQS': [
79-
'NumberOfMessagesSent', 'SentMessageSize', 'NumberOfMessagesReceived', 'NumberOfEmptyReceives', 'NumberOfMessagesDeleted', 'ApproximateNumberOfMessagesDelayed', 'ApproximateNumberOfMessagesVisible', 'ApproximateNumberOfMessagesNotVisible'
80-
],
81-
'AWS/S3': [
82-
'BucketSizeBytes', 'NumberOfObjects'
83-
],
84-
'AWS/SWF': [
85-
'DecisionTaskScheduleToStartTime', 'DecisionTaskStartToCloseTime', 'DecisionTasksCompleted', 'StartedDecisionTasksTimedOutOnClose', 'WorkflowStartToCloseTime', 'WorkflowsCanceled', 'WorkflowsCompleted', 'WorkflowsContinuedAsNew', 'WorkflowsFailed', 'WorkflowsTerminated', 'WorkflowsTimedOut'
86-
],
87-
'AWS/StorageGateway': [
88-
'CacheHitPercent', 'CachePercentUsed', 'CachePercentDirty', 'CloudBytesDownloaded', 'CloudDownloadLatency', 'CloudBytesUploaded', 'UploadBufferFree', 'UploadBufferPercentUsed', 'UploadBufferUsed', 'QueuedWrites', 'ReadBytes', 'ReadTime', 'TotalCacheSize', 'WriteBytes', 'WriteTime', 'WorkingStorageFree', 'WorkingStoragePercentUsed', 'WorkingStorageUsed', 'CacheHitPercent', 'CachePercentUsed', 'CachePercentDirty', 'ReadBytes', 'ReadTime', 'WriteBytes', 'WriteTime', 'QueuedWrites'
89-
],
90-
'AWS/WorkSpaces': [
91-
'Available', 'Unhealthy', 'ConnectionAttempt', 'ConnectionSuccess', 'ConnectionFailure', 'SessionLaunchTime', 'InSessionLatency', 'SessionDisconnect'
92-
],
93-
};
94-
95-
this.supportedDimensions = {
96-
'AWS/AutoScaling': [
97-
'AutoScalingGroupName'
98-
],
99-
'AWS/Billing': [
100-
'ServiceName', 'LinkedAccount', 'Currency'
101-
],
102-
'AWS/CloudFront': [
103-
'DistributionId', 'Region'
104-
],
105-
'AWS/CloudSearch': [
106-
107-
],
108-
'AWS/DynamoDB': [
109-
'TableName', 'GlobalSecondaryIndexName', 'Operation'
110-
],
111-
'AWS/ElastiCache': [
112-
'CacheClusterId', 'CacheNodeId'
113-
],
114-
'AWS/EBS': [
115-
'VolumeId'
116-
],
117-
'AWS/EC2': [
118-
'AutoScalingGroupName', 'ImageId', 'InstanceId', 'InstanceType'
119-
],
120-
'AWS/ELB': [
121-
'LoadBalancerName', 'AvailabilityZone'
122-
],
123-
'AWS/ElasticMapReduce': [
124-
'ClusterId', 'JobId'
125-
],
126-
'AWS/Kinesis': [
127-
'StreamName'
128-
],
129-
'AWS/ML': [
130-
'MLModelId', 'RequestMode'
131-
],
132-
'AWS/OpsWorks': [
133-
'StackId', 'LayerId', 'InstanceId'
134-
],
135-
'AWS/Redshift': [
136-
'NodeID', 'ClusterIdentifier'
137-
],
138-
'AWS/RDS': [
139-
'DBInstanceIdentifier', 'DatabaseClass', 'EngineName'
140-
],
141-
'AWS/Route53': [
142-
'HealthCheckId'
143-
],
144-
'AWS/SNS': [
145-
'Application', 'Platform', 'TopicName'
146-
],
147-
'AWS/SQS': [
148-
'QueueName'
149-
],
150-
'AWS/S3': [
151-
'BucketName', 'StorageType'
152-
],
153-
'AWS/SWF': [
154-
'Domain', 'ActivityTypeName', 'ActivityTypeVersion'
155-
],
156-
'AWS/StorageGateway': [
157-
'GatewayId', 'GatewayName', 'VolumeId'
158-
],
159-
'AWS/WorkSpaces': [
160-
'DirectoryId', 'WorkspaceId'
161-
],
162-
};
163-
/* jshint +W101 */
164-
165-
/* load custom metrics definitions */
166-
var self = this;
167-
$q.all(
168-
_.chain(datasource.jsonData.customMetricsAttributes)
169-
.reject(function(u) {
170-
return _.isEmpty(u);
171-
})
172-
.map(function(u) {
173-
return backendSrv.datasourceRequest({ method: 'GET', url: u });
174-
})
175-
)
176-
.then(function(allResponse) {
177-
_.chain(allResponse)
178-
.map(function(d) {
179-
return d.data.Metrics;
180-
})
181-
.flatten()
182-
.reject(function(metric) {
183-
return metric.Namespace.indexOf('AWS/') === 0;
184-
})
185-
.map(function(metric) {
186-
metric.Dimensions = _.chain(metric.Dimensions)
187-
.map(function(d) {
188-
return d.Name;
189-
})
190-
.value().sort();
191-
return metric;
192-
})
193-
.uniq(function(metric) {
194-
return metric.Namespace + metric.MetricName + metric.Dimensions.join('');
195-
})
196-
.each(function(metric) {
197-
if (!_.has(self.supportedMetrics, metric.Namespace)) {
198-
self.supportedMetrics[metric.Namespace] = [];
199-
}
200-
self.supportedMetrics[metric.Namespace].push(metric.MetricName);
201-
202-
if (!_.has(self.supportedDimensions, metric.Namespace)) {
203-
self.supportedDimensions[metric.Namespace] = [];
204-
}
205-
206-
self.supportedDimensions[metric.Namespace] = _.union(self.supportedDimensions[metric.Namespace], metric.Dimensions);
207-
});
208-
});
20921
}
21022

211-
// Called once per panel (graph)
21223
CloudWatchDatasource.prototype.query = function(options) {
21324
var start = convertToCloudWatchTime(options.range.from);
21425
var end = convertToCloudWatchTime(options.range.to);
@@ -280,12 +91,16 @@ function (angular, _) {
28091
};
28192

28293
CloudWatchDatasource.prototype.getNamespaces = function() {
283-
return $q.when(_.keys(this.supportedMetrics));
94+
return this.awsRequest({action: '__GetNamespaces'});
28495
};
28596

28697
CloudWatchDatasource.prototype.getMetrics = function(namespace) {
287-
namespace = templateSrv.replace(namespace);
288-
return $q.when(this.supportedMetrics[namespace] || []);
98+
return this.awsRequest({
99+
action: '__GetMetrics',
100+
parameters: {
101+
namespace: templateSrv.replace(namespace)
102+
}
103+
});
289104
};
290105

291106
CloudWatchDatasource.prototype.getDimensionKeys = function(namespace) {
@@ -342,13 +157,12 @@ function (angular, _) {
342157

343158
var namespaceQuery = query.match(/^namespaces\(\)/);
344159
if (namespaceQuery) {
345-
return this.getNamespaces().then(transformSuggestData);
160+
return this.getNamespaces();
346161
}
347162

348163
var metricNameQuery = query.match(/^metrics\(([^\)]+?)\)/);
349164
if (metricNameQuery) {
350-
namespace = templateSrv.replace(metricNameQuery[1]);
351-
return this.getMetrics(namespace).then(transformSuggestData);
165+
return this.getMetrics(metricNameQuery[1]);
352166
}
353167

354168
var dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)\)/);

0 commit comments

Comments
 (0)