CloudMonitoring: Remove link setting for SLO queries (#53031)

This commit is contained in:
Andres Martinez Gotor 2022-08-01 14:53:09 +02:00 committed by GitHub
parent 58ff0f07b4
commit 314eb5223f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -658,12 +658,14 @@ func addConfigData(frames data.Frames, dl string, unit string) data.Frames {
if frames[i].Fields[1].Config == nil { if frames[i].Fields[1].Config == nil {
frames[i].Fields[1].Config = &data.FieldConfig{} frames[i].Fields[1].Config = &data.FieldConfig{}
} }
if len(dl) > 0 {
deepLink := data.DataLink{ deepLink := data.DataLink{
Title: "View in Metrics Explorer", Title: "View in Metrics Explorer",
TargetBlank: true, TargetBlank: true,
URL: dl, URL: dl,
} }
frames[i].Fields[1].Config.Links = append(frames[i].Fields[1].Config.Links, deepLink) frames[i].Fields[1].Config.Links = append(frames[i].Fields[1].Config.Links, deepLink)
}
if len(unit) > 0 { if len(unit) > 0 {
if val, ok := cloudMonitoringUnitMappings[unit]; ok { if val, ok := cloudMonitoringUnitMappings[unit]; ok {
frames[i].Fields[1].Config.Unit = val frames[i].Fields[1].Config.Unit = val

View File

@ -459,6 +459,19 @@ func TestTimeSeriesFilter(t *testing.T) {
}, *res.Frames[0].Meta) }, *res.Frames[0].Meta)
}) })
}) })
t.Run("when data comes from a slo query, it should skip the link", func(t *testing.T) {
data, err := loadTestFile("./test-data/3-series-response-distribution-exponential.json")
require.NoError(t, err)
assert.Equal(t, 1, len(data.TimeSeries))
res := &backend.DataResponse{}
query := &cloudMonitoringTimeSeriesFilter{Params: url.Values{}, Slo: "yes"}
err = query.parseResponse(res, data, "")
require.NoError(t, err)
frames := res.Frames
assert.Equal(t, len(frames[0].Fields[1].Config.Links), 0)
})
} }
func loadTestFile(path string) (cloudMonitoringResponse, error) { func loadTestFile(path string) (cloudMonitoringResponse, error) {