stackdriver: remove metric.category alias pattern

After discussions with the Stackdriver team, they did not think this was
needed.
pull/13289/head
Daniel Lee 7 years ago
parent a25389332c
commit 399e83f91b
  1. 27
      pkg/tsdb/stackdriver/stackdriver.go
  2. 8
      pkg/tsdb/stackdriver/stackdriver_test.go
  3. 3
      public/app/plugins/datasource/stackdriver/partials/query.editor.html

@ -29,10 +29,9 @@ import (
) )
var ( var (
slog log.Logger slog log.Logger
legendKeyFormat *regexp.Regexp legendKeyFormat *regexp.Regexp
longMetricNameFormat *regexp.Regexp metricNameFormat *regexp.Regexp
shortMetricNameFormat *regexp.Regexp
) )
// StackdriverExecutor executes queries for the Stackdriver datasource // StackdriverExecutor executes queries for the Stackdriver datasource
@ -58,8 +57,7 @@ func init() {
slog = log.New("tsdb.stackdriver") slog = log.New("tsdb.stackdriver")
tsdb.RegisterTsdbQueryEndpoint("stackdriver", NewStackdriverExecutor) tsdb.RegisterTsdbQueryEndpoint("stackdriver", NewStackdriverExecutor)
legendKeyFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`) legendKeyFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
longMetricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/([\w\d_]+)/(.+)`) metricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
shortMetricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
} }
// Query takes in the frontend queries, parses them into the Stackdriver query format // 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 { func replaceWithMetricPart(metaPartName string, metricType string) []byte {
// https://cloud.google.com/monitoring/api/v3/metrics-details#label_names // https://cloud.google.com/monitoring/api/v3/metrics-details#label_names
longMatches := longMetricNameFormat.FindStringSubmatch(metricType) shortMatches := metricNameFormat.FindStringSubmatch(metricType)
shortMatches := shortMetricNameFormat.FindStringSubmatch(metricType)
if metaPartName == "metric.name" { if metaPartName == "metric.name" {
if len(longMatches) > 0 { if len(shortMatches) > 0 {
return []byte(longMatches[3])
} else if len(shortMatches) > 0 {
return []byte(shortMatches[2]) return []byte(shortMatches[2])
} }
} }
if metaPartName == "metric.category" {
if len(longMatches) > 0 {
return []byte(longMatches[2])
}
}
if metaPartName == "metric.service" { if metaPartName == "metric.service" {
if len(longMatches) > 0 { if len(shortMatches) > 0 {
return []byte(longMatches[1])
} else if len(shortMatches) > 0 {
return []byte(shortMatches[1]) return []byte(shortMatches[1])
} }
} }

@ -329,15 +329,15 @@ func TestStackdriver(t *testing.T) {
Convey("and the alias pattern is for metric name", func() { 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) err = executor.parseResponse(res, data, query)
So(err, ShouldBeNil) So(err, ShouldBeNil)
Convey("Should use alias by formatting and only show instance name", func() { Convey("Should use alias by formatting and only show instance name", func() {
So(len(res.Series), ShouldEqual, 3) So(len(res.Series), ShouldEqual, 3)
So(res.Series[0].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 cpu/usage_time service compute category instance") So(res.Series[1].Name, ShouldEqual, "metric instance/cpu/usage_time service compute")
So(res.Series[2].Name, ShouldEqual, "metric cpu/usage_time service compute category instance") So(res.Series[2].Name, ShouldEqual, "metric instance/cpu/usage_time service compute")
}) })
}) })
}) })

@ -49,8 +49,7 @@
Patterns: Patterns:
<code ng-non-bindable>{{metric.type}}</code> = metric type e.g. compute.googleapis.com/instance/cpu/usage_time <code ng-non-bindable>{{metric.type}}</code> = metric type e.g. compute.googleapis.com/instance/cpu/usage_time
<code ng-non-bindable>{{metric.name}}</code> = name part of metric e.g. cpu/usage_time <code ng-non-bindable>{{metric.name}}</code> = name part of metric e.g. instance/cpu/usage_time
<code ng-non-bindable>{{metric.category}}</code> = category part of metric e.g. instance
<code ng-non-bindable>{{metric.service}}</code> = service part of metric e.g. compute <code ng-non-bindable>{{metric.service}}</code> = service part of metric e.g. compute
<code ng-non-bindable>{{metric.label.label_name}}</code> = Metric label metadata e.g. metric.label.instance_name <code ng-non-bindable>{{metric.label.label_name}}</code> = Metric label metadata e.g. metric.label.instance_name

Loading…
Cancel
Save