Skip to content

Commit

Permalink
move to golden fixture file instead of resource_metrics (#5771)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Jan 10, 2025
1 parent 18fabd1 commit 456eccc
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 30 deletions.
30 changes: 28 additions & 2 deletions tests/general/discoverymode/host_observer_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"testing"
"time"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
Expand Down Expand Up @@ -119,8 +121,32 @@ func TestHostObserver(t *testing.T) {
promPid := strings.TrimSpace(stdout)
require.Zero(t, sc, stderr)

expectedResourceMetrics := tc.ResourceMetrics("host-observer-internal-prometheus.yaml")
require.NoError(t, tc.OTLPReceiverSink.AssertAllMetricsReceived(t, *expectedResourceMetrics, 30*time.Second))
expected, err := golden.ReadMetrics(filepath.Join("testdata", "expected", "host-observer-internal-prometheus-expected.yaml"))
require.NoError(t, err)
assert.EventuallyWithT(t, func(tt *assert.CollectT) {
if len(tc.OTLPReceiverSink.AllMetrics()) == 0 {
assert.Fail(tt, "No metrics collected")
return
}
err := pmetrictest.CompareMetrics(expected, tc.OTLPReceiverSink.AllMetrics()[len(tc.OTLPReceiverSink.AllMetrics())-1],
pmetrictest.IgnoreResourceAttributeValue("service.instance.id"),
pmetrictest.IgnoreResourceAttributeValue("net.host.port"),
pmetrictest.IgnoreResourceAttributeValue("server.port"),
pmetrictest.IgnoreResourceAttributeValue("service.name"),
pmetrictest.IgnoreResourceAttributeValue("service_instance_id"),
pmetrictest.IgnoreResourceAttributeValue("service_version"),
pmetrictest.IgnoreMetricAttributeValue("service_version"),
pmetrictest.IgnoreMetricAttributeValue("service_instance_id"),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
)
assert.NoError(tt, err)
}, 30*time.Second, 1*time.Second)

expectedInitial := map[string]any{
"file": map[string]any{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
resourceMetrics:
- resource:
attributes:
- key: http.scheme
value:
stringValue: http
- key: label_one
value:
stringValue: actual.label.one.value.from.env.var
- key: label_three
value:
stringValue: actual.label.three.value.from.cmdline.property
- key: label_two
value:
stringValue: actual.label.two.value.from.env.var
- key: net.host.port
value:
stringValue: "52144"
- key: server.port
value:
stringValue: "52144"
- key: service.instance.id
value:
stringValue: 127.0.0.1:52144
- key: service.name
value:
stringValue: prometheus_simple/127.0.0.1:52144
- key: service_instance_id
value:
stringValue: b3d7e86d-d1fb-47be-9ecc-d3bc4f5b552d
- key: service_name
value:
stringValue: otelcol
- key: service_version
value:
stringValue: v0.115.0
- key: url.scheme
value:
stringValue: http
scopeMetrics:
- metrics:
- description: Uptime of the process [alpha]
metadata:
- key: prometheus.type
value:
stringValue: counter
name: otelcol_process_uptime
sum:
aggregationTemporality: 2
dataPoints:
- asDouble: 21.150509204
attributes:
- key: label_one
value:
stringValue: actual.label.one.value.from.env.var
- key: label_three
value:
stringValue: actual.label.three.value.from.cmdline.property
- key: label_two
value:
stringValue: actual.label.two.value.from.env.var
- key: service_instance_id
value:
stringValue: b3d7e86d-d1fb-47be-9ecc-d3bc4f5b552d
- key: service_name
value:
stringValue: otelcol
- key: service_version
value:
stringValue: v0.115.0
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver
version: v0.115.0

This file was deleted.

0 comments on commit 456eccc

Please sign in to comment.