CloudMonitoring: Fix INT64 label unmarshal error (#39441)

This commit is contained in:
Benedikt Spellmeyer
2021-09-22 17:05:36 +02:00
committed by GitHub
parent c75737c808
commit f76a11c955
4 changed files with 13 additions and 8 deletions

View File

@@ -942,7 +942,7 @@ func TestCloudMonitoring(t *testing.T) {
query := &cloudMonitoringTimeSeriesQuery{ query := &cloudMonitoringTimeSeriesQuery{
ProjectName: "test-proj", ProjectName: "test-proj",
Query: "test-query", Query: "test-query",
AliasBy: "{{project}} - {{resource.label.zone}} - {{resource.label.instance_id}}", AliasBy: "{{project}} - {{resource.label.zone}} - {{resource.label.instance_id}} - {{metric.label.response_code_class}}",
timeRange: plugins.DataTimeRange{ timeRange: plugins.DataTimeRange{
From: fmt.Sprintf("%v", fromStart.Unix()*1000), From: fmt.Sprintf("%v", fromStart.Unix()*1000),
To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000), To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000),
@@ -952,7 +952,7 @@ func TestCloudMonitoring(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
frames, err := res.Dataframes.Decoded() frames, err := res.Dataframes.Decoded()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "test-proj - asia-northeast1-c - 6724404429462225363", frames[0].Fields[1].Name) assert.Equal(t, "test-proj - asia-northeast1-c - 6724404429462225363 - 200", frames[0].Fields[1].Name)
}) })
}) })
}) })

View File

@@ -9,6 +9,10 @@
}, },
{ {
"key": "resource.instance_id" "key": "resource.instance_id"
},
{
"key": "metric.response_code_class",
"valueType": "INT64"
} }
], ],
"pointDescriptors": [ "pointDescriptors": [
@@ -30,6 +34,9 @@
}, },
{ {
"stringValue": "6724404429462225363" "stringValue": "6724404429462225363"
},
{
"int64Value": "200"
} }
], ],
"pointData": [ "pointData": [

View File

@@ -123,9 +123,8 @@ func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) parseResponse(queryRes *pl
labels[key][strVal] = true labels[key][strVal] = true
seriesLabels[key] = strVal seriesLabels[key] = strVal
case "INT64": case "INT64":
intVal := strconv.FormatInt(labelValue.Int64Value, 10) labels[key][labelValue.Int64Value] = true
labels[key][intVal] = true seriesLabels[key] = labelValue.Int64Value
seriesLabels[key] = intVal
default: default:
labels[key][labelValue.StringValue] = true labels[key][labelValue.StringValue] = true
seriesLabels[key] = labelValue.StringValue seriesLabels[key] = labelValue.StringValue
@@ -285,8 +284,7 @@ func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) parseToAnnotations(queryRe
strVal := strconv.FormatBool(labelValue.BoolValue) strVal := strconv.FormatBool(labelValue.BoolValue)
value = strVal value = strVal
case "INT64": case "INT64":
intVal := strconv.FormatInt(labelValue.Int64Value, 10) value = labelValue.Int64Value
value = intVal
default: default:
value = labelValue.StringValue value = labelValue.StringValue
} }

View File

@@ -118,7 +118,7 @@ type timeSeriesDescriptor struct {
type timeSeriesData []struct { type timeSeriesData []struct {
LabelValues []struct { LabelValues []struct {
BoolValue bool `json:"boolValue"` BoolValue bool `json:"boolValue"`
Int64Value int64 `json:"int64Value"` Int64Value string `json:"int64Value"`
StringValue string `json:"stringValue"` StringValue string `json:"stringValue"`
} `json:"labelValues"` } `json:"labelValues"`
PointData []struct { PointData []struct {