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

Skip adding display name prefix for metrics with custom domain #273

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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