Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: bug-fix
summary: Restore Heartbeat monitor state in OTel mode
component: elastic-agent
issue: https://github.com/elastic/elastic-agent/issues/16284
18 changes: 17 additions & 1 deletion internal/pkg/otel/translate/otelconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func getReceiversConfigForComponent(
if comp.OutputType == "kafka" || comp.OutputType == "logstash" {
sharedConfig["include_metadata"] = true
}
if beatName == "heartbeat" && comp.OutputType == "elasticsearch" {
sharedConfig["monitor_state"] = map[string]any{
"elasticsearch": getBeatsAuthExtensionID(comp.OutputName).String(),
}
}
if beatName == "filebeat" && fbfeatures.IsElasticsearchStateStoreEnabled() {
sharedConfig["storage"] = elasticsearchStateStoreExtensionName
}
Expand Down Expand Up @@ -645,7 +650,18 @@ func getExporterConfigForComponent(comp *component.Component, exporterType otelc
if !ok {
return nil, nil, nil, nil, nil
}
return unitToExporterConfig(outputUnit, comp.OutputName, exporterType, logger)

exporterCfg, queueCfg, extensionCfg, processors, err = unitToExporterConfig(
outputUnit,
comp.OutputName,
exporterType,
logger,
)
if err != nil {
return nil, nil, nil, nil, err
}

return exporterCfg, queueCfg, extensionCfg, processors, nil
}

// getSignalForComponent returns the otel signal for the given component. Currently, this is always logs, even for
Expand Down
140 changes: 139 additions & 1 deletion internal/pkg/otel/translate/otelconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,12 @@ func TestGetOtelConfig(t *testing.T) {

expectedExtensionConfig := func(extra ...extraParams) map[string]any {
finalOutput := map[string]any{
"auth": map[string]any{
"password": "password",
"username": "elastic",
},
"continue_on_error": true,
"endpoints": []string{"http://localhost:9200"},
"idle_connection_timeout": "3s",
"proxy_disable": false,
"proxy_url": "https://example.com",
Expand Down Expand Up @@ -592,6 +597,9 @@ func TestGetOtelConfig(t *testing.T) {
// expects component id
expectedHeartbeatReceiverConfig := func(id string) map[string]any {
cfg := beatReceiverBaseConfig(id, "heartbeat", "synthetics/http")
cfg["monitor_state"] = map[string]any{
"elasticsearch": "beatsauth/_agent-component/default",
}
cfg["heartbeat"] = map[string]any{
"monitors": []map[string]any{
{
Expand Down Expand Up @@ -2080,7 +2088,9 @@ func TestGetOtelConfig(t *testing.T) {
"heartbeatreceiver/_agent-component/heartbeat-default/heartbeat-unit-test-1": expectedHeartbeatReceiverConfig("heartbeat-default"),
},
"service": map[string]any{
"extensions": []any{"beatsauth/_agent-component/default"},
"extensions": []any{
"beatsauth/_agent-component/default",
},
"pipelines": map[string]any{
"logs/_agent-component/heartbeat-default": map[string][]string{
"exporters": {"elasticsearch/_agent-component/default"},
Expand Down Expand Up @@ -3620,6 +3630,130 @@ func TestGetReceiversConfigForComponentNoEnabledStreams(t *testing.T) {
}
}

func TestGetReceiversConfigForComponentHeartbeatElasticsearchAuth(t *testing.T) {
newHeartbeatComponent := func(outputType string, singleReceiver bool) *component.Component {
return &component.Component{
ID: "heartbeat-auth-test-id",
InputType: "synthetics/http",
OutputType: outputType,
OutputName: "default",
InputSpec: &component.InputRuntimeSpec{
BinaryName: "elastic-otel-collector",
Spec: component.InputSpec{
Name: "synthetics/http",
Command: &component.CommandSpec{
Args: []string{"heartbeat"},
},
SingleReceiver: singleReceiver,
},
},
Units: []component.Unit{
{
ID: "heartbeat-auth-test-id-unit",
Type: client.UnitTypeInput,
Config: component.MustExpectedConfig(map[string]any{
"id": "test",
"use_output": "default",
"type": "synthetics/http",
"streams": []any{
map[string]any{
"id": "http-1",
"data_stream": map[string]any{
"dataset": "synthetics.http",
},
"urls": []any{"https://example.com/one"},
"schedule": "@every 5s",
},
map[string]any{
"id": "http-2",
"data_stream": map[string]any{
"dataset": "synthetics.http",
},
"urls": []any{"https://example.com/two"},
"schedule": "@every 10s",
},
},
}),
},
},
}
}

tests := []struct {
name string
outputType string
singleReceiver bool
expectedReceiverIDs []string
expectedAuth string
}{
{
name: "elasticsearch per-stream receivers",
outputType: "elasticsearch",
singleReceiver: false,
expectedReceiverIDs: []string{
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-1",
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-2",
},
expectedAuth: "beatsauth/_agent-component/default",
},
{
name: "elasticsearch single receiver",
outputType: "elasticsearch",
singleReceiver: true,
expectedReceiverIDs: []string{
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/single",
},
expectedAuth: "beatsauth/_agent-component/default",
},
{
name: "logstash",
outputType: "logstash",
singleReceiver: false,
expectedReceiverIDs: []string{
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-1",
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-2",
},
},
{
name: "kafka",
outputType: "kafka",
singleReceiver: false,
expectedReceiverIDs: []string{
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-1",
"heartbeatreceiver/_agent-component/heartbeat-auth-test-id/unit-http-2",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := getReceiversConfigForComponent(
newHeartbeatComponent(tt.outputType, tt.singleReceiver),
nil,
nil,
)
require.NoError(t, err, "heartbeat receiver translation must succeed")
require.Len(t, result, len(tt.expectedReceiverIDs), "translation must generate the expected receiver count")

for _, receiverID := range tt.expectedReceiverIDs {
require.Contains(t, result, receiverID, "translation must generate receiver %q", receiverID)
}

for receiverID, rawConfig := range result {
receiverConfig, ok := rawConfig.(map[string]any)
require.True(t, ok, "receiver %q config must be a map", receiverID)
if tt.expectedAuth == "" {
assert.NotContains(t, receiverConfig, "monitor_state", "receiver %q must omit monitor state for %s output", receiverID, tt.outputType)
continue
}
monitorState, ok := receiverConfig["monitor_state"].(map[string]any)
require.True(t, ok, "receiver %q monitor state config must be a map", receiverID)
assert.Equal(t, tt.expectedAuth, monitorState["elasticsearch"], "receiver %q must reference the output-scoped Elasticsearch auth extension", receiverID)
}
})
}
}

// TestGetReceiversConfigForComponentBrowserMonitor verifies that a Synthetics browser
// monitor, which compiles into a single synthetics/browser input with a scheduled
// "browser" stream plus schedule-less "browser.network" and "browser.screenshot"
Expand Down Expand Up @@ -4263,6 +4397,7 @@ func TestUnitToExporterConfig(t *testing.T) {
expectedExtensionCfg: map[string]any{
"beatsauth/_agent-component/default": map[string]any{
"continue_on_error": true,
"endpoints": []string{"http://es:9200"},
"idle_connection_timeout": "3s",
"proxy_disable": false,
"timeout": "1m30s",
Expand Down Expand Up @@ -4302,6 +4437,7 @@ func TestUnitToExporterConfig(t *testing.T) {
expectedExtensionCfg: map[string]any{
"beatsauth/_agent-component/default": map[string]any{
"continue_on_error": true,
"endpoints": []string{"http://es:9200"},
"idle_connection_timeout": "3s",
"proxy_disable": false,
"timeout": "1m30s",
Expand Down Expand Up @@ -4333,6 +4469,7 @@ func TestUnitToExporterConfig(t *testing.T) {
expectedExtensionCfg: map[string]any{
"beatsauth/_agent-component/default": map[string]any{
"continue_on_error": true,
"endpoints": []string{"http://es:9200"},
"idle_connection_timeout": "3s",
"proxy_disable": false,
"timeout": "1m30s",
Expand Down Expand Up @@ -4368,6 +4505,7 @@ func TestUnitToExporterConfig(t *testing.T) {
expectedExtensionCfg: map[string]any{
"beatsauth/_agent-component/default": map[string]any{
"continue_on_error": true,
"endpoints": []string{"http://es:9200"},
"idle_connection_timeout": "3s",
"proxy_disable": false,
"timeout": "5m",
Expand Down
Loading
Loading