Skip to content
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

[NDM][NDMII-2748] test snmp tags on agent restart #26003

Merged
merged 11 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 12 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,18 @@ workflow:
- when: manual
allow_failure: true

.on_ndm_snmp_or_e2e_changes_or_manual:
- !reference [.on_e2e_main_release_or_rc]
- changes:
paths:
- pkg/collector/corechecks/snmp/**/*
- test/new-e2e/tests/ndm/snmp/**/*
- test/new-e2e/go.mod
compare_to: main # TODO: use a variable, when this is supported https://gitlab.com/gitlab-org/gitlab/-/issues/369916
when: on_success
- when: manual
allow_failure: true

.on_trace_agent_changes_or_manual:
- !reference [.except_mergequeue]
- changes:
Expand Down
9 changes: 9 additions & 0 deletions .gitlab/e2e/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,12 @@ new-e2e-ndm-netflow:
variables:
TARGETS: ./tests/ndm/netflow
TEAM: network-device-monitoring

new-e2e-ndm-snmp:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 praise

extends: .new_e2e_template
rules: !reference [.on_ndm_snmp_or_e2e_changes_or_manual]
needs:
- qa_agent
variables:
TARGETS: ./tests/ndm/snmp
jmw51798 marked this conversation as resolved.
Show resolved Hide resolved
TEAM: network-device-monitoring
2 changes: 1 addition & 1 deletion test/new-e2e/tests/ndm/snmp/config/public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ init_config:
instances:
- ip_address: dd-snmp
port: 1161
community_string: "public"
community_string: "cisco-nexus"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥜 nitpick
You could update the config file name accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed b80d861

41 changes: 41 additions & 0 deletions test/new-e2e/tests/ndm/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ package snmp

import (
"embed"
"fmt"
"path"
"testing"
"time"

"github.com/DataDog/datadog-agent/test/fakeintake/aggregator"
"github.com/DataDog/datadog-agent/test/fakeintake/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/components/datadog/dockeragentparams"
Expand Down Expand Up @@ -155,3 +159,40 @@ func (s *snmpDockerSuite) TestSnmp() {
assert.Contains(c, metrics, "snmp.sysUpTimeInstance", "metrics %v doesn't contain snmp.sysUpTimeInstance", metrics)
}, 5*time.Minute, 10*time.Second)
}

func (s *snmpDockerSuite) TestSnmpTagsAreStoredOnRestart() {
fakeintake := s.Env().FakeIntake.Client()
initialMetrics, err := fakeintake.FilterMetrics("snmp.device.reachable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe from potentially flaky test failures I think FIlterMetrics() should be inside an EventuallyWithT().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed d8de7c0
also changed in that commit the require to assert to prevent the test from failing if the fakeintake responds an error

client.WithTags[*aggregator.MetricSeries]([]string{}),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options are optional.
An empty list of filtering tags should be equivalent to not specifying any list of filtering tags at all.

Suggested change
initialMetrics, err := fakeintake.FilterMetrics("snmp.device.reachable",
client.WithTags[*aggregator.MetricSeries]([]string{}),
)
initialMetrics, err := fakeintake.FilterMetrics("snmp.device.reachable")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed 45ae6cc

require.NoError(s.T(), err)

initialTags := initialMetrics[0].Tags
_, err = s.Env().RemoteHost.Execute("docker stop dd-snmp")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion
Should be possible to run the request using the Docker client in

Docker *components.RemoteHostDocker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be tested:

// stop
s.Env().Docker.GetClient().ContainerStop(context.Background(), "dd-snmp", container.StopOptions{})

// restart
s.Env().Docker.GetClient().ContainerRestart(context.Background(), s.Env().Agent.ContainerName, container.StopOptions{})

But I think you need to get the ID from the container name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked and indeed you would need to get the container ID, will create a card to provide this through the Docker client, we can generate a list of container ids by their name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I tried before to get the list of container ids filtered by the name and then get the first one from the list but it is maybe easier like this

require.NoError(s.T(), err)

err = fakeintake.FlushServerAndResetAggregators()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed both before and after the agent restart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the first one ! 45ae6cc

require.NoError(s.T(), err)

_, err = s.Env().RemoteHost.Execute(fmt.Sprintf("docker restart %s", s.Env().Agent.ContainerName))
require.NoError(s.T(), err)

err = fakeintake.FlushServerAndResetAggregators()
require.NoError(s.T(), err)

var metrics []*aggregator.MetricSeries

require.EventuallyWithT(s.T(), func(t *assert.CollectT) {
metrics, err = fakeintake.FilterMetrics("snmp.device.reachable",
client.WithTags[*aggregator.MetricSeries]([]string{}),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as above.

Suggested change
metrics, err = fakeintake.FilterMetrics("snmp.device.reachable",
client.WithTags[*aggregator.MetricSeries]([]string{}),
)
metrics, err = fakeintake.FilterMetrics("snmp.device.reachable")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed 45ae6cc

require.NoError(t, err)
assert.NotEmpty(t, metrics)
}, 5*time.Minute, 5*time.Second)

tags := metrics[0].Tags

require.Zero(s.T(), metrics[0].Points[0].Value)
require.ElementsMatch(s.T(), tags, initialTags)
jmw51798 marked this conversation as resolved.
Show resolved Hide resolved
require.Len(s.T(), tags, 9)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing this check since the number of tags could change and it probably doesn't check anything beyond what was already checked by the previous ElementsMatch().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed 45ae6cc

}
Loading