Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions comp/dogstatsd/http/impl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ go_library(
"//pkg/proto/pbgo/dogstatsdhttp",
"//pkg/tagger/types",
"//pkg/tagset",
"//pkg/util/strings",
"//pkg/util/metricname",
],
)

Expand All @@ -48,7 +48,7 @@ dd_agent_go_test(
"//pkg/metrics",
"//pkg/proto/pbgo/dogstatsdhttp",
"//pkg/tagset",
"//pkg/util/strings",
"//pkg/util/metricname",
"@com_github_stretchr_testify//require",
],
)
6 changes: 3 additions & 3 deletions comp/dogstatsd/http/impl/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/dogstatsdhttp"
"github.com/DataDog/datadog-agent/pkg/tagset"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

// payloadStats counts what a single payload contributed. Accumulated as the
Expand All @@ -36,7 +36,7 @@ type iteratorCommon struct {
reader *reader.MetricDataReader
origin origin
hostname string
filterList utilstrings.Matcher
filterList metricname.Matcher
stats payloadStats
err error
}
Expand Down Expand Up @@ -83,7 +83,7 @@ type seriesIterator struct {
buffer metrics.Serie
}

func newSeriesIterator(payload *pb.Payload, origin origin, hostname string, filterList utilstrings.Matcher) (*seriesIterator, error) {
func newSeriesIterator(payload *pb.Payload, origin origin, hostname string, filterList metricname.Matcher) (*seriesIterator, error) {
it := &seriesIterator{
iteratorCommon: iteratorCommon{
reader: reader.NewMetricDataReader(payload.MetricData),
Expand Down
20 changes: 10 additions & 10 deletions comp/dogstatsd/http/impl/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/dogstatsdhttp"
"github.com/DataDog/datadog-agent/pkg/tagset"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

// seriesTestPayload builds a payload holding the count `foo` (1 point), the
Expand Down Expand Up @@ -68,7 +68,7 @@ func seriesTestOrigin(t *testing.T) origin {
}

func TestIterator(t *testing.T) {
it, err := newSeriesIterator(seriesTestPayload(), seriesTestOrigin(t), "default", utilstrings.Matcher{})
it, err := newSeriesIterator(seriesTestPayload(), seriesTestOrigin(t), "default", metricname.Matcher{})
require.NoError(t, err)
require.NotNil(t, it)

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestIterator(t *testing.T) {
func TestIteratorFilterList(t *testing.T) {
t.Run("exact match skips the metric", func(t *testing.T) {
it, err := newSeriesIterator(seriesTestPayload(), seriesTestOrigin(t), "default",
utilstrings.NewMatcher([]string{"bar"}, false))
metricname.NewMatcher([]string{"bar"}, false))
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand All @@ -134,7 +134,7 @@ func TestIteratorFilterList(t *testing.T) {

t.Run("prefix match skips every matching metric", func(t *testing.T) {
it, err := newSeriesIterator(seriesTestPayload(), seriesTestOrigin(t), "default",
utilstrings.NewMatcher([]string{"ba"}, true))
metricname.NewMatcher([]string{"ba"}, true))
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand All @@ -147,7 +147,7 @@ func TestIteratorFilterList(t *testing.T) {

t.Run("everything filtered", func(t *testing.T) {
it, err := newSeriesIterator(seriesTestPayload(), seriesTestOrigin(t), "default",
utilstrings.NewMatcher([]string{"foo", "bar", "baz"}, false))
metricname.NewMatcher([]string{"foo", "bar", "baz"}, false))
require.NoError(t, err)

require.False(t, it.MoveNext())
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestIteratorTagCardinality(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
it, err := newSeriesIterator(payload([]uint64{tc.packedType}), seriesTestOrigin(t), "default",
utilstrings.Matcher{})
metricname.Matcher{})
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand All @@ -215,7 +215,7 @@ func TestIteratorTagCardinality(t *testing.T) {
p.MetricData.DictTagStr = []byte("\x03ook\x15dd.internal.card:high")
p.MetricData.DictTagsets = []int64{2, 1, 1}

it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", utilstrings.Matcher{})
it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", metricname.Matcher{})
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand All @@ -231,7 +231,7 @@ func TestIteratorTagCardinality(t *testing.T) {
p.MetricData.DictTagStr = []byte("\x03ook\x15dd.internal.card:high")
p.MetricData.DictTagsets = []int64{2, 1, 1}

it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", utilstrings.Matcher{})
it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", metricname.Matcher{})
require.NoError(t, err)

// Both metrics reference the same filtered dictionary entry.
Expand All @@ -248,7 +248,7 @@ func TestIteratorTagCardinality(t *testing.T) {
p.MetricData.DictTagStr = []byte("\x15dd.internal.card:high\x14dd.internal.card:low")
p.MetricData.DictTagsets = []int64{2, 1, 1}

it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", utilstrings.Matcher{})
it, err := newSeriesIterator(p, seriesTestOrigin(t), "default", metricname.Matcher{})
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand All @@ -260,7 +260,7 @@ func TestIteratorTagCardinality(t *testing.T) {
t.Run("origin tags are resolved once per cardinality", func(t *testing.T) {
it, err := newSeriesIterator(
payload([]uint64{0x13, 0x13 | uint64(pb.TagCardinality_High), 0x13}),
seriesTestOrigin(t), "default", utilstrings.Matcher{})
seriesTestOrigin(t), "default", metricname.Matcher{})
require.NoError(t, err)

for range 3 {
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/http/impl/sketch_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/http/impl/internal/reader"
"github.com/DataDog/datadog-agent/pkg/metrics"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/dogstatsdhttp"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

// sketchData holds one sketch point's reader-provided columns and summary.
Expand Down Expand Up @@ -50,7 +50,7 @@ type sketchIterator struct {
buffer dogstatsdSketchSeries
}

func newSketchIterator(payload *pb.Payload, origin origin, hostname string, filterList utilstrings.Matcher) (*sketchIterator, error) {
func newSketchIterator(payload *pb.Payload, origin origin, hostname string, filterList metricname.Matcher) (*sketchIterator, error) {
it := &sketchIterator{
iteratorCommon: iteratorCommon{
reader: reader.NewMetricDataReader(payload.MetricData),
Expand Down
12 changes: 6 additions & 6 deletions comp/dogstatsd/http/impl/sketch_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/dogstatsdhttp"
"github.com/DataDog/datadog-agent/pkg/tagset"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

func TestSketchIterator(t *testing.T) {
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestSketchIterator(t *testing.T) {
origin, err := originFromHeader(header, tagger)
require.NoError(t, err)

it, err := newSketchIterator(payload, origin, "default", utilstrings.Matcher{})
it, err := newSketchIterator(payload, origin, "default", metricname.Matcher{})
require.NoError(t, err)
require.NotNil(t, it)

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestSketchIteratorFilterList(t *testing.T) {
origin, err := originFromHeader(http.Header{}, tagger)
require.NoError(t, err)

it, err := newSketchIterator(payload, origin, "default", utilstrings.NewMatcher([]string{"foo"}, false))
it, err := newSketchIterator(payload, origin, "default", metricname.NewMatcher([]string{"foo"}, false))
require.NoError(t, err)

// bar's summary and bins must not be shifted by foo's skipped points.
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestSketchIteratorTagMerging(t *testing.T) {
origin, err := originFromHeader(header, tagger)
require.NoError(t, err)

it, err := newSketchIterator(payload, origin, "default", utilstrings.Matcher{})
it, err := newSketchIterator(payload, origin, "default", metricname.Matcher{})
require.NoError(t, err)

require.True(t, it.MoveNext())
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestSketchIteratorHostOverride(t *testing.T) {
header := http.Header{}
origin, err := originFromHeader(header, tagger)
require.NoError(t, err)
it, err := newSketchIterator(payload, origin, "default", utilstrings.Matcher{})
it, err := newSketchIterator(payload, origin, "default", metricname.Matcher{})
require.NoError(t, err)
require.True(t, it.MoveNext())
s := it.Current().(*dogstatsdSketchSeries)
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestSketchIteratorWrongType(t *testing.T) {
header := http.Header{}
origin, err := originFromHeader(header, tagger)
require.NoError(t, err)
it, err := newSketchIterator(payload, origin, "default", utilstrings.Matcher{})
it, err := newSketchIterator(payload, origin, "default", metricname.Matcher{})
require.NoError(t, err)
require.False(t, it.MoveNext())
require.Error(t, it.err)
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/server/impl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ go_library(
"//pkg/util/http",
"//pkg/util/infratags",
"//pkg/util/log",
"//pkg/util/metricname",
"//pkg/util/option",
"//pkg/util/sort",
"//pkg/util/stat",
"//pkg/util/strings",
"//pkg/util/tags",
],
)
Expand Down Expand Up @@ -139,8 +139,8 @@ dd_agent_go_test(
"//pkg/util/hostname",
"//pkg/util/infratags",
"//pkg/util/log/setup",
"//pkg/util/metricname",
"//pkg/util/option",
"//pkg/util/strings",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_uber_go_fx//:fx",
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/server/impl/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
taggertypes "github.com/DataDog/datadog-agent/pkg/tagger/types"
"github.com/DataDog/datadog-agent/pkg/util/infratags"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

var (
Expand Down Expand Up @@ -149,7 +149,7 @@ func tsToFloatForSamples(ts time.Time) float64 {
return float64(ts.Unix())
}

func enrichMetricSample(dest []metrics.MetricSample, ddSample dogstatsdMetricSample, origin string, processID uint32, listenerID string, conf enrichConfig, filterList *utilstrings.Matcher) []metrics.MetricSample {
func enrichMetricSample(dest []metrics.MetricSample, ddSample dogstatsdMetricSample, origin string, processID uint32, listenerID string, conf enrichConfig, filterList *metricname.Matcher) []metrics.MetricSample {
metricName := ddSample.name
tags, hostnameFromTags, extractedOrigin, metricSource, jmxCheckName := extractTagsMetadata(ddSample.tags, origin, processID, ddSample.localData, ddSample.externalData, ddSample.cardinality, conf)
if conf.infraTagger.IsCheckEligible(jmxCheckName) {
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/server/impl/enrich_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/DataDog/datadog-agent/comp/core/tagger/origindetection"
"github.com/DataDog/datadog-agent/pkg/metrics"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

func buildTags(tagCount int) []string {
Expand Down Expand Up @@ -63,7 +63,7 @@ func BenchmarkMetricsExclusion(b *testing.B) {
}

for i := 1; i <= 512; i *= 2 {
matcher := utilstrings.NewMatcher(list[:i], false)
matcher := metricname.NewMatcher(list[:i], false)
b.Run(fmt.Sprintf("%d-exact", i),
func(b *testing.B) {
for i := 0; i < b.N; i++ {
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/server/impl/enrich_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/DataDog/datadog-agent/pkg/metrics"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

// Run locally with `go test -fuzz=FuzzParseEventWithEnrich -run=FuzzParseEventWithEnrich -tags=test`
Expand Down Expand Up @@ -48,7 +48,7 @@ func FuzzParseMetricWithEnrich(f *testing.F) {
deps := newServerDeps(t)
stringInternerTelemetry := newSiTelemetry(false, deps.Telemetry)
parser := newParser(deps.Config, newFloat64ListPool(deps.Config, deps.Telemetry), 1, deps.WMeta, stringInternerTelemetry)
filter := utilstrings.NewMatcher([]string{"custom.metric.a", "custom.metric.b"}, false)
filter := metricname.NewMatcher([]string{"custom.metric.a", "custom.metric.b"}, false)

parsed, err := parser.parseMetricSample(rawMetric)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions comp/dogstatsd/server/impl/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
taggertypes "github.com/DataDog/datadog-agent/pkg/tagger/types"
"github.com/DataDog/datadog-agent/pkg/util/infratags"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
)

var (
Expand Down Expand Up @@ -994,7 +994,7 @@ func TestConvertNamespaceBlacklist(t *testing.T) {

func TestMetricFilterListShouldBlock(t *testing.T) {
message := []byte("custom.metric.a:21|ms")
filter := utilstrings.NewMatcher([]string{"custom.metric.a", "custom.metric.b"}, false)
filter := metricname.NewMatcher([]string{"custom.metric.a", "custom.metric.b"}, false)
conf := enrichConfig{
defaultHostname: "default",
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ func TestServerlessModeShouldSetEmptyHostname(t *testing.T) {

func TestMetricFilterListShouldNotBlock(t *testing.T) {
message := []byte("custom.metric.a:21|ms")
filterList := utilstrings.NewMatcher([]string{"custom.metric.b", "custom.metric.c"}, false)
filterList := metricname.NewMatcher([]string{"custom.metric.b", "custom.metric.c"}, false)
conf := enrichConfig{
defaultHostname: "default",
}
Expand Down
8 changes: 4 additions & 4 deletions comp/dogstatsd/server/impl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import (
"github.com/DataDog/datadog-agent/pkg/metrics/event"
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
"github.com/DataDog/datadog-agent/pkg/status/health"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
"github.com/DataDog/datadog-agent/pkg/util/option"
"github.com/DataDog/datadog-agent/pkg/util/sort"
statutil "github.com/DataDog/datadog-agent/pkg/util/stat"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
tagutil "github.com/DataDog/datadog-agent/pkg/util/tags"

"github.com/DataDog/datadog-agent/pkg/util/infratags"
Expand Down Expand Up @@ -552,7 +552,7 @@ func (s *dsdServer) IsRunning() bool {
return s.Started
}

func (s *dsdServer) onFilterListUpdate(filterList utilstrings.Matcher, _ utilstrings.Matcher) {
func (s *dsdServer) onFilterListUpdate(filterList metricname.Matcher, _ metricname.Matcher) {
s.startedMtx.RLock()
defer s.startedMtx.RUnlock()

Expand Down Expand Up @@ -695,7 +695,7 @@ func (s *dsdServer) errLog(format string, params ...interface{}) {
}

// workers are running this function in their goroutine
func (s *dsdServer) parsePackets(batcher dogstatsdBatcher, parser *parser, packets []*packets.Packet, samples metrics.MetricSampleBatch, filterList *utilstrings.Matcher) metrics.MetricSampleBatch {
func (s *dsdServer) parsePackets(batcher dogstatsdBatcher, parser *parser, packets []*packets.Packet, samples metrics.MetricSampleBatch, filterList *metricname.Matcher) metrics.MetricSampleBatch {
for _, packet := range packets {
s.log.Tracef("Dogstatsd receive: %q", packet.Contents)
for {
Expand Down Expand Up @@ -807,7 +807,7 @@ func (s *dsdServer) getOriginCounter(origin string) (okCnt telemetry.SimpleCount
// is the first part aware of processing a late metric. Also, it may help us having a telemetry of a "late_metrics" type here
// which we can't do today.
func (s *dsdServer) parseMetricMessage(metricSamples []metrics.MetricSample, parser *parser, message []byte, origin string,
processID uint32, listenerID string, originTelemetry bool, filterList *utilstrings.Matcher) ([]metrics.MetricSample, error) {
processID uint32, listenerID string, originTelemetry bool, filterList *metricname.Matcher) ([]metrics.MetricSample, error) {
okCnt := s.tlmProcessedOk
errorCnt := s.tlmProcessedError
if origin != "" && originTelemetry {
Expand Down
10 changes: 5 additions & 5 deletions comp/dogstatsd/server/impl/server_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/metrics"
"github.com/DataDog/datadog-agent/pkg/util/metricname"
"github.com/DataDog/datadog-agent/pkg/util/option"
utilstrings "github.com/DataDog/datadog-agent/pkg/util/strings"
)

var (
Expand All @@ -36,11 +36,11 @@ type worker struct {

packetsTelemetry *packets.TelemetryStore

FilterListUpdate chan utilstrings.Matcher
filterList utilstrings.Matcher
FilterListUpdate chan metricname.Matcher
filterList metricname.Matcher
}

func newWorker(s *dsdServer, workerNum int, wmeta option.Option[workloadmeta.Component], packetsTelemetry *packets.TelemetryStore, stringInternerTelemetry *stringInternerTelemetry, filterList utilstrings.Matcher) *worker {
func newWorker(s *dsdServer, workerNum int, wmeta option.Option[workloadmeta.Component], packetsTelemetry *packets.TelemetryStore, stringInternerTelemetry *stringInternerTelemetry, filterList metricname.Matcher) *worker {
var batcher *batcher
if s.ServerlessMode {
batcher = newServerlessBatcher(s.demultiplexer, s.tlmChannel)
Expand All @@ -54,7 +54,7 @@ func newWorker(s *dsdServer, workerNum int, wmeta option.Option[workloadmeta.Com
parser: newParser(s.config, s.sharedFloat64List, workerNum, wmeta, stringInternerTelemetry),
samples: make(metrics.MetricSampleBatch, 0, defaultSampleSize),
packetsTelemetry: packetsTelemetry,
FilterListUpdate: make(chan utilstrings.Matcher),
FilterListUpdate: make(chan metricname.Matcher),
filterList: filterList,
}
}
Expand Down
2 changes: 1 addition & 1 deletion comp/filterlist/def/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ go_library(
],
importpath = "github.com/DataDog/datadog-agent/comp/filterlist/def",
visibility = ["//visibility:public"],
deps = ["//pkg/util/strings"],
deps = ["//pkg/util/metricname"],
)
Loading
Loading