grafana/pkg/tsdb/cloudwatch/routes/dimension_values.go
Shabeeb Khalid 8f96d23eee
CloudWatch: Use context in aws ListMetricsPages (#76938)
Use context in aws ListMetricsPages

Use ListMetricsPagesWithContext and pass context in related sub calls
2023-10-23 16:17:06 +02:00

37 lines
1.3 KiB
Go

package routes
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
)
func DimensionValuesHandler(ctx context.Context, pluginCtx backend.PluginContext, reqCtxFactory models.RequestContextFactoryFunc, parameters url.Values) ([]byte, *models.HttpError) {
dimensionValuesRequest, err := resources.GetDimensionValuesRequest(parameters)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusBadRequest, err)
}
service, err := newListMetricsService(ctx, pluginCtx, reqCtxFactory, dimensionValuesRequest.Region)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
response, err := service.GetDimensionValuesByDimensionFilter(ctx, dimensionValuesRequest)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
dimensionValuesResponse, err := json.Marshal(response)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
return dimensionValuesResponse, nil
}