grafana/pkg/tsdb/cloudwatch/models/request/dimension_keys_request.go
Erik Sundell 4c654ddb76
Cloudwatch: Refactor metrics resource request (#57424)
* refactor metrics request

* Update pkg/tsdb/cloudwatch/routes/dimension_keys_test.go

Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>

* return metric struct value intead of pointer

* make it possible to test hard coded metrics service

* test all paths in route

* fix broken test

* fix one more broken test

* add integration test

Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>
2022-10-25 14:00:54 +02:00

56 lines
1.1 KiB
Go

package request
import (
"net/url"
)
type DimensionKeysRequestType uint32
const (
StandardDimensionKeysRequest DimensionKeysRequestType = iota
FilterDimensionKeysRequest
CustomMetricDimensionKeysRequest
)
type DimensionKeysRequest struct {
*ResourceRequest
Namespace string
MetricName string
DimensionFilter []*Dimension
}
func (q *DimensionKeysRequest) Type() DimensionKeysRequestType {
if isCustomNamespace(q.Namespace) {
return CustomMetricDimensionKeysRequest
}
if len(q.DimensionFilter) > 0 {
return FilterDimensionKeysRequest
}
return StandardDimensionKeysRequest
}
func GetDimensionKeysRequest(parameters url.Values) (*DimensionKeysRequest, error) {
resourceRequest, err := getResourceRequest(parameters)
if err != nil {
return nil, err
}
request := &DimensionKeysRequest{
ResourceRequest: resourceRequest,
Namespace: parameters.Get("namespace"),
MetricName: parameters.Get("metricName"),
DimensionFilter: []*Dimension{},
}
dimensions, err := parseDimensionFilter(parameters.Get("dimensionFilters"))
if err != nil {
return nil, err
}
request.DimensionFilter = dimensions
return request, nil
}