Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTEL-2362] Test metric origins in otel e2e test #33011

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
receivers:
hostmetrics:
collection_interval: 10s
scrapers:
load:
memory:
exporters:
datadog:
metrics:
resource_attributes_as_tags: true
hostname: "otelcol-docker"
api:
key: ${env:DD_API_KEY}
service:
pipelines:
metrics:
receivers: [hostmetrics]
exporters: [datadog]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// Package otelagent contains e2e otel agent tests
package otelagent

import (
_ "embed"
"testing"

"github.com/DataDog/test-infra-definitions/components/datadog/kubernetesagentparams"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
awskubernetes "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/kubernetes"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/otel/utils"
)

type hostmetricsreceiverTestSuite struct {
e2e.BaseSuite[environments.Kubernetes]
}

//go:embed config/hostmetricsreceiver.yml
var hostmetricsreceiverConfig string

func TestOTelAgentHostmetricsReceiver(t *testing.T) {
values := `
datadog:
logs:
containerCollectAll: false
containerCollectUsingFiles: false
`
t.Parallel()
e2e.Run(t, &hostmetricsreceiverTestSuite{},
e2e.WithProvisioner(
awskubernetes.KindProvisioner(
awskubernetes.WithAgentOptions(
kubernetesagentparams.WithHelmValues(values),
kubernetesagentparams.WithOTelAgent(),
kubernetesagentparams.WithOTelConfig(hostmetricsreceiverConfig),
))))
}

func (s *hostmetricsreceiverTestSuite) TestOTelAgentInstalled() {
utils.TestOTelAgentInstalled(s)
}

func (s *hostmetricsreceiverTestSuite) TestHostMetrics() {
utils.TestHostMetrics(s)
}
42 changes: 42 additions & 0 deletions test/new-e2e/tests/otel/utils/pipelines_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ func TestAPMStats(s OTelTestSuite, numTraces int, computeTopLevelBySpanKind bool
s.T().Log("Got APM stats", stats)
}

const (
// https://github.com/DataDog/dd-source/blob/3b6316543b8a5c64078fe75ca79e4825ecc624b1/domains/metrics/shared/libs/proto/origin/origin.proto#L188
originProductDatadogExporter = 19
// https://github.com/DataDog/dd-source/blob/3b6316543b8a5c64078fe75ca79e4825ecc624b1/domains/metrics/shared/libs/proto/origin/origin.proto#L765
originCategoryPrometheusReceiver = 238
// https://github.com/DataDog/dd-source/blob/3b6316543b8a5c64078fe75ca79e4825ecc624b1/domains/metrics/shared/libs/proto/origin/origin.proto#L751
originCategoryHostmetricsReceiver = 224
)

// TestPrometheusMetrics tests that expected prometheus metrics are scraped
func TestPrometheusMetrics(s OTelTestSuite) {
err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators()
Expand All @@ -430,15 +439,48 @@ func TestPrometheusMetrics(s OTelTestSuite) {
otelcolMetrics, err = s.Env().FakeIntake.Client().FilterMetrics("otelcol_process_uptime")
assert.NoError(c, err)
assert.NotEmpty(c, otelcolMetrics)
for _, m := range otelcolMetrics {
origin := m.Metadata.Origin
assert.Equal(c, originProductDatadogExporter, int(origin.OriginProduct))
assert.Equal(c, originCategoryPrometheusReceiver, int(origin.OriginCategory))
}

traceAgentMetrics, err = s.Env().FakeIntake.Client().FilterMetrics("otelcol_datadog_trace_agent_trace_writer_spans")
assert.NoError(c, err)
assert.NotEmpty(c, traceAgentMetrics)
for _, m := range otelcolMetrics {
origin := m.Metadata.Origin
assert.Equal(c, originProductDatadogExporter, int(origin.OriginProduct))
assert.Equal(c, originCategoryPrometheusReceiver, int(origin.OriginCategory))
}
}, 2*time.Minute, 10*time.Second)
s.T().Log("Got otelcol_process_uptime", otelcolMetrics)
s.T().Log("Got otelcol_datadog_trace_agent_trace_writer_spans", traceAgentMetrics)
}

// TestHostMetrics tests that expected host metrics are scraped
func TestHostMetrics(s OTelTestSuite) {
err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators()
require.NoError(s.T(), err)
s.T().Log("Waiting for metrics")
expectedMetrics := []string{
"otel.system.cpu.load_average.15m",
"otel.system.cpu.load_average.5m",
"otel.system.memory.usage",
}
require.EventuallyWithT(s.T(), func(c *assert.CollectT) {
for _, m := range expectedMetrics {
metrics, err := s.Env().FakeIntake.Client().FilterMetrics(m)
assert.NoError(c, err)
s.T().Log("Got host metric", metrics)
assert.Len(c, metrics, 1)
origin := metrics[0].Metadata.Origin
assert.Equal(c, originProductDatadogExporter, int(origin.OriginProduct))
assert.Equal(c, originCategoryHostmetricsReceiver, int(origin.OriginCategory))
}
}, 1*time.Minute, 10*time.Second)
}

// SetupSampleTraces flushes the intake server and starts a telemetrygen job to generate traces
func SetupSampleTraces(s OTelTestSuite) {
ctx := context.Background()
Expand Down
Loading