Skip to content

Commit

Permalink
Update K8s test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-taf committed Aug 23, 2024
1 parent 9308d58 commit e4992ca
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 33 deletions.
3 changes: 1 addition & 2 deletions test/new-e2e/tests/process/config/helm-template.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
datadog:
processAgent:
enabled: {{.ProcessAgentEnabled}}
processCollection: {{.ProcessCollection}}
processDiscovery: {{.ProcessDiscoveryCollection}}
containerCollection: {{.ContainerCollection}}
runInCoreAgent: {{.RunInCoreAgent}}
networkMonitoring:
enabled: false
enabled: {{.NetworkPerformanceMonitoring}}
107 changes: 76 additions & 31 deletions test/new-e2e/tests/process/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import (
var helmTemplate string

type helmConfig struct {
ProcessAgentEnabled bool
ProcessCollection bool
ProcessDiscoveryCollection bool
ContainerCollection bool
RunInCoreAgent bool
ProcessCollection bool
ProcessDiscoveryCollection bool
ContainerCollection bool
RunInCoreAgent bool
NetworkPerformanceMonitoring bool
}

func createHelmValues(cfg helmConfig) (string, error) {
Expand All @@ -66,8 +66,7 @@ type K8sSuite struct {
func TestK8sTestSuite(t *testing.T) {
t.Parallel()
helmValues, err := createHelmValues(helmConfig{
ProcessAgentEnabled: true,
ProcessCollection: true,
ProcessCollection: true,
})
require.NoError(t, err)

Expand Down Expand Up @@ -105,8 +104,65 @@ func (s *K8sSuite) TestProcessCheck() {
assertContainersCollected(t, payloads, []string{"stress-ng"})
}

func (s *K8sSuite) TestManualProcessCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "process")
assertManualProcessCheck(s.T(), checkOutput, false, "stress-ng-cpu [run]", "stress-ng")
}

func (s *K8sSuite) TestManualProcessDiscoveryCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "process_discovery")
assertManualProcessDiscoveryCheck(s.T(), checkOutput, "stress-ng-cpu [run]")
}

func (s *K8sSuite) TestManualContainerCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "container")
assertManualContainerCheck(s.T(), checkOutput, "stress-ng")
}

func (s *K8sSuite) TestProcessDiscoveryCheck() {
t := s.T()
helmValues, err := createHelmValues(helmConfig{
ProcessDiscoveryCollection: true,
})
require.NoError(t, err)

s.UpdateEnv(awskubernetes.KindProvisioner(
awskubernetes.WithWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider) (*kubeComp.Workload, error) {
return cpustress.K8sAppDefinition(e, kubeProvider, "workload-stress")
}),
awskubernetes.WithAgentOptions(kubernetesagentparams.WithHelmValues(helmValues)),
))

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

var payloads []*aggregator.ProcessDiscoveryPayload
assert.EventuallyWithT(t, func(c *assert.CollectT) {
var err error
payloads, err = s.Env().FakeIntake.Client().GetProcessDiscoveries()
assert.NoError(c, err, "failed to get process discovery payloads from fakeintake")
assert.NotEmpty(c, payloads, "no process discovery payloads returned")
}, 2*time.Minute, 10*time.Second)

assertProcessDiscoveryCollected(t, payloads, "stress-ng-cpu [run]")
}

func (s *K8sSuite) TestProcessCheckInCoreAgent() {
t := s.T()
helmValues, err := createHelmValues(helmConfig{
ProcessCollection: true,
RunInCoreAgent: true,
})
require.NoError(t, err)

s.UpdateEnv(awskubernetes.KindProvisioner(
awskubernetes.WithWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider) (*kubeComp.Workload, error) {
return cpustress.K8sAppDefinition(e, kubeProvider, "workload-stress")
}),
awskubernetes.WithAgentOptions(kubernetesagentparams.WithHelmValues(helmValues)),
))

assert.EventuallyWithT(t, func(*assert.CollectT) {
status := k8sAgentStatus(t, s.Env().KubernetesCluster)
Expand All @@ -128,11 +184,12 @@ func (s *K8sSuite) TestProcessCheckInCoreAgent() {
assertContainersNotCollected(t, payloads, []string{"process-agent"})
}

func (s *K8sSuite) TestProcessDiscoveryCheck() {
func (s *K8sSuite) TestProcessCheckInCoreAgentWithNPM() {
t := s.T()
helmValues, err := createHelmValues(helmConfig{
ProcessAgentEnabled: true,
ProcessDiscoveryCollection: true,
ProcessCollection: true,
RunInCoreAgent: true,
NetworkPerformanceMonitoring: true,
})
require.NoError(t, err)

Expand All @@ -145,33 +202,21 @@ func (s *K8sSuite) TestProcessDiscoveryCheck() {

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

var payloads []*aggregator.ProcessDiscoveryPayload
var payloads []*aggregator.ProcessPayload
assert.EventuallyWithT(t, func(c *assert.CollectT) {
var err error
payloads, err = s.Env().FakeIntake.Client().GetProcessDiscoveries()
assert.NoError(c, err, "failed to get process discovery payloads from fakeintake")
assert.NotEmpty(c, payloads, "no process discovery payloads returned")
}, 2*time.Minute, 10*time.Second)

assertProcessDiscoveryCollected(t, payloads, "stress-ng-cpu [run]")
}

func (s *K8sSuite) TestManualProcessCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "process")
assertManualProcessCheck(s.T(), checkOutput, false, "stress-ng-cpu [run]", "stress-ng")
}
payloads, err = s.Env().FakeIntake.Client().GetProcesses()
assert.NoError(c, err, "failed to get process payloads from fakeintake")

func (s *K8sSuite) TestManualProcessDiscoveryCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "process_discovery")
assertManualProcessDiscoveryCheck(s.T(), checkOutput, "stress-ng-cpu [run]")
}
// 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)

func (s *K8sSuite) TestManualContainerCheck() {
checkOutput := execProcessAgentCheck(s.T(), s.Env().KubernetesCluster, "container")
assertManualContainerCheck(s.T(), checkOutput, "stress-ng")
assertProcessCollected(t, payloads, false, "stress-ng-cpu [run]")
assertContainersCollected(t, payloads, []string{"stress-ng", "process-agent"})
}

func execProcessAgentCheck(t *testing.T, cluster *components.KubernetesCluster, check string) string {
Expand Down

0 comments on commit e4992ca

Please sign in to comment.