Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spiffyy99 committed Jan 9, 2025
1 parent de1d250 commit 826b23c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
28 changes: 22 additions & 6 deletions receiver/dockerstatsreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ func TestContainerLifecycleEventsIntegration(t *testing.T) {

// no events should be received before container starts
assert.Never(t, func() bool {
return len(consumer.AllLogs()) > 0
}, 5*time.Second, 1*time.Second, "received unexpected events")
return consumer.LogRecordCount() > 0
}, 5*time.Second, 1*time.Second, "received %d unexpected events, expected 0", consumer.LogRecordCount())

nginxContainer := createNginxContainer(ctx, t)
nginxID := nginxContainer.GetContainerID()
Expand Down Expand Up @@ -250,13 +250,21 @@ func TestContainerLifecycleEventsIntegration(t *testing.T) {
require.NoError(t, nginxContainer.Terminate(ctx))

assert.Eventuallyf(t, func() bool {
return hasDockerEvents(consumer.AllLogs(), redisID, []string{
return hasDockerEvents(consumer.AllLogs(), nginxID, []string{
"docker.container.die",
"docker.container.stop",
})
}, 5*time.Second, 1*time.Second, "failed to receive container stop/die events")

consumer.Reset()
require.NoError(t, redisContainer.Terminate(ctx))

assert.Eventuallyf(t, func() bool {
return hasDockerEvents(consumer.AllLogs(), redisID, []string{
"docker.container.die",
"docker.container.stop",
})
}, 5*time.Second, 1*time.Second, "failed to receive container stop/die events")
assert.NoError(t, recv.Shutdown(ctx))
}

Expand All @@ -268,7 +276,7 @@ func TestFilteredContainerEventsIntegration(t *testing.T) {
f, config := factory()
// Only receive events from redis containers
config.Logs.Filters = map[string][]string{
"image": {"*redis*"},
"image": {"docker.io/library/redis:latest"},
}

consumer := new(consumertest.LogsSink)
Expand All @@ -282,8 +290,8 @@ func TestFilteredContainerEventsIntegration(t *testing.T) {

nginxContainer := createNginxContainer(ctx, t)
assert.Never(t, func() bool {
return len(consumer.AllLogs()) > 0
}, 5*time.Second, 1*time.Second, "received events for excluded container")
return consumer.LogRecordCount() > 0
}, 5*time.Second, 1*time.Second, "received %d unexpected events, expected 0", consumer.LogRecordCount())

redisContainer := createRedisContainer(ctx, t)
redisID := redisContainer.GetContainerID()
Expand All @@ -295,8 +303,16 @@ func TestFilteredContainerEventsIntegration(t *testing.T) {
})
}, 5*time.Second, 1*time.Second, "failed to receive redis container events")

consumer.Reset()
require.NoError(t, nginxContainer.Terminate(ctx))
require.NoError(t, redisContainer.Terminate(ctx))
assert.Eventuallyf(t, func() bool {
return hasDockerEvents(consumer.AllLogs(), redisID, []string{
"docker.container.die",
"docker.container.stop",
})
}, 5*time.Second, 1*time.Second, "failed to receive container stop/die events")

assert.NoError(t, recv.Shutdown(ctx))
}

Expand Down
11 changes: 7 additions & 4 deletions receiver/dockerstatsreceiver/logs_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ func newDockerEventPoller(
}

func (d *dockerEventPoller) Start(ctx context.Context) {
filterArgs := filters.NewArgs()
for k, v := range d.config.Logs.Filters {
for _, elem := range v {
filterArgs.Add(k, elem)
filterArgs := filters.Args{}
if len(d.config.Logs.Filters) > 0 {
filterArgs = filters.NewArgs()
for k, v := range d.config.Logs.Filters {
for _, elem := range v {
filterArgs.Add(k, elem)
}
}
}
for {
Expand Down

0 comments on commit 826b23c

Please sign in to comment.