mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudMonitoring: Use response unit instead of metric descriptor unit (#32928)
* improve unit detection * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * goimports * fix typo * golint fixes * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * pr feedback * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
@@ -893,77 +893,34 @@ func TestCloudMonitoring(t *testing.T) {
|
||||
assert.Equal(t, "select_slo_compliance(\"projects/test-proj/services/test-service/serviceLevelObjectives/test-slo\")", frames[0].Fields[1].Name)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Parse cloud monitoring unit", func(t *testing.T) {
|
||||
t.Run("when there is only one query", func(t *testing.T) {
|
||||
t.Run("and cloud monitoring unit does not have a corresponding grafana unit", func(t *testing.T) {
|
||||
executors := []cloudMonitoringQueryExecutor{
|
||||
&cloudMonitoringTimeSeriesFilter{Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance", Service: "test-service",
|
||||
Slo: "test-slo", Unit: "megaseconds"},
|
||||
}
|
||||
unit := executor.resolvePanelUnitFromQueries(executors)
|
||||
assert.Equal(t, "", unit)
|
||||
t.Run("Parse cloud monitoring unit", func(t *testing.T) {
|
||||
t.Run("when mapping is found a unit should be specified on the field config", func(t *testing.T) {
|
||||
data, err := loadTestFile("./test-data/1-series-response-agg-one-metric.json")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(data.TimeSeries))
|
||||
|
||||
res := &plugins.DataQueryResult{Meta: simplejson.New(), RefID: "A"}
|
||||
query := &cloudMonitoringTimeSeriesFilter{Params: url.Values{}}
|
||||
err = query.parseResponse(res, data, "")
|
||||
require.NoError(t, err)
|
||||
frames, err := res.Dataframes.Decoded()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Bps", frames[0].Fields[1].Config.Unit)
|
||||
})
|
||||
|
||||
t.Run("and cloud monitoring unit has a corresponding grafana unit", func(t *testing.T) {
|
||||
for key, element := range cloudMonitoringUnitMappings {
|
||||
queries := []cloudMonitoringQueryExecutor{
|
||||
&cloudMonitoringTimeSeriesFilter{Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance", Service: "test-service",
|
||||
Slo: "test-slo", Unit: key},
|
||||
}
|
||||
unit := executor.resolvePanelUnitFromQueries(queries)
|
||||
assert.Equal(t, element, unit)
|
||||
}
|
||||
})
|
||||
})
|
||||
t.Run("when mapping is found a unit should be specified on the field config", func(t *testing.T) {
|
||||
data, err := loadTestFile("./test-data/2-series-response-no-agg.json")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 3, len(data.TimeSeries))
|
||||
|
||||
t.Run("when there are more than one query", func(t *testing.T) {
|
||||
t.Run("and all target units are the same", func(t *testing.T) {
|
||||
for key, element := range cloudMonitoringUnitMappings {
|
||||
queries := []cloudMonitoringQueryExecutor{
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service1", Slo: "test-slo", Unit: key,
|
||||
},
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service2", Slo: "test-slo", Unit: key,
|
||||
},
|
||||
}
|
||||
unit := executor.resolvePanelUnitFromQueries(queries)
|
||||
assert.Equal(t, element, unit)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("and all target units are the same but does not have grafana mappings", func(t *testing.T) {
|
||||
queries := []cloudMonitoringQueryExecutor{
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service1", Slo: "test-slo", Unit: "megaseconds",
|
||||
},
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service2", Slo: "test-slo", Unit: "megaseconds",
|
||||
},
|
||||
}
|
||||
unit := executor.resolvePanelUnitFromQueries(queries)
|
||||
assert.Equal(t, "", unit)
|
||||
})
|
||||
|
||||
t.Run("and all target units are not the same", func(t *testing.T) {
|
||||
queries := []cloudMonitoringQueryExecutor{
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service1", Slo: "test-slo", Unit: "bit",
|
||||
},
|
||||
&cloudMonitoringTimeSeriesFilter{
|
||||
Params: url.Values{}, ProjectName: "test-proj", Selector: "select_slo_compliance",
|
||||
Service: "test-service2", Slo: "test-slo", Unit: "min",
|
||||
},
|
||||
}
|
||||
unit := executor.resolvePanelUnitFromQueries(queries)
|
||||
assert.Equal(t, "", unit)
|
||||
res := &plugins.DataQueryResult{Meta: simplejson.New(), RefID: "A"}
|
||||
query := &cloudMonitoringTimeSeriesFilter{Params: url.Values{}}
|
||||
err = query.parseResponse(res, data, "")
|
||||
require.NoError(t, err)
|
||||
frames, err := res.Dataframes.Decoded()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "", frames[0].Fields[1].Config.Unit)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user