-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NPM-4131] Add netpath aggregator + e2e test (#33416)
- Loading branch information
Showing
19 changed files
with
455 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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. | ||
|
||
package aggregator | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/networkpath/payload" | ||
"github.com/DataDog/datadog-agent/test/fakeintake/api" | ||
) | ||
|
||
// Netpath represents a network path payload | ||
type Netpath struct { | ||
collectedTime time.Time | ||
payload.NetworkPath | ||
} | ||
|
||
func (p *Netpath) name() string { | ||
return fmt.Sprintf("%s:%d %s", p.Destination.Hostname, p.Destination.Port, p.Protocol) | ||
} | ||
|
||
// GetTags return the tags from a payload | ||
func (p *Netpath) GetTags() []string { | ||
return []string{} | ||
} | ||
|
||
// GetCollectedTime return the time when the payload has been collected by the fakeintake server | ||
func (p *Netpath) GetCollectedTime() time.Time { | ||
return p.collectedTime | ||
} | ||
|
||
// ParseNetpathPayload parses an api.Payload into a list of Netpath | ||
func ParseNetpathPayload(payload api.Payload) (netpaths []*Netpath, err error) { | ||
if len(payload.Data) == 0 || bytes.Equal(payload.Data, []byte("{}")) { | ||
return []*Netpath{}, nil | ||
} | ||
enflated, err := enflate(payload.Data, payload.Encoding) | ||
if err != nil { | ||
return nil, err | ||
} | ||
netpaths = []*Netpath{} | ||
err = json.Unmarshal(enflated, &netpaths) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, n := range netpaths { | ||
n.collectedTime = payload.Timestamp | ||
} | ||
return netpaths, err | ||
} | ||
|
||
// NetpathAggregator is an Aggregator for netpath payloads | ||
type NetpathAggregator struct { | ||
Aggregator[*Netpath] | ||
} | ||
|
||
// NewNetpathAggregator return a new NetpathAggregator | ||
func NewNetpathAggregator() NetpathAggregator { | ||
return NetpathAggregator{ | ||
Aggregator: newAggregator(ParseNetpathPayload), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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 2016-present Datadog, Inc. | ||
|
||
package aggregator | ||
|
||
import ( | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/networkpath/payload" | ||
"github.com/DataDog/datadog-agent/test/fakeintake/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
//go:embed fixtures/netpath_bytes | ||
var netpathData []byte | ||
|
||
func TestNetpathAggregator(t *testing.T) { | ||
t.Run("ParseNetpathPayload should return empty Netpath array on empty data", func(t *testing.T) { | ||
netpaths, err := ParseNetpathPayload(api.Payload{Data: []byte(""), Encoding: encodingEmpty}) | ||
assert.NoError(t, err) | ||
assert.Empty(t, netpaths) | ||
}) | ||
|
||
t.Run("ParseNetpathPayload should return empty Netpath array on empty json object", func(t *testing.T) { | ||
netpaths, err := ParseNetpathPayload(api.Payload{Data: []byte("{}"), Encoding: encodingJSON}) | ||
assert.NoError(t, err) | ||
assert.Empty(t, netpaths) | ||
}) | ||
|
||
t.Run("ParseNetpathPayload should return a valid Netpath on valid payload", func(t *testing.T) { | ||
netpaths, err := ParseNetpathPayload(api.Payload{Data: netpathData, Encoding: encodingGzip}) | ||
assert.NoError(t, err) | ||
|
||
assert.Len(t, netpaths, 1) | ||
np := netpaths[0] | ||
|
||
assert.Equal(t, int64(1737933404281), np.Timestamp) | ||
assert.Equal(t, "7.64.0-devel+git.40.38beef2", np.AgentVersion) | ||
assert.Equal(t, "default", np.Namespace) | ||
assert.Equal(t, "da6f9055-b7df-41b0-bafd-0e5d3c6c370e", np.PathtraceID) | ||
assert.Equal(t, payload.PathOrigin("network_path_integration"), np.Origin) | ||
assert.Equal(t, payload.Protocol("TCP"), np.Protocol) | ||
assert.Equal(t, "i-019fda1a9f830d95e", np.Source.Hostname) | ||
assert.Equal(t, "subnet-091570395d476e9ce", np.Source.Via.Subnet.Alias) | ||
assert.Equal(t, "vpc-029c0faf8f49dee8d", np.Source.NetworkID) | ||
assert.Equal(t, "api.datadoghq.eu", np.Destination.Hostname) | ||
assert.Equal(t, "34.107.236.155", np.Destination.IPAddress) | ||
assert.Equal(t, uint16(443), np.Destination.Port) | ||
assert.Equal(t, "155.236.107.34.bc.googleusercontent.com", np.Destination.ReverseDNSHostname) | ||
|
||
assert.Len(t, np.Hops, 9) | ||
assert.Equal(t, payload.NetworkPathHop{ | ||
TTL: 1, | ||
IPAddress: "10.1.62.52", | ||
Hostname: "ip-10-1-62-52.ec2.internal", | ||
RTT: 0.39, | ||
Reachable: true, | ||
}, np.Hops[0]) | ||
assert.Equal(t, payload.NetworkPathHop{ | ||
TTL: 2, | ||
IPAddress: "unknown_hop_2", | ||
Hostname: "unknown_hop_2", | ||
Reachable: false, | ||
}, np.Hops[1]) | ||
assert.Equal(t, payload.NetworkPathHop{ | ||
TTL: 9, | ||
IPAddress: "34.107.236.155", | ||
Hostname: "155.236.107.34.bc.googleusercontent.com", | ||
RTT: 2.864, | ||
Reachable: true, | ||
}, np.Hops[8]) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"payloads": [ | ||
{ | ||
"timestamp": "2025-01-26T23:16:45.522649265Z", | ||
"data": "H4sIAAAAAAAA/5yUzY6jOBSF3+VuB678y992XmAWs2uVkMEXgorYtDGpRSnv3nIq3Z0QJS31Agn5Wt85Pgfz7RPidKQ1muMCDS9lWUupmBIVz8CM5GJ7orBO3kEDJRYKWW7pRPM/4xRRMZRVRzQIyMCZI62L6QkasDSYbY6QwWLiIQbTUzvZNDDFUDOt8660Q654x/LODDZnpK3si16WjCADH6ZxSpKO4ocP723CtJOLNAYTk5sMluCj7/0MDfz/73+Qweq3kNQ/4eDXmOxAA1POeD1Yw009VJLZWif+aTJp37p1jmJ6M/NkVmiuKzmruS6ZrLVVZUF1T3A+Z7/MXE5yWvqcibpngxmqQdWWqLJwzsDSGif35fLei1kmtCYa68fDd6QNMpiW1lgbaE3iUiFnJQpZINc6HdGHCI1SMoNAqQdqrVvbGyTX+ms/K1Eq7HocvR9n2lYKvXeRXMTeH5Ovg19WaFLhcYaG77Q5Q46FQJ2qvM1vyTnLeV6IXAukXmBqITgzQwYhRmgYyjr5M/3BdDNBE8NG5+yqI3Y6m3t3/sO1B7+0O6n96AY5mHn9zZQvmPI5U75iqh1TKIbsK9p74v3gkoBArsXzCPRD1AzTc6mN3dMfZleBqqieCxQP3jkyVFgWe+s36xcwf+283IN5gULW6TvhfJ/LfnZ1LqoXzqt9NEqg0Dz9ZzjbVfkw+5k9K58L1H+6Yn9xl25KUY/Kb+e3HwAAAP//AQAA///bNfaSVQUAAA==", | ||
"encoding": "gzip", | ||
"content_type": "application/json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.