CloudWatch: Remove references to pkg/infra/metrics (#81744)

CloudWatch: remove references to pkg/infra/metrics
This commit is contained in:
Isabella Siu 2024-02-06 14:21:55 -05:00 committed by GitHub
parent aafff73899
commit 3b852bb582
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 35 deletions

View File

@ -81,15 +81,6 @@ var (
// MAlertingNotificationSent is a metric counter for how many alert notifications that failed
MAlertingNotificationFailed *prometheus.CounterVec
// MAwsCloudWatchGetMetricStatistics is a metric counter for getting metric statistics from aws
MAwsCloudWatchGetMetricStatistics prometheus.Counter
// MAwsCloudWatchListMetrics is a metric counter for getting list of metrics from aws
MAwsCloudWatchListMetrics prometheus.Counter
// MAwsCloudWatchGetMetricData is a metric counter for getting metric data time series from aws
MAwsCloudWatchGetMetricData prometheus.Counter
// MDBDataSourceQueryByID is a metric counter for getting datasource by id
MDBDataSourceQueryByID prometheus.Counter
@ -397,24 +388,6 @@ func init() {
Namespace: ExporterName,
}, []string{"type"})
MAwsCloudWatchGetMetricStatistics = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "aws_cloudwatch_get_metric_statistics_total",
Help: "counter for getting metric statistics from aws",
Namespace: ExporterName,
})
MAwsCloudWatchListMetrics = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "aws_cloudwatch_list_metrics_total",
Help: "counter for getting list of metrics from aws",
Namespace: ExporterName,
})
MAwsCloudWatchGetMetricData = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "aws_cloudwatch_get_metric_data_total",
Help: "counter for getting metric data time series from aws",
Namespace: ExporterName,
})
MDBDataSourceQueryByID = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "db_datasource_query_by_id_total",
Help: "counter for getting datasource by id",
@ -763,9 +736,6 @@ func initMetricVars(reg prometheus.Registerer) {
MAlertingResultState,
MAlertingNotificationSent,
MAlertingNotificationFailed,
MAwsCloudWatchGetMetricStatistics,
MAwsCloudWatchListMetrics,
MAwsCloudWatchGetMetricData,
MDBDataSourceQueryByID,
LDAPUsersSyncExecutionTime,
MRenderingRequestTotal,

View File

@ -5,9 +5,9 @@ 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/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
// this client wraps the CloudWatch API and handles pagination and the composition of the MetricResponse DTO
@ -25,7 +25,7 @@ func (l *metricsClient) ListMetricsWithPageLimit(ctx context.Context, params *cl
pageNum := 0
err := l.ListMetricsPagesWithContext(ctx, params, func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
pageNum++
metrics.MAwsCloudWatchListMetrics.Inc()
utils.QueriesTotalCounter.WithLabelValues(utils.ListMetricsLabel).Inc()
metrics, err := awsutil.ValuesAtPath(page, "Metrics")
if err == nil {
for idx, metric := range metrics {

View File

@ -6,7 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
func (e *cloudWatchExecutor) executeRequest(ctx context.Context, client cloudwatchiface.CloudWatchAPI,
@ -24,8 +24,7 @@ func (e *cloudWatchExecutor) executeRequest(ctx context.Context, client cloudwat
}
mdo = append(mdo, resp)
metrics.MAwsCloudWatchGetMetricData.Add(float64(len(metricDataInput.MetricDataQueries)))
utils.QueriesTotalCounter.WithLabelValues(utils.GetMetricDataLabel).Add(float64(len(metricDataInput.MetricDataQueries)))
if resp.NextToken == nil || *resp.NextToken == "" {
break
}

View File

@ -0,0 +1,22 @@
package utils
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
// Labels for the metric counter query types
ListMetricsLabel = "list_metrics"
GetMetricDataLabel = "get_metric_data"
)
var QueriesTotalCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "grafana_plugin",
Name: "aws_cloudwatch_queries_total",
Help: "Counter for AWS Queries",
},
[]string{"query_type"},
)