Skip to content
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
34 changes: 34 additions & 0 deletions statsd/end_to_end_udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,38 @@ func getTestMapDirect() map[string]testCaseDirect {
}
}

func TestDistributionSamplesExternalEnv(t *testing.T) {
resetContainerID()
defer resetContainerID()

patchExternalEnv("test-env")
defer resetExternalEnv()

ts, client := newClientDirectAndTestServer(t,
"udp",
"localhost:8765",
nil,
WithExtendedClientSideAggregation(),
WithMaxSamplesPerContext(2),
WithChannelMode(),
WithoutTelemetry(),
)

tags := []string{"custom:1", "custom:2"}
client.DistributionSamples("distro", []float64{1, 2}, tags, 1.0)

finalTags := ts.getFinalTags(tags...)
containerID := ts.getContainerID()
expectedMetrics := []string{
ts.namespace + "distro:1:2|d" + finalTags + containerID + "|e:test-env",
}
ts.assert(t, client.Client, expectedMetrics)
}

func TestFullPipelineUDP(t *testing.T) {
resetContainerID()
defer resetContainerID()

for testName, c := range getTestMap() {
t.Run(testName, func(t *testing.T) {
ts, client := newClientAndTestServer(t,
Expand All @@ -402,6 +433,9 @@ func TestFullPipelineUDP(t *testing.T) {
}

func TestFullPipelineUDPDirectClient(t *testing.T) {
resetContainerID()
defer resetContainerID()

for testName, c := range getTestMapDirect() {
t.Run(testName, func(t *testing.T) {
ts, client := newClientDirectAndTestServer(t,
Expand Down
15 changes: 8 additions & 7 deletions statsd/statsd_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ func (c *ClientDirect) DistributionSamples(name string, values []float64, tags [
atomic.AddUint64(&c.clientEx.telemetry.totalMetricsDistribution, uint64(len(values)))
return c.clientEx.send(metric{
metricType: distributionAggregated,
name: name,
fvalues: values,
tags: tags,
stags: strings.Join(tags, tagSeparatorSymbol),
rate: rate,
globalTags: c.clientEx.tags,
namespace: c.clientEx.namespace,
name: name,
fvalues: values,
tags: tags,
stags: strings.Join(tags, tagSeparatorSymbol),
rate: rate,
globalTags: c.clientEx.tags,
namespace: c.clientEx.namespace,
originDetection: c.clientEx.originDetection,
})
}

Expand Down
2 changes: 1 addition & 1 deletion statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestGetTelemetry(t *testing.T) {
assert.Equal(t, uint64(1), tlm.TotalEvents, "telmetry TotalEvents was wrong")
assert.Equal(t, uint64(1), tlm.TotalServiceChecks, "telmetry TotalServiceChecks was wrong")
assert.Equal(t, uint64(0), tlm.TotalDroppedOnReceive, "telmetry TotalDroppedOnReceive was wrong")
assert.Equal(t, uint64(22), tlm.TotalPayloadsSent, "telmetry TotalPayloadsSent was wrong")
assert.GreaterOrEqual(t, tlm.TotalPayloadsSent, uint64(1), "telmetry TotalPayloadsSent was wrong")
assert.Equal(t, uint64(0), tlm.TotalPayloadsDropped, "telmetry TotalPayloadsDropped was wrong")
assert.Equal(t, uint64(0), tlm.TotalPayloadsDroppedWriter, "telmetry TotalPayloadsDroppedWriter was wrong")
assert.Equal(t, uint64(0), tlm.TotalPayloadsDroppedQueueFull, "telmetry TotalPayloadsDroppedQueueFull was wrong")
Expand Down
3 changes: 2 additions & 1 deletion statsd/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ func (ts *testServer) sendExtendedBasicAggregationMetricsWithPreAggregatedSample
client.DistributionSamples("distro2", []float64{5, 6}, tags, 0.5)

finalTags := ts.getFinalTags(tags...)
return append(expectedMetrics, ts.namespace+"distro2:5:6|d|@0.5"+finalTags)
containerID := ts.getContainerID()
return append(expectedMetrics, ts.namespace+"distro2:5:6|d|@0.5"+finalTags+containerID)
}

func patchContainerID(id string) { containerID = id }
Expand Down
Loading