Skip to content

Commit aba6cc1

Browse files
committed
fix TestBeatsReceiverProcessRuntimeFallback
1 parent d343ae2 commit aba6cc1

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

testing/integration/ess/beat_receivers_test.go

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ agent.monitoring.enabled: false
819819

820820
// Log lines TestBeatsReceiverProcessRuntimeFallback checks for
821821
const (
822-
otelRuntimeUnsupportedLogLineStart = "otel runtime is not supported"
822+
otelRuntimeUnsupportedLogLineStart = "otel runtime is not supported for component"
823823
otelRuntimeMonitoringOutputUnsupportedLogLineStart = "otel runtime is not supported for monitoring output"
824824
prometheusInputSkippedLogLine = "The Otel prometheus metrics monitoring input can't run in a beats process, skipping"
825825
)
@@ -842,19 +842,31 @@ func TestBeatsReceiverProcessRuntimeFallback(t *testing.T) {
842842
config := `agent.logging.to_stderr: true
843843
agent.logging.to_files: false
844844
inputs:
845-
# Collecting system metrics
846845
- type: system/metrics
847846
id: unique-system-metrics-input
848847
_runtime_experimental: otel
849848
streams:
850849
- metricsets:
851850
- cpu
851+
- type: system/metrics
852+
id: unique-system-metrics-input-2
853+
use_output: supported
854+
_runtime_experimental: otel
855+
streams:
856+
- metricsets:
857+
- cpu
852858
outputs:
853859
default:
854860
type: elasticsearch
855861
hosts: [http://localhost:9200]
856862
api_key: placeholder
857863
indices: [] # not supported by the elasticsearch exporter
864+
supported:
865+
type: elasticsearch
866+
hosts: [http://localhost:9200]
867+
api_key: placeholder
868+
status_reporting:
869+
enabled: false
858870
`
859871

860872
// this is the context for the whole test, with a global timeout defined
@@ -877,8 +889,25 @@ outputs:
877889
var statusErr error
878890
status, statusErr := fixture.ExecStatus(ctx)
879891
assert.NoError(collect, statusErr)
880-
// we should be running beats processes even though the otel runtime was requested
881-
assertBeatsHealthy(collect, &status, component.ProcessRuntimeManager, 4)
892+
// we should be running beats processes for components with default output even though the otel runtime was requested
893+
// agent should be healthy
894+
assert.Equal(t, int(cproto.State_HEALTHY), status.State)
895+
assert.Equal(t, 5, len(status.Components))
896+
897+
// all the components should be healthy, their units should be healthy, and they should identify
898+
// themselves as running in the process runtime if they're using the default or monitoring outputs
899+
for _, comp := range status.Components {
900+
assert.Equal(t, int(cproto.State_HEALTHY), comp.State)
901+
expectedComponentVersionInfoName := componentVersionInfoNameForRuntime(component.OtelRuntimeManager)
902+
if strings.HasSuffix(comp.Name, "default") || strings.HasSuffix(comp.Name, "monitoring") {
903+
expectedComponentVersionInfoName = componentVersionInfoNameForRuntime(component.ProcessRuntimeManager)
904+
}
905+
assert.Equal(t, expectedComponentVersionInfoName, comp.VersionInfo.Name)
906+
assert.Equal(t, expectedComponentVersionInfoName, comp.VersionInfo.Name)
907+
for _, unit := range comp.Units {
908+
assert.Equal(t, int(cproto.State_HEALTHY), unit.State)
909+
}
910+
}
882911
}, 1*time.Minute, 1*time.Second)
883912
logsBytes, err := fixture.Exec(ctx, []string{"logs", "-n", "1000", "--exclude-events"})
884913
require.NoError(t, err)
@@ -917,7 +946,7 @@ outputs:
917946
}
918947
})
919948

920-
assert.Len(t, unsupportedLogRecords, 5, "one log line for each component we try to run")
949+
assert.Len(t, unsupportedLogRecords, 1, "one log line for each component we try to run")
921950
assert.NotEmpty(t, prometheusUnsupportedLogRecord, "should get a log line about Otel prometheus metrics input being skipped")
922951
assert.NotEmpty(t, monitoringOutputUnsupportedLogRecord, "should get a log line about monitoring output not being supported")
923952
}
@@ -1068,13 +1097,8 @@ func assertCollectorComponentsHealthy(t *assert.CollectT, status *atesting.Agent
10681097
}
10691098

10701099
func assertBeatsHealthy(t *assert.CollectT, status *atesting.AgentStatusOutput, runtime component.RuntimeManager, componentCount int) {
1071-
var componentVersionInfoName string
1072-
switch runtime {
1073-
case "otel":
1074-
componentVersionInfoName = "beats-receiver"
1075-
default:
1076-
componentVersionInfoName = "beat-v2-client"
1077-
}
1100+
t.Helper()
1101+
componentVersionInfoName := componentVersionInfoNameForRuntime(runtime)
10781102

10791103
// agent should be healthy
10801104
assert.Equal(t, int(cproto.State_HEALTHY), status.State)
@@ -1798,3 +1822,15 @@ func TestMonitoringNoDuplicates(t *testing.T) {
17981822
combinedOutput, err = fut.Uninstall(ctx, &atesting.UninstallOpts{Force: true})
17991823
require.NoErrorf(t, err, "error uninstalling beat receiver agent monitoring, err: %s, combined output: %s", err, string(combinedOutput))
18001824
}
1825+
1826+
func componentVersionInfoNameForRuntime(runtime component.RuntimeManager) string {
1827+
var componentVersionInfoName string
1828+
switch runtime {
1829+
case component.OtelRuntimeManager:
1830+
componentVersionInfoName = "beats-receiver"
1831+
case component.ProcessRuntimeManager:
1832+
default:
1833+
componentVersionInfoName = componentVersionInfoNameForRuntime(component.DefaultRuntimeManager)
1834+
}
1835+
return componentVersionInfoName
1836+
}

0 commit comments

Comments
 (0)