mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* use new layered architecture in get dimension keys request * go lint fixes * pr feedback * more pr feedback * remove not used code * refactor route middleware * change signature * add integration tests for the dimension keys route * use request suffix instead of query * use typed args also in frontend * remove unused import * harmonize naming * fix merge conflict
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package clients
|
|
|
|
import (
|
|
"github.com/aws/aws-sdk-go/aws/awsutil"
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
|
)
|
|
|
|
type metricsClient struct {
|
|
models.CloudWatchMetricsAPIProvider
|
|
config *setting.Cfg
|
|
}
|
|
|
|
func NewMetricsClient(api models.CloudWatchMetricsAPIProvider, config *setting.Cfg) *metricsClient {
|
|
return &metricsClient{CloudWatchMetricsAPIProvider: api, config: config}
|
|
}
|
|
|
|
func (l *metricsClient) ListMetricsWithPageLimit(params *cloudwatch.ListMetricsInput) ([]*cloudwatch.Metric, error) {
|
|
var cloudWatchMetrics []*cloudwatch.Metric
|
|
pageNum := 0
|
|
err := l.ListMetricsPages(params, func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
|
|
pageNum++
|
|
metrics.MAwsCloudWatchListMetrics.Inc()
|
|
metrics, err := awsutil.ValuesAtPath(page, "Metrics")
|
|
if err == nil {
|
|
for _, metric := range metrics {
|
|
cloudWatchMetrics = append(cloudWatchMetrics, metric.(*cloudwatch.Metric))
|
|
}
|
|
}
|
|
return !lastPage && pageNum < l.config.AWSListMetricsPageLimit
|
|
})
|
|
|
|
return cloudWatchMetrics, err
|
|
}
|