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

Commit 19b2ae7

Browse files
authored
Skip adding displa name prefix for metrics with custom domain (#273)
1 parent 366afe7 commit 19b2ae7

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

metrics_proto_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,26 @@ func TestProtoToMonitoringMetricDescriptor(t *testing.T) {
621621
Unit: "By",
622622
},
623623
},
624+
{
625+
in: &metricspb.Metric{
626+
MetricDescriptor: &metricspb.MetricDescriptor{
627+
Name: "external.googleapis.com/user/with_domain",
628+
Description: "With metric descriptor and domain prefix",
629+
Unit: "By",
630+
},
631+
},
632+
statsExporter: &statsExporter{
633+
o: Options{ProjectID: "test"},
634+
},
635+
want: &googlemetricpb.MetricDescriptor{
636+
Name: "projects/test/metricDescriptors/external.googleapis.com/user/with_domain",
637+
Type: "external.googleapis.com/user/with_domain",
638+
Labels: []*labelpb.LabelDescriptor{},
639+
DisplayName: "external.googleapis.com/user/with_domain",
640+
Description: "With metric descriptor and domain prefix",
641+
Unit: "By",
642+
},
643+
},
624644
}
625645

626646
for i, tt := range tests {

stats.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ func (e *statsExporter) createMetricDescriptorFromView(ctx context.Context, v *v
365365
}
366366

367367
func (e *statsExporter) displayName(suffix string) string {
368+
if hasDomain(suffix) {
369+
// If the display name suffix is already prefixed with domain, skip adding extra prefix
370+
return suffix
371+
}
368372
return path.Join(defaultDisplayNamePrefix, suffix)
369373
}
370374

0 commit comments

Comments
 (0)