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
34 changes: 29 additions & 5 deletions libbeat/otelbeat/oteltest/oteltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/fbreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestNewReceiver(t *testing.T) {
Receivers: []oteltest.ReceiverConfig{
{
Name: "r1",
Beat: "filebeat",
Config: &config,
Factory: NewFactory(),
},
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/metricbeat/mbreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestNewReceiver(t *testing.T) {
Receivers: []oteltest.ReceiverConfig{
{
Name: "r1",
Beat: "metricbeat",
Config: &config,
Factory: NewFactory(),
},
Expand Down Expand Up @@ -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,
},
Expand Down
Loading