-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NPM-4131] Add netpath aggregator + e2e test #33416
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fb4ab1b
add netpath aggregator to e2e
pimlu f082cbd
add aggregator parsing test
pimlu 2b0bd07
add e2e test
pimlu 2d2421a
cleanup test output
pimlu 6c15ee9
fix test
pimlu e174035
get it to push...
pimlu 34aa0b7
document test script
pimlu 4f46dbe
remove debug line
pimlu e2c2a37
check payload end to end for the existing tests
pimlu f8c6a44
remove 'local' verbiage
pimlu dbc71c9
fix replaced modules
pimlu 7fc47cf
go work sync
pimlu 3d784ff
fix lint (shorten filenames)
pimlu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is the correct fix, but new-e2e was panicking here which was interfering with pulumi destroy. Let me know if this should be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah that should help. We were aware of the issue but did not check to fix it yet.
Thanks for the fix