diff --git a/libbeat/otelbeat/oteltest/oteltest.go b/libbeat/otelbeat/oteltest/oteltest.go index 1fb35f04d7a5..b7a68b351bc9 100644 --- a/libbeat/otelbeat/oteltest/oteltest.go +++ b/libbeat/otelbeat/oteltest/oteltest.go @@ -39,8 +39,13 @@ import ( ) type ReceiverConfig struct { - Name string - Config component.Config + // Name is the unique identifier for the component + Name string + // Beat is the name of the Beat that is running as a receiver + Beat string + // Config is the configuration for the receiver component + Config component.Config + // Factory is the factory to instantiate the receiver Factory receiver.Factory } @@ -73,6 +78,9 @@ func CheckReceivers(params CheckReceiversParams) { createReceiver := func(t *testing.T, rc ReceiverConfig) receiver.Logs { t.Helper() + require.NotEmpty(t, rc.Name, "receiver name must not be empty") + require.NotEmpty(t, rc.Beat, "receiver beat must not be empty") + var receiverSettings receiver.Settings // Replicate the behavior of the collector logger @@ -127,15 +135,31 @@ func CheckReceivers(params CheckReceiversParams) { } }) + beatForCompID := func(compID string) string { + for _, rec := range params.Receivers { + if rec.Name == compID { + return rec.Beat + } + } + + return "" + } + require.EventuallyWithT(t, func(ct *assert.CollectT) { logsMu.Lock() defer logsMu.Unlock() - // Ensure the logger fields from the otel collector are present in the logs. + // Ensure the logger fields from the otel collector are present for _, zl := range zapLogs.All() { + require.Contains(t, zl.ContextMap(), "otelcol.component.kind") + require.Equal(t, "receiver", zl.ContextMap()["otelcol.component.kind"]) + require.Contains(t, zl.ContextMap(), "otelcol.signal") + require.Equal(t, "logs", zl.ContextMap()["otelcol.signal"]) require.Contains(t, zl.ContextMap(), "otelcol.component.id") - require.Equal(t, zl.ContextMap()["otelcol.component.kind"], "receiver") - require.Equal(t, zl.ContextMap()["otelcol.signal"], "logs") + compID, ok := zl.ContextMap()["otelcol.component.id"].(string) + require.True(t, ok, "otelcol.component.id should be a string") + require.Contains(t, zl.ContextMap(), "service.name") + require.Equal(t, beatForCompID(compID), zl.ContextMap()["service.name"]) break } diff --git a/x-pack/filebeat/fbreceiver/receiver_test.go b/x-pack/filebeat/fbreceiver/receiver_test.go index a5384023d5dc..ddb9cc8724a9 100644 --- a/x-pack/filebeat/fbreceiver/receiver_test.go +++ b/x-pack/filebeat/fbreceiver/receiver_test.go @@ -51,6 +51,7 @@ func TestNewReceiver(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "filebeat", Config: &config, Factory: NewFactory(), }, @@ -155,11 +156,13 @@ func TestMultipleReceivers(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "filebeat", Config: config(), Factory: factory, }, { Name: "r2", + Beat: "filebeat", Config: config(), Factory: factory, }, diff --git a/x-pack/libbeat/cmd/instance/beat.go b/x-pack/libbeat/cmd/instance/beat.go index 4b71a01be1b5..22562256754a 100644 --- a/x-pack/libbeat/cmd/instance/beat.go +++ b/x-pack/libbeat/cmd/instance/beat.go @@ -110,7 +110,7 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an logpConfig := logp.Config{} logpConfig.AddCaller = true - logpConfig.Beat = b.Info.Name + logpConfig.Beat = b.Info.Beat logpConfig.Files.MaxSize = 1 if b.Config.Logging == nil { diff --git a/x-pack/metricbeat/mbreceiver/receiver_test.go b/x-pack/metricbeat/mbreceiver/receiver_test.go index 7f5b0bcef7d9..86af125b7a18 100644 --- a/x-pack/metricbeat/mbreceiver/receiver_test.go +++ b/x-pack/metricbeat/mbreceiver/receiver_test.go @@ -73,6 +73,7 @@ func TestNewReceiver(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "metricbeat", Config: &config, Factory: NewFactory(), }, @@ -178,11 +179,13 @@ func TestMultipleReceivers(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "metricbeat", Config: &config1, Factory: factory, }, { Name: "r2", + Beat: "metricbeat", Config: &config2, Factory: factory, },