Skip to content

Commit

Permalink
Remove __v1_type tag
Browse files Browse the repository at this point in the history
- Metrics that were received initially as v1 metrics include a __v1_type
  tag to indicate the type of v1 metric that was emitted.
- This causes issues for the prometheus exporter as:
  'Label names beginning with __ (two "_") are reserved for internal use.'
  https://prometheus.io/docs/concepts/data_model/
- Remove the __v1_type tag during the conversion so that these metrics
  will be acceptable to prometheus exporters.

Fixes:

  "__v1_type" is not a valid label name for metric

Signed-off-by: Rebecca Roberts <robertsre@vmware.com>
  • Loading branch information
acrmp committed Dec 4, 2023
1 parent ce6cb79 commit b51fa0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pkg/otelcolclient/otelcolclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func attributes(e *loggregator_v2.Envelope) []*commonpb.KeyValue {
}

for k, v := range e.Tags {
if k == "instance_id" || k == "source_id" {
if k == "instance_id" || k == "source_id" || k == "__v1_type" {
continue
}

Expand Down
14 changes: 14 additions & 0 deletions src/pkg/otelcolclient/otelcolclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ var _ = Describe("Client", func() {
Expect(cmp.Diff(actualAtts, expectedAtts, protocmp.Transform(), sortFunc)).To(BeEmpty())
})
})

Context("when the envelope has been converted from a v1 representation", func() {
BeforeEach(func() {
envelope.Tags["__v1_type"] = "ValueMetric"
})

It("drops the __v1_type tag", func() {
var msr *colmetricspb.ExportMetricsServiceRequest
Expect(spyMSC.requests).To(Receive(&msr))

actualAtts := msr.GetResourceMetrics()[0].GetScopeMetrics()[0].GetMetrics()[0].GetGauge().GetDataPoints()[0].GetAttributes()
Expect(actualAtts).ToNot(ContainElement(HaveField("Key", "__v1_type")))
})
})
})

Context("when given a counter", func() {
Expand Down

0 comments on commit b51fa0c

Please sign in to comment.