Skip to content

Commit c20cea5

Browse files
committed
fix TestBeatsReceiverProcessRuntimeFallback
1 parent b7965be commit c20cea5

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,24 @@ 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(collect, int(cproto.State_HEALTHY), status.State)
895+
assert.Equal(collect, 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(collect, int(cproto.State_HEALTHY), comp.State)
901+
expectedComponentVersionInfoName := componentVersionInfoNameForRuntime(component.OtelRuntimeManager)
902+
if strings.HasSuffix(comp.ID, "default") || strings.HasSuffix(comp.ID, "monitoring") {
903+
expectedComponentVersionInfoName = componentVersionInfoNameForRuntime(component.ProcessRuntimeManager)
904+
}
905+
assert.Equal(collect, expectedComponentVersionInfoName, comp.VersionInfo.Name)
906+
for _, unit := range comp.Units {
907+
assert.Equal(collect, int(cproto.State_HEALTHY), unit.State)
908+
}
909+
}
882910
}, 1*time.Minute, 1*time.Second)
883911
logsBytes, err := fixture.Exec(ctx, []string{"logs", "-n", "1000", "--exclude-events"})
884912
require.NoError(t, err)
@@ -917,7 +945,7 @@ outputs:
917945
}
918946
})
919947

920-
assert.Len(t, unsupportedLogRecords, 5, "one log line for each component we try to run")
948+
assert.Len(t, unsupportedLogRecords, 1, "one log line for each component we try to run")
921949
assert.NotEmpty(t, prometheusUnsupportedLogRecord, "should get a log line about Otel prometheus metrics input being skipped")
922950
assert.NotEmpty(t, monitoringOutputUnsupportedLogRecord, "should get a log line about monitoring output not being supported")
923951
}
@@ -1068,13 +1096,8 @@ func assertCollectorComponentsHealthy(t *assert.CollectT, status *atesting.Agent
10681096
}
10691097

10701098
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-
}
1099+
t.Helper()
1100+
componentVersionInfoName := componentVersionInfoNameForRuntime(runtime)
10781101

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

0 commit comments

Comments
 (0)