mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
4c654ddb76
* 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>
56 lines
1.1 KiB
Go
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
|
|
}
|