Skip to content

Commit

Permalink
Add core agent k8s test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-taf committed Aug 23, 2024
1 parent db3fd9c commit 1d6e112
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/new-e2e/tests/process/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ func (s *K8sSuite) TestProcessCheck() {
assertContainersCollected(t, payloads, []string{"stress-ng"})
}

func (s *K8sSuite) TestProcessCheckInCoreAgent() {
t := s.T()

assert.EventuallyWithT(t, func(*assert.CollectT) {
status := k8sAgentStatus(t, s.Env().KubernetesCluster)
assert.ElementsMatch(t, []string{"process", "rtprocess"}, status.ProcessComponentStatus.Expvars.Map.EnabledChecks)
}, 2*time.Minute, 5*time.Second)

var payloads []*aggregator.ProcessPayload
assert.EventuallyWithT(t, func(c *assert.CollectT) {
var err error
payloads, err = s.Env().FakeIntake.Client().GetProcesses()
assert.NoError(c, err, "failed to get process payloads from fakeintake")

// Wait for two payloads, as processes must be detected in two check runs to be returned
assert.GreaterOrEqual(c, len(payloads), 2, "fewer than 2 payloads returned")
}, 2*time.Minute, 10*time.Second)

assertProcessCollected(t, payloads, false, "stress-ng-cpu [run]")
assertContainersCollected(t, payloads, []string{"stress-ng"})
assertContainersNotCollected(t, payloads, []string{"process-agent"})
}

func (s *K8sSuite) TestProcessDiscoveryCheck() {
t := s.T()
helmValues, err := createHelmValues(helmConfig{
Expand Down
20 changes: 20 additions & 0 deletions test/new-e2e/tests/process/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ func assertContainersCollected(t *testing.T, payloads []*aggregator.ProcessPaylo
}
}

// assertContainersNotCollected asserts that the given containers are not collected
func assertContainersNotCollected(t *testing.T, payloads []*aggregator.ProcessPayload, containers []string) {
defer func() {
if t.Failed() {
t.Logf("Payloads:\n%+v\n", payloads)
}
}()

for _, container := range containers {
var found bool
for _, payload := range payloads {
if findContainer(container, payload.Containers) {
found = true
break
}
}
assert.False(t, found, "%s container found", container)
}
}

// findContainer returns whether the container with the given name exists in the given list of
// containers and whether it has the expected data populated
func findContainer(name string, containers []*agentmodel.Container) bool {
Expand Down

0 comments on commit 1d6e112

Please sign in to comment.