forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsd_test.go
More file actions
52 lines (41 loc) · 1.71 KB
/
Copy pathstatsd_test.go
File metadata and controls
52 lines (41 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 2025-present Datadog, Inc.
//go:build test
package aggregator
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"go.uber.org/fx"
hostnameinterface "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface/mock"
"github.com/DataDog/datadog-agent/pkg/metrics"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)
func TestStatsdDirect(t *testing.T) {
opts := DefaultAgentDemultiplexerOptions()
opts.FlushInterval = time.Hour
opts.DontStartForwarders = true
demuxDeps := createDemultiplexerAgentTestDeps(t)
demux := initAgentDemultiplexer(demuxDeps.Log, NewForwarderTest(demuxDeps.Log), demuxDeps.OrchestratorFwd, opts, demuxDeps.EventPlatform, demuxDeps.HaAgent, demuxDeps.Compressor, demuxDeps.Tagger, demuxDeps.FilterList, "")
hostnameComp := fxutil.Test[hostnameinterface.Mock](t,
fx.Options(
hostnameinterface.MockModule(),
fx.Replace(hostnameinterface.MockHostname("my-hostname")),
),
)
statsd, err := NewStatsdDirect(demux, hostnameComp)
require.NoError(t, err)
err = statsd.Gauge("test.gauge", 1.0, []string{"tag1:value1", "tag2:value2"}, 1.0)
require.NoError(t, err)
samples := <-demux.statsd.workers[0].samplesChan
require.Len(t, samples, 1)
sample := samples[0]
require.Equal(t, "test.gauge", sample.Name)
require.Equal(t, 1.0, sample.Value)
require.Equal(t, []string{"tag1:value1", "tag2:value2"}, sample.Tags)
require.Equal(t, "my-hostname", sample.Host)
require.Equal(t, 1.0, sample.SampleRate)
require.Equal(t, metrics.GaugeType, sample.Mtype)
}