Skip to content

Commit 9788f96

Browse files
committed
usm: Move IsTLS to tls package
1 parent 08342ed commit 9788f96

File tree

10 files changed

+27
-30
lines changed

10 files changed

+27
-30
lines changed

pkg/network/encoding/encoding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func getExpectedConnections(encodedWithQueryType bool, httpOutBlob []byte) *mode
144144
NpmEnabled: false,
145145
UsmEnabled: false,
146146
},
147-
Tags: network.GetStaticTags(tagOpenSSL | tagTLS),
147+
Tags: tls.GetStaticTags(tagOpenSSL | tagTLS),
148148
}
149149
// fixup Protocol stack as on windows or macos
150150
// we don't have tags mechanism inserting TLS protocol on protocol stack

pkg/network/encoding/marshal/format.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/twmb/murmur3"
1414

1515
"github.com/DataDog/datadog-agent/pkg/network"
16+
"github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
1617
"github.com/DataDog/datadog-agent/pkg/process/util"
1718
)
1819

@@ -268,7 +269,7 @@ func formatRouteIdx(v *network.Via, routes map[network.Via]RouteIdx) int32 {
268269
func formatTags(c network.ConnectionStats, tagsSet *network.TagsSet, connDynamicTags map[string]struct{}) ([]uint32, uint32) {
269270
var checksum uint32
270271

271-
staticTags := network.GetStaticTags(c.StaticTags)
272+
staticTags := tls.GetStaticTags(c.StaticTags)
272273
tagsIdx := make([]uint32, 0, len(staticTags)+len(connDynamicTags)+len(c.Tags))
273274

274275
for _, tag := range staticTags {

pkg/network/encoding/marshal/usm_protocols.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package marshal
88
import (
99
model "github.com/DataDog/agent-payload/v5/process"
1010

11-
"github.com/DataDog/datadog-agent/pkg/network"
1211
"github.com/DataDog/datadog-agent/pkg/network/protocols"
12+
"github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
1313
"github.com/DataDog/datadog-agent/pkg/util/log"
1414
)
1515

@@ -34,7 +34,7 @@ import (
3434
func FormatProtocolStack(originalStack protocols.Stack, staticTags uint64) *model.ProtocolStack {
3535
var stack []model.ProtocolType
3636

37-
if network.IsTLSTag(staticTags) || originalStack.Encryption == protocols.TLS {
37+
if tls.IsTLSTag(staticTags) || originalStack.Encryption == protocols.TLS {
3838
stack = addProtocol(stack, protocols.TLS)
3939
}
4040
if originalStack.Application != protocols.Unknown {

pkg/network/tags_linux.go renamed to pkg/network/protocols/tls/tags_linux.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,26 @@
55

66
//go:build linux
77

8-
package network
9-
10-
import (
11-
"github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
12-
)
8+
package tls
139

1410
const (
1511
// ConnTagGnuTLS is the tag for GnuTLS connections
16-
ConnTagGnuTLS = tls.GnuTLS
12+
ConnTagGnuTLS = GnuTLS
1713
// ConnTagOpenSSL is the tag for OpenSSL connections
18-
ConnTagOpenSSL = tls.OpenSSL
14+
ConnTagOpenSSL = OpenSSL
1915
// ConnTagGo is the tag for GO TLS connections
20-
ConnTagGo = tls.Go
16+
ConnTagGo = Go
2117
// ConnTagTLS is the tag for TLS connections in general
22-
ConnTagTLS = tls.TLS
18+
ConnTagTLS = TLS
2319
// ConnTagIstio is the tag for Istio TLS connections
24-
ConnTagIstio = tls.Istio
20+
ConnTagIstio = Istio
2521
// ConnTagNodeJS is the tag for NodeJS TLS connections
26-
ConnTagNodeJS = tls.NodeJS
22+
ConnTagNodeJS = NodeJS
2723
)
2824

2925
// GetStaticTags return the string list of static tags from network.ConnectionStats.Tags
3026
func GetStaticTags(staticTags uint64) (tags []string) {
31-
for tag, str := range tls.StaticTags {
27+
for tag, str := range StaticTags {
3228
if (staticTags & tag) > 0 {
3329
tags = append(tags, str)
3430
}

pkg/network/tags_nolinux.go renamed to pkg/network/protocols/tls/tags_nolinux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
//go:build !linux
77

8-
package network
8+
package tls
99

1010
// GetStaticTags return the string list of static tags from network.ConnectionStats.Tags
11-
func GetStaticTags(_ uint64) (tags []string) {
11+
func GetStaticTags(uint64) (tags []string) {
1212
return tags
1313
}
1414

1515
// IsTLSTag return if the tag is a TLS tag
16-
func IsTLSTag(_ uint64) bool {
16+
func IsTLSTag(uint64) bool {
1717
return false
1818
}

pkg/network/usm/kafka_monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import (
3434

3535
ddebpf "github.com/DataDog/datadog-agent/pkg/ebpf"
3636
"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
37-
"github.com/DataDog/datadog-agent/pkg/network"
3837
"github.com/DataDog/datadog-agent/pkg/network/config"
3938
"github.com/DataDog/datadog-agent/pkg/network/protocols"
4039
"github.com/DataDog/datadog-agent/pkg/network/protocols/http/testutil"
4140
"github.com/DataDog/datadog-agent/pkg/network/protocols/kafka"
4241
"github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry"
42+
ebpftls "github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
4343
gotlsutils "github.com/DataDog/datadog-agent/pkg/network/protocols/tls/gotls/testutil"
4444
"github.com/DataDog/datadog-agent/pkg/network/tracer/testutil/proxy"
4545
usmconfig "github.com/DataDog/datadog-agent/pkg/network/usm/config"
@@ -1704,7 +1704,7 @@ func validateProduceFetchCount(t *assert.CollectT, kafkaStats map[kafka.Key]*kaf
17041704
if !exists {
17051705
return
17061706
}
1707-
hasTLSTag := requestStats.StaticTags&network.ConnTagGo != 0
1707+
hasTLSTag := requestStats.StaticTags&ebpftls.ConnTagGo != 0
17081708
if hasTLSTag != validation.tlsEnabled {
17091709
continue
17101710
}

pkg/network/usm/monitor_tls_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import (
3333
"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
3434
"github.com/DataDog/datadog-agent/pkg/eventmonitor/consumers"
3535
consumerstestutil "github.com/DataDog/datadog-agent/pkg/eventmonitor/consumers/testutil"
36-
"github.com/DataDog/datadog-agent/pkg/network"
3736
"github.com/DataDog/datadog-agent/pkg/network/config"
3837
"github.com/DataDog/datadog-agent/pkg/network/protocols"
3938
"github.com/DataDog/datadog-agent/pkg/network/protocols/http"
4039
"github.com/DataDog/datadog-agent/pkg/network/protocols/http/testutil"
4140
"github.com/DataDog/datadog-agent/pkg/network/protocols/http2"
41+
ebpftls "github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
4242
gotlstestutil "github.com/DataDog/datadog-agent/pkg/network/protocols/tls/gotls/testutil"
4343
"github.com/DataDog/datadog-agent/pkg/network/protocols/tls/nodejs"
4444
usmconfig "github.com/DataDog/datadog-agent/pkg/network/usm/config"
@@ -237,8 +237,8 @@ func testHTTPSLibrary(t *testing.T, cfg *config.Config, fetchCmd, prefetchLibs [
237237
statsTags := req.StaticTags
238238
// debian 10 have curl binary linked with openssl and gnutls but use only openssl during tls query (there no runtime flag available)
239239
// this make harder to map lib and tags, one set of tag should match but not both
240-
if statsTags == network.ConnTagGnuTLS || statsTags == network.ConnTagOpenSSL {
241-
t.Logf("found tag 0x%x %s", statsTags, network.GetStaticTags(statsTags))
240+
if statsTags == ebpftls.ConnTagGnuTLS || statsTags == ebpftls.ConnTagOpenSSL {
241+
t.Logf("found tag 0x%x %s", statsTags, ebpftls.GetStaticTags(statsTags))
242242
return true
243243
}
244244
t.Logf("HTTP stat didn't match criteria %v tags 0x%x\n", key, statsTags)

pkg/network/usm/postgres_monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import (
2424
"github.com/stretchr/testify/suite"
2525

2626
"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
27-
"github.com/DataDog/datadog-agent/pkg/network"
2827
"github.com/DataDog/datadog-agent/pkg/network/config"
2928
"github.com/DataDog/datadog-agent/pkg/network/protocols"
3029
"github.com/DataDog/datadog-agent/pkg/network/protocols/http/testutil"
3130
"github.com/DataDog/datadog-agent/pkg/network/protocols/postgres"
3231
"github.com/DataDog/datadog-agent/pkg/network/protocols/postgres/ebpf"
3332
protocolsUtils "github.com/DataDog/datadog-agent/pkg/network/protocols/testutil"
33+
ebpftls "github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
3434
gotlstestutil "github.com/DataDog/datadog-agent/pkg/network/protocols/tls/gotls/testutil"
3535
"github.com/DataDog/datadog-agent/pkg/network/usm/consts"
3636
usmtestutil "github.com/DataDog/datadog-agent/pkg/network/usm/testutil"
@@ -782,7 +782,7 @@ func validatePostgres(t *testing.T, monitor *Monitor, expectedStats map[string]m
782782
// We might not have postgres stats, and it might be the expected case (to capture 0).
783783
currentStats := postgresProtocolStats.(map[postgres.Key]*postgres.RequestStat)
784784
for key, stats := range currentStats {
785-
hasTLSTag := stats.StaticTags&network.ConnTagGo != 0
785+
hasTLSTag := stats.StaticTags&ebpftls.ConnTagGo != 0
786786
if hasTLSTag != tls {
787787
continue
788788
}

pkg/network/usm/redis_monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"github.com/stretchr/testify/suite"
2020

2121
"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
22-
"github.com/DataDog/datadog-agent/pkg/network"
2322
"github.com/DataDog/datadog-agent/pkg/network/config"
2423
"github.com/DataDog/datadog-agent/pkg/network/protocols"
2524
"github.com/DataDog/datadog-agent/pkg/network/protocols/redis"
2625
protocolsUtils "github.com/DataDog/datadog-agent/pkg/network/protocols/testutil"
26+
ebpftls "github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
2727
gotlstestutil "github.com/DataDog/datadog-agent/pkg/network/protocols/tls/gotls/testutil"
2828
"github.com/DataDog/datadog-agent/pkg/network/usm/consts"
2929
usmtestutil "github.com/DataDog/datadog-agent/pkg/network/usm/testutil"
@@ -233,7 +233,7 @@ func validateRedis(t *testing.T, monitor *Monitor, expectedStats map[string]map[
233233
// Check all error states for TLS tag and sum counts
234234
var hasTLSTag bool
235235
for _, stat := range stats.ErrorToStats {
236-
if stat.StaticTags&network.ConnTagGo != 0 {
236+
if stat.StaticTags&ebpftls.ConnTagGo != 0 {
237237
hasTLSTag = true
238238
break
239239
}

pkg/network/usm/usm_http2_monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import (
3535

3636
ddebpf "github.com/DataDog/datadog-agent/pkg/ebpf"
3737
"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
38-
"github.com/DataDog/datadog-agent/pkg/network"
3938
"github.com/DataDog/datadog-agent/pkg/network/config"
4039
"github.com/DataDog/datadog-agent/pkg/network/protocols"
4140
usmhttp "github.com/DataDog/datadog-agent/pkg/network/protocols/http"
4241
"github.com/DataDog/datadog-agent/pkg/network/protocols/http/testutil"
4342
usmhttp2 "github.com/DataDog/datadog-agent/pkg/network/protocols/http2"
43+
ebpftls "github.com/DataDog/datadog-agent/pkg/network/protocols/tls"
4444
gotlsutils "github.com/DataDog/datadog-agent/pkg/network/protocols/tls/gotls/testutil"
4545
"github.com/DataDog/datadog-agent/pkg/network/tracer/testutil/proxy"
4646
"github.com/DataDog/datadog-agent/pkg/network/usm/consts"
@@ -1624,7 +1624,7 @@ func validateStats(t *testing.T, usmMonitor *Monitor, res, expectedEndpoints map
16241624
if statusCode == 0 {
16251625
statusCode = 200
16261626
}
1627-
hasTag := stat.Data[statusCode].StaticTags == network.ConnTagGo
1627+
hasTag := stat.Data[statusCode].StaticTags == ebpftls.ConnTagGo
16281628
if hasTag != isTLS {
16291629
continue
16301630
}

0 commit comments

Comments
 (0)