From 404a2803e308580e942d34ce06d3d36cac09e02a Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Thu, 4 Jun 2020 09:48:43 -0700 Subject: [PATCH 1/2] Hard code expected labels on obsreport tests The goal is to prevent inadvertent changes of the labels. Using hard coded values requires manual changes of the tests. --- obsreport/obsreport_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index b7456de087e..581ab1b23ad 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -44,6 +44,15 @@ const ( var ( errFake = errors.New("errFake") + + // Names used by the metrics and labels are hard coded here in order to avoid + // inadvertent changes: at this point changing metric names and labeles should + // be treated as a breaking changing and requires a good justification. + // DO NOT SWITCH THE VARIABLES BELOW TO SIMILAR ONES DEFINED ON THE PACKAGE. + receiverTag, _ = tag.NewKey("receiver") + transportTag, _ = tag.NewKey("transport") + exporterTag, _ = tag.NewKey("exporter") + processorTag, _ = tag.NewKey("processor") ) type receiveTestParams struct { @@ -579,20 +588,20 @@ func checkValueForSumView(t *testing.T, vName string, wantTags []tag.Tag, value func receiverViewTags(receiver, transport string) []tag.Tag { return []tag.Tag{ - {Key: tagKeyReceiver, Value: receiver}, - {Key: tagKeyTransport, Value: transport}, + {Key: receiverTag, Value: receiver}, + {Key: transportTag, Value: transport}, } } func exporterViewTags(exporter string) []tag.Tag { return []tag.Tag{ - {Key: tagKeyExporter, Value: exporter}, + {Key: exporterTag, Value: exporter}, } } func processorViewTags(processor string) []tag.Tag { return []tag.Tag{ - {Key: tagKeyProcessor, Value: processor}, + {Key: processorTag, Value: processor}, } } From 79bad9c19b9d9a4e06e09e9367ba4d4c27395652 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Thu, 4 Jun 2020 10:00:29 -0700 Subject: [PATCH 2/2] Add reason to be careful about metric name and label changes --- obsreport/obsreport_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 581ab1b23ad..18c42cba93e 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -46,8 +46,10 @@ var ( errFake = errors.New("errFake") // Names used by the metrics and labels are hard coded here in order to avoid - // inadvertent changes: at this point changing metric names and labeles should + // inadvertent changes: at this point changing metric names and labels should // be treated as a breaking changing and requires a good justification. + // Changes to metric names or labels can break alerting, dashboards, etc + // that are used to monitor the Collector in production deployments. // DO NOT SWITCH THE VARIABLES BELOW TO SIMILAR ONES DEFINED ON THE PACKAGE. receiverTag, _ = tag.NewKey("receiver") transportTag, _ = tag.NewKey("transport")