Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Skip adding displa name prefix for metrics with custom domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Nail Islamov committed Aug 10, 2020
1 parent 366afe7 commit e3c7f0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions metrics_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,26 @@ func TestProtoToMonitoringMetricDescriptor(t *testing.T) {
Unit: "By",
},
},
{
in: &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "external.googleapis.com/user/with_domain",
Description: "With metric descriptor and domain prefix",
Unit: "By",
},
},
statsExporter: &statsExporter{
o: Options{ProjectID: "test"},
},
want: &googlemetricpb.MetricDescriptor{
Name: "projects/test/metricDescriptors/external.googleapis.com/user/with_domain",
Type: "external.googleapis.com/user/with_domain",
Labels: []*labelpb.LabelDescriptor{},
DisplayName: "external.googleapis.com/user/with_domain",
Description: "With metric descriptor and domain prefix",
Unit: "By",
},
},
}

for i, tt := range tests {
Expand Down
4 changes: 4 additions & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ func (e *statsExporter) createMetricDescriptorFromView(ctx context.Context, v *v
}

func (e *statsExporter) displayName(suffix string) string {
if hasDomain(suffix) {
// If the display name suffix is already prefixed with domain, skip adding extra prefix
return suffix
}
return path.Join(defaultDisplayNamePrefix, suffix)
}

Expand Down

0 comments on commit e3c7f0c

Please sign in to comment.