Skip to content

Commit e459938

Browse files
authored
(fix) internal/civisibility: fixes the removeEmptyStrings func and updates the common_metrics.json file (#3291)
1 parent 8052b0f commit e459938

File tree

3 files changed

+217
-19
lines changed

3 files changed

+217
-19
lines changed

internal/civisibility/utils/telemetry/telemetry.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,15 @@ var (
147147
TestManagementEnabledSettingsResponseType SettingsResponseType = []string{"test_management_enabled:true"}
148148
)
149149

150-
// removeEmptyStrings removes empty string values inside an array or use the same if not empty string is found.
150+
// removeEmptyStrings removes empty string values from a slice.
151151
func removeEmptyStrings(s []string) []string {
152-
var r []string
153-
hasSpace := false
154-
for i, str := range s {
155-
if str == "" && r == nil {
156-
if i > 0 {
157-
r = s[:i]
158-
}
159-
hasSpace = true
160-
continue
152+
result := make([]string, len(s))
153+
n := 0
154+
for _, str := range s {
155+
if str != "" {
156+
result[n] = str
157+
n++
161158
}
162-
if hasSpace {
163-
r = append(r, str)
164-
}
165-
}
166-
167-
if r == nil {
168-
r = s
169159
}
170-
171-
return r
160+
return result[:n]
172161
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2025 Datadog, Inc.
5+
6+
package telemetry
7+
8+
import (
9+
"reflect"
10+
"testing"
11+
)
12+
13+
func TestRemoveEmptyStrings(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
input []string
17+
want []string
18+
}{
19+
{
20+
name: "All non-empty strings",
21+
input: []string{"hello", "world"},
22+
want: []string{"hello", "world"},
23+
},
24+
{
25+
name: "All empty strings",
26+
input: []string{"", "", ""},
27+
want: []string{},
28+
},
29+
{
30+
name: "Mixed empty and non-empty strings",
31+
input: []string{"one", "", "two", "", "three"},
32+
want: []string{"one", "two", "three"},
33+
},
34+
{
35+
name: "Empty slice",
36+
input: []string{},
37+
want: []string{},
38+
},
39+
{
40+
name: "Empty string at the beginning",
41+
input: []string{"", "start", "end"},
42+
want: []string{"start", "end"},
43+
},
44+
{
45+
name: "Empty string at the end",
46+
input: []string{"start", "end", ""},
47+
want: []string{"start", "end"},
48+
},
49+
{
50+
name: "Multiple consecutive empty strings",
51+
input: []string{"start", "", "", "end", ""},
52+
want: []string{"start", "end"},
53+
},
54+
{
55+
name: "Strings with spaces (not considered empty)",
56+
input: []string{" ", "text", "", " "},
57+
want: []string{" ", "text", " "},
58+
},
59+
}
60+
61+
for _, tc := range tests {
62+
t.Run(tc.name, func(t *testing.T) {
63+
got := removeEmptyStrings(tc.input)
64+
if !reflect.DeepEqual(got, tc.want) {
65+
t.Errorf("removeEmptyStrings(%v) = %v; expected %v", tc.input, got, tc.want)
66+
}
67+
})
68+
}
69+
}

internal/telemetry/internal/knownmetrics/common_metrics.json

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
[
2+
{
3+
"namespace": "appsec",
4+
"type": "count",
5+
"name": "api_security.missing_route"
6+
},
7+
{
8+
"namespace": "appsec",
9+
"type": "count",
10+
"name": "api_security.request.no_schema"
11+
},
12+
{
13+
"namespace": "appsec",
14+
"type": "count",
15+
"name": "api_security.request.schema"
16+
},
217
{
318
"namespace": "appsec",
419
"type": "count",
@@ -9,6 +24,11 @@
924
"type": "count",
1025
"name": "instrum.user_auth.missing_user_login"
1126
},
27+
{
28+
"namespace": "appsec",
29+
"type": "count",
30+
"name": "rasp.error"
31+
},
1232
{
1333
"namespace": "appsec",
1434
"type": "count",
@@ -19,16 +39,31 @@
1939
"type": "count",
2040
"name": "rasp.rule.match"
2141
},
42+
{
43+
"namespace": "appsec",
44+
"type": "count",
45+
"name": "rasp.rule.skipped"
46+
},
2247
{
2348
"namespace": "appsec",
2449
"type": "count",
2550
"name": "rasp.timeout"
2651
},
52+
{
53+
"namespace": "appsec",
54+
"type": "count",
55+
"name": "sdk.event"
56+
},
2757
{
2858
"namespace": "appsec",
2959
"type": "count",
3060
"name": "waf.config_errors"
3161
},
62+
{
63+
"namespace": "appsec",
64+
"type": "count",
65+
"name": "waf.error"
66+
},
3267
{
3368
"namespace": "appsec",
3469
"type": "count",
@@ -49,6 +84,16 @@
4984
"type": "count",
5085
"name": "waf.updates"
5186
},
87+
{
88+
"namespace": "appsec",
89+
"type": "distribution",
90+
"name": "rasp.duration"
91+
},
92+
{
93+
"namespace": "appsec",
94+
"type": "distribution",
95+
"name": "rasp.duration_ext"
96+
},
5297
{
5398
"namespace": "appsec",
5499
"type": "distribution",
@@ -239,6 +284,16 @@
239284
"type": "count",
240285
"name": "manual_api_events"
241286
},
287+
{
288+
"namespace": "civisibility",
289+
"type": "count",
290+
"name": "test_management_tests.request"
291+
},
292+
{
293+
"namespace": "civisibility",
294+
"type": "count",
295+
"name": "test_management_tests.request_errors"
296+
},
242297
{
243298
"namespace": "civisibility",
244299
"type": "count",
@@ -369,6 +424,21 @@
369424
"type": "distribution",
370425
"name": "known_tests.response_tests"
371426
},
427+
{
428+
"namespace": "civisibility",
429+
"type": "distribution",
430+
"name": "test_management_tests.request_ms"
431+
},
432+
{
433+
"namespace": "civisibility",
434+
"type": "distribution",
435+
"name": "test_management_tests.response_bytes"
436+
},
437+
{
438+
"namespace": "civisibility",
439+
"type": "distribution",
440+
"name": "test_management_tests.response_tests"
441+
},
372442
{
373443
"namespace": "general",
374444
"type": "count",
@@ -434,6 +504,31 @@
434504
"type": "count",
435505
"name": "suppressed.vulnerabilities"
436506
},
507+
{
508+
"namespace": "mlobs",
509+
"type": "count",
510+
"name": "activate_distributed_headers"
511+
},
512+
{
513+
"namespace": "mlobs",
514+
"type": "count",
515+
"name": "annotations"
516+
},
517+
{
518+
"namespace": "mlobs",
519+
"type": "count",
520+
"name": "dropped_eval_events"
521+
},
522+
{
523+
"namespace": "mlobs",
524+
"type": "count",
525+
"name": "dropped_span_events"
526+
},
527+
{
528+
"namespace": "mlobs",
529+
"type": "count",
530+
"name": "evals_submitted"
531+
},
437532
{
438533
"namespace": "mlobs",
439534
"type": "count",
@@ -449,16 +544,56 @@
449544
"type": "count",
450545
"name": "evaluators.run"
451546
},
547+
{
548+
"namespace": "mlobs",
549+
"type": "count",
550+
"name": "inject_distributed_headers"
551+
},
552+
{
553+
"namespace": "mlobs",
554+
"type": "count",
555+
"name": "product_enabled"
556+
},
557+
{
558+
"namespace": "mlobs",
559+
"type": "count",
560+
"name": "span.finished"
561+
},
452562
{
453563
"namespace": "mlobs",
454564
"type": "count",
455565
"name": "span.start"
456566
},
567+
{
568+
"namespace": "mlobs",
569+
"type": "count",
570+
"name": "spans_exported"
571+
},
572+
{
573+
"namespace": "mlobs",
574+
"type": "count",
575+
"name": "user_flush"
576+
},
457577
{
458578
"namespace": "mlobs",
459579
"type": "distribution",
460580
"name": "evaluators.rule_sample_rate"
461581
},
582+
{
583+
"namespace": "mlobs",
584+
"type": "distribution",
585+
"name": "init_time"
586+
},
587+
{
588+
"namespace": "mlobs",
589+
"type": "distribution",
590+
"name": "span.raw_size"
591+
},
592+
{
593+
"namespace": "mlobs",
594+
"type": "distribution",
595+
"name": "span.size"
596+
},
462597
{
463598
"namespace": "profilers",
464599
"type": "count",
@@ -704,6 +839,11 @@
704839
"type": "count",
705840
"name": "otel.env.unsupported"
706841
},
842+
{
843+
"namespace": "tracers",
844+
"type": "count",
845+
"name": "public_api.called"
846+
},
707847
{
708848
"namespace": "tracers",
709849
"type": "count",

0 commit comments

Comments
 (0)