Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
17 changes: 16 additions & 1 deletion pkg/testing/fixture_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)

// ErrNotInstalled is returned in cases where Agent isn't installed
var ErrNotInstalled = errors.New("Elastic Agent is not installed") //nolint:stylecheck // Elastic Agent is a proper noun

Check failure on line 34 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

ST1005: error strings should not be capitalized (staticcheck)

// CmdOpts creates vectors of command arguments for different agent commands
type CmdOpts interface {
Expand Down Expand Up @@ -408,8 +408,23 @@
return mappedProcess
}

// getElasticAgentProcesses returns the running elastic-agent control plane processes. Note that this does not mean
// all processes running using the elastic-agent binary.
func getElasticAgentProcesses(t *gotesting.T) []runningProcess {
return getProcesses(t, `.*elastic\-agent.*`)
agentProcesses := getProcesses(t, `.*elastic\-agent.*`)
// the otel collector might be running as a subprocess using the elastic-agent otel command
// we don't want to count these, so we drop all processes which are children of another process on the list
pids := make(map[int]struct{}, len(agentProcesses))
for _, p := range agentProcesses {
pids[p.Pid] = struct{}{}
}
agentControlPlaneProcesses := make([]runningProcess, 0, len(agentProcesses))
for _, p := range agentProcesses {
if _, ok := pids[p.Ppid]; !ok {
agentControlPlaneProcesses = append(agentControlPlaneProcesses, p)
}
}
return agentControlPlaneProcesses
}

// Includes both the main elastic-agent process and the agentbeat sub-processes for ensuring
Expand Down Expand Up @@ -520,11 +535,11 @@
if installOpts.DelayEnroll {
enrollArgs = append(enrollArgs, "--delay-enroll")
}
if installOpts.EnrollOpts.URL != "" {

Check failure on line 538 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
enrollArgs = append(enrollArgs, "--url", installOpts.EnrollOpts.URL)

Check failure on line 539 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
}
if installOpts.EnrollOpts.EnrollmentToken != "" {

Check failure on line 541 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
enrollArgs = append(enrollArgs, "--enrollment-token", installOpts.EnrollOpts.EnrollmentToken)

Check failure on line 542 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
}
out, err = exec.CommandContext(ctx, "sudo", enrollArgs...).CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -611,11 +626,11 @@
if installOpts.DelayEnroll {
enrollArgs = append(enrollArgs, "--delay-enroll")
}
if installOpts.EnrollOpts.URL != "" {

Check failure on line 629 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
enrollArgs = append(enrollArgs, "--url", installOpts.EnrollOpts.URL)

Check failure on line 630 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
}
if installOpts.EnrollOpts.EnrollmentToken != "" {

Check failure on line 632 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
enrollArgs = append(enrollArgs, "--enrollment-token", installOpts.EnrollOpts.EnrollmentToken)

Check failure on line 633 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1008: could remove embedded field "EnrollOpts" from selector (staticcheck)
}
// run sudo elastic-agent enroll
out, err = exec.CommandContext(ctx, "sudo", enrollArgs...).CombinedOutput()
Expand Down Expand Up @@ -722,7 +737,7 @@
}

if err != nil && topPathStats != nil {
return out, fmt.Errorf("Elastic Agent is still installed at [%s]", topPath) //nolint:stylecheck // Elastic Agent is a proper noun

Check failure on line 740 in pkg/testing/fixture_install.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

ST1005: error strings should not be capitalized (staticcheck)
}

return out, nil
Expand Down
6 changes: 5 additions & 1 deletion testing/integration/ess/beat_receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ func TestClassicAndReceiverAgentMonitoring(t *testing.T) {
require.NoError(t, err, "error unmarshalling policy: %s", string(policyBytes))
d, prs := policy.Outputs["default"]
require.True(t, prs, "default must be in outputs")
d.ApiKey = string(apiKey)
d.ApiKey = apiKey
policy.Outputs["default"] = d

processNamespace := fmt.Sprintf("%s-%s", info.Namespace, "process")
policy.Agent.Monitoring["namespace"] = processNamespace
policy.Agent.Monitoring["_runtime_experimental"] = "process"

updatedPolicyBytes, err := yaml.Marshal(policy)
require.NoErrorf(t, err, "error marshalling policy, struct was %v", policy)
t.Cleanup(func() {
Expand Down
3 changes: 1 addition & 2 deletions testing/integration/ess/metrics_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func (runner *MetricsRunner) TestBeatsMetrics() {
query = genESQuery(agentStatus.Info.ID,
[][]string{
{"match", "component.id", cid},
{"exists", "field", "system.process.cpu.total.value"},
{"exists", "field", "system.process.memory.size"},
{"match", "agent.type", "metricbeat"},
})
now = time.Now()
res, err := estools.PerformQueryForRawQuery(ctx, query, "metrics-elastic_agent*", runner.info.ESClient)
Expand Down
22 changes: 19 additions & 3 deletions testing/integration/ess/package_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
require.Lenf(t, splits, 2,
"expected split of beats output version to be split into 2, it was split into %q",
strings.Join(splits, "|"))
wantBuildHash := splits[0]
filebeatBuildHash := splits[0]

// get the elastic-agent build hash
agentVersion, err := f.ExecVersion(ctx)
require.NoError(t, err, "failed to get agent version")
agentCommit := agentVersion.Binary.Commit

diagZip, err := f.ExecDiagnostics(ctx)
require.NoError(t, err, "failed collecting diagnostics")
Expand Down Expand Up @@ -251,9 +256,20 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
require.NoError(t, err, "could not parse state.yaml (%s)", stateYAML.Name())

for _, c := range state.Components {
assert.Equalf(t, wantBuildHash, c.State.VersionInfo.BuildHash,
var expectedCommit, expectedBuildHash string
switch c.State.VersionInfo.Name {
case "beats-receiver":
expectedBuildHash = agentCommit
expectedCommit = agentCommit
case "beat-v2-client":
expectedBuildHash = filebeatBuildHash
expectedCommit = filebeatBuildHash
default:
t.Errorf("got unknown value in version_info.name: %s", c.State.VersionInfo.Name)
}
assert.Equalf(t, expectedBuildHash, c.State.VersionInfo.BuildHash,
"component %s: VersionInfo.BuildHash mismatch", c.ID)
assert.Equalf(t, wantBuildHash, c.State.VersionInfo.Meta.Commit,
assert.Equalf(t, expectedCommit, c.State.VersionInfo.Meta.Commit,
"component %s: VersionInfo.Meta.Commit mismatch", c.ID)
}

Expand Down
3 changes: 3 additions & 0 deletions testing/integration/leak/long_running_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ func (handleMon *handleMonitor) Init(ctx context.Context, t *testing.T, fixture

for _, comp := range status.Components {
pidStr := pidInStatusMessageRegex.FindString(comp.Message)
if pidStr == "" { // could be an otel receiver, not a process
continue
}
pid, err := strconv.ParseInt(pidStr, 10, 64)
require.NoError(t, err)

Expand Down
Loading