Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 98b8f9c

Browse files
authored
receiver/prometheus: ignore XXX_sizecache in test comparison. (#540)
1 parent 77effe5 commit 98b8f9c

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

receiver/prometheusreceiver/metrics_receiver_test.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,22 @@ buffer_count: 2
199199

200200
close(shutdownCh)
201201
gotMDs := cms.AllMetrics()
202+
if len(gotMDs) == 0 {
203+
t.Errorf("Want at least one Metric. Got zero.")
204+
}
202205

203206
// Now compare the received metrics data with what we expect.
204207
wantNode := &commonpb.Node{
205208
Identifier: &commonpb.ProcessIdentifier{
206-
HostName: host,
207-
XXX_sizecache: 11,
209+
HostName: host,
208210
},
209211
ServiceInfo: &commonpb.ServiceInfo{
210-
Name: "demo",
211-
XXX_sizecache: 6,
212+
Name: "demo",
212213
},
213214
Attributes: map[string]string{
214215
"scheme": "http",
215216
"port": port,
216217
},
217-
XXX_sizecache: 52,
218218
}
219219

220220
wantMetricPb1 := &metricspb.Metric{
@@ -223,9 +223,8 @@ buffer_count: 2
223223
Description: "The number of calls",
224224
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
225225
LabelKeys: []*metricspb.LabelKey{
226-
{Key: "method", XXX_sizecache: 8},
226+
{Key: "method"},
227227
},
228-
XXX_sizecache: 56,
229228
},
230229
Timeseries: []*metricspb.TimeSeries{
231230
{
@@ -249,9 +248,8 @@ buffer_count: 2
249248
Description: "The latency in milliseconds per call",
250249
Type: metricspb.MetricDescriptor_CUMULATIVE_DISTRIBUTION,
251250
LabelKeys: []*metricspb.LabelKey{
252-
{Key: "method", XXX_sizecache: 8},
251+
{Key: "method"},
253252
},
254-
XXX_sizecache: 56,
255253
},
256254
Timeseries: []*metricspb.TimeSeries{
257255
{
@@ -290,7 +288,7 @@ buffer_count: 2
290288

291289
for _, md := range gotMDs {
292290
node := md.Node
293-
if diff := cmp.Diff(node, wantNode); diff != "" {
291+
if diff := cmpNodePb(node, wantNode); diff != "" {
294292
t.Errorf("Mismatch Node\n-Got +Want:\n%s", diff)
295293
}
296294
metricPbs := md.Metrics
@@ -314,7 +312,22 @@ func (producer *fakeProducer) Read() []*metricdata.Metric {
314312
return producer.metrics
315313
}
316314

315+
func cmpNodePb(got, want *commonpb.Node) string {
316+
// Ignore all "XXX_sizecache" fields.
317+
return cmp.Diff(
318+
got,
319+
want,
320+
cmpopts.IgnoreFields(commonpb.Node{}, "XXX_sizecache"),
321+
cmpopts.IgnoreFields(commonpb.ProcessIdentifier{}, "XXX_sizecache"),
322+
cmpopts.IgnoreFields(commonpb.ServiceInfo{}, "XXX_sizecache"))
323+
}
324+
317325
func cmpMetricPb(got, want *metricspb.Metric) string {
318326
// Start and end time are non-deteministic. Ignore them when do the comparison.
319-
return cmp.Diff(got, want, cmpopts.IgnoreTypes(&timestamp.Timestamp{}))
327+
return cmp.Diff(
328+
got,
329+
want,
330+
cmpopts.IgnoreTypes(&timestamp.Timestamp{}),
331+
cmpopts.IgnoreFields(metricspb.MetricDescriptor{}, "XXX_sizecache"),
332+
cmpopts.IgnoreFields(metricspb.LabelKey{}, "XXX_sizecache"))
320333
}

0 commit comments

Comments
 (0)