diff --git a/collector/logs/sources/tail/pod_discovery.go b/collector/logs/sources/tail/pod_discovery.go index 521d1b3b..177aa5e9 100644 --- a/collector/logs/sources/tail/pod_discovery.go +++ b/collector/logs/sources/tail/pod_discovery.go @@ -206,8 +206,10 @@ func (i *PodDiscovery) tombstoneTarget(existingCurrentTarget *currenttarget) { // We don't want to just tell tailsource to stop tailing when the file reaches EOF because the file // may be written to again in the "future" and perhaps even rotated. - logger.Infof("Tombstoning target %s", existingCurrentTarget.CurrentTarget.FilePath) - existingCurrentTarget.ExpireTime = i.nowFunc().Add(1 * time.Minute) + if existingCurrentTarget.ExpireTime.IsZero() { + logger.Infof("Tombstoning target %s", existingCurrentTarget.CurrentTarget.FilePath) + existingCurrentTarget.ExpireTime = i.nowFunc().Add(1 * time.Minute) + } } func (i *PodDiscovery) cleanTombstonedTargets() { diff --git a/collector/logs/sources/tail/pod_discovery_test.go b/collector/logs/sources/tail/pod_discovery_test.go index a54f00c3..730eb700 100644 --- a/collector/logs/sources/tail/pod_discovery_test.go +++ b/collector/logs/sources/tail/pod_discovery_test.go @@ -39,6 +39,25 @@ func TestPodDiscoveryLifecycle(t *testing.T) { require.Equal(t, 0, len(tailSource.targetRemoves)) }) + t.Run("Add Pod Without ContainerId", func(t *testing.T) { + _, tailSource, podDiscovery := create() + defer tailSource.Close() + err := podDiscovery.Open(context.Background()) + require.NoError(t, err) + + pod := scrapedPod("pod1") + pod.Status.ContainerStatuses[0].ContainerID = "" + + podDiscovery.OnAdd(pod, false) + + cleanTombstonedTargets(podDiscovery) + err = podDiscovery.Close() + require.NoError(t, err) + // No containerID yet, so no target added. + require.Equal(t, 0, len(tailSource.targetAdds)) + require.Equal(t, 0, len(tailSource.targetRemoves)) + }) + t.Run("Add Tolerant of Failure", func(t *testing.T) { // Failure tailing first container, but ok to tail the second container failureFunc := func(target FileTailTarget) error { diff --git a/collector/logs/sources/tail/pod_target.go b/collector/logs/sources/tail/pod_target.go index d44f99f0..4ab983f3 100644 --- a/collector/logs/sources/tail/pod_target.go +++ b/collector/logs/sources/tail/pod_target.go @@ -172,7 +172,8 @@ func isTargetChanged(old, new FileTailTarget) bool { func getContainerID(containerStatuses []v1.ContainerStatus, containerName string) (string, bool) { for _, container := range containerStatuses { if container.Name == containerName { - return container.ContainerID, true + containerIdPopulated := container.ContainerID != "" + return container.ContainerID, containerIdPopulated } } return "", false