Skip to content

Instantly share code, notes, and snippets.

@MadVikingGod
Created August 19, 2022 16:07
Show Gist options
  • Save MadVikingGod/0512885403357cda46f0f8eac8e79838 to your computer and use it in GitHub Desktop.
Save MadVikingGod/0512885403357cda46f0f8eac8e79838 to your computer and use it in GitHub Desktop.
otel AssertEqual outputs

This is an example of how test data compares when using different levels of metricdatatest.AssertEqual.

Asserting at the Metrics level

var tt.want metricsdata.Metrics
var rm metricsdata.ResourceMetrics // This was from Collect()

require.Len(t, rm.ScopeMetrics, 1)
sm := rm.ScopeMetrics[0]
require.Len(t, sm.Metrics, 1)
got := sm.Metrics[0]
metricdatatest.AssertEqual(t, tt.want, got, metricdatatest.IgnoreTimestamp())
    --- FAIL: TestMeterCreatesInstruments/AyncFloat64Gauge (0.00s)
        meter_test.go:292: [Name not equal:
            expected: agauge2
            actual: agauge]

Asserting at the ResourceMetrics level

var tt.want metricsdata.Metrics
var rm metricsdata.ResourceMetrics // This was from Collect()

want := metricdata.ResourceMetrics{
  ScopeMetrics: []metricdata.ScopeMetrics{
    {
      Scope: instrumentation.Scope{Name: "testInstruments"},
      Metrics: []metricdata.Metrics{
        tt.want,
      },
    },
  },
}
metricdatatest.AssertEqual(t, want, rm, metricdatatest.IgnoreTimestamp())
--- FAIL: TestMeterCreatesInstruments/AyncFloat64Gauge (0.00s)
    meter_test.go:304: [ResourceMetrics ScopeMetrics not equal:
        missing expected values:
        metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"testInstruments", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"agauge2", Description:"", Unit:"", Data:metricdata.Gauge[float64]{DataPoints:[]metricdata.DataPoint[float64]{metricdata.DataPoint[float64]{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:interface {}(nil)}}, StartTime:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Value:11}}}}}}
        unexpected additional values:
        metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"testInstruments", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"agauge", Description:"", Unit:"", Data:metricdata.Gauge[float64]{DataPoints:[]metricdata.DataPoint[float64]{metricdata.DataPoint[float64]{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[0]attribute.KeyValue{}}}, StartTime:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Time:time.Date(2022, time.August, 19, 15, 53, 36, 960390100, time.Local), Value:11}}}}}}
        ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment