diff --git a/pkg/tsdb/stackdriver/stackdriver.go b/pkg/tsdb/stackdriver/stackdriver.go
index 94edd0ab52d..d0725fca071 100644
--- a/pkg/tsdb/stackdriver/stackdriver.go
+++ b/pkg/tsdb/stackdriver/stackdriver.go
@@ -29,10 +29,9 @@ import (
)
var (
- slog log.Logger
- legendKeyFormat *regexp.Regexp
- longMetricNameFormat *regexp.Regexp
- shortMetricNameFormat *regexp.Regexp
+ slog log.Logger
+ legendKeyFormat *regexp.Regexp
+ metricNameFormat *regexp.Regexp
)
// StackdriverExecutor executes queries for the Stackdriver datasource
@@ -58,8 +57,7 @@ func init() {
slog = log.New("tsdb.stackdriver")
tsdb.RegisterTsdbQueryEndpoint("stackdriver", NewStackdriverExecutor)
legendKeyFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
- longMetricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/([\w\d_]+)/(.+)`)
- shortMetricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
+ metricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
}
// Query takes in the frontend queries, parses them into the Stackdriver query format
@@ -410,27 +408,16 @@ func formatLegendKeys(metricType string, defaultMetricName string, metricLabels
func replaceWithMetricPart(metaPartName string, metricType string) []byte {
// https://cloud.google.com/monitoring/api/v3/metrics-details#label_names
- longMatches := longMetricNameFormat.FindStringSubmatch(metricType)
- shortMatches := shortMetricNameFormat.FindStringSubmatch(metricType)
+ shortMatches := metricNameFormat.FindStringSubmatch(metricType)
if metaPartName == "metric.name" {
- if len(longMatches) > 0 {
- return []byte(longMatches[3])
- } else if len(shortMatches) > 0 {
+ if len(shortMatches) > 0 {
return []byte(shortMatches[2])
}
}
- if metaPartName == "metric.category" {
- if len(longMatches) > 0 {
- return []byte(longMatches[2])
- }
- }
-
if metaPartName == "metric.service" {
- if len(longMatches) > 0 {
- return []byte(longMatches[1])
- } else if len(shortMatches) > 0 {
+ if len(shortMatches) > 0 {
return []byte(shortMatches[1])
}
}
diff --git a/pkg/tsdb/stackdriver/stackdriver_test.go b/pkg/tsdb/stackdriver/stackdriver_test.go
index 022c876d178..b460de6cdbc 100644
--- a/pkg/tsdb/stackdriver/stackdriver_test.go
+++ b/pkg/tsdb/stackdriver/stackdriver_test.go
@@ -329,15 +329,15 @@ func TestStackdriver(t *testing.T) {
Convey("and the alias pattern is for metric name", func() {
- query := &StackdriverQuery{AliasBy: "metric {{metric.name}} service {{metric.service}} category {{metric.category}}", GroupBys: []string{"metric.label.instance_name", "resource.label.zone"}}
+ query := &StackdriverQuery{AliasBy: "metric {{metric.name}} service {{metric.service}}", GroupBys: []string{"metric.label.instance_name", "resource.label.zone"}}
err = executor.parseResponse(res, data, query)
So(err, ShouldBeNil)
Convey("Should use alias by formatting and only show instance name", func() {
So(len(res.Series), ShouldEqual, 3)
- So(res.Series[0].Name, ShouldEqual, "metric cpu/usage_time service compute category instance")
- So(res.Series[1].Name, ShouldEqual, "metric cpu/usage_time service compute category instance")
- So(res.Series[2].Name, ShouldEqual, "metric cpu/usage_time service compute category instance")
+ So(res.Series[0].Name, ShouldEqual, "metric instance/cpu/usage_time service compute")
+ So(res.Series[1].Name, ShouldEqual, "metric instance/cpu/usage_time service compute")
+ So(res.Series[2].Name, ShouldEqual, "metric instance/cpu/usage_time service compute")
})
})
})
diff --git a/public/app/plugins/datasource/stackdriver/partials/query.editor.html b/public/app/plugins/datasource/stackdriver/partials/query.editor.html
index 256a854830d..1d3b6c93e76 100755
--- a/public/app/plugins/datasource/stackdriver/partials/query.editor.html
+++ b/public/app/plugins/datasource/stackdriver/partials/query.editor.html
@@ -49,8 +49,7 @@
Patterns:
{{metric.type}}
= metric type e.g. compute.googleapis.com/instance/cpu/usage_time
- {{metric.name}}
= name part of metric e.g. cpu/usage_time
- {{metric.category}}
= category part of metric e.g. instance
+ {{metric.name}}
= name part of metric e.g. instance/cpu/usage_time
{{metric.service}}
= service part of metric e.g. compute
{{metric.label.label_name}}
= Metric label metadata e.g. metric.label.instance_name