From bcd7e0495af97aaf8da80eb8e2b120a032c1a241 Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Mon, 13 Jan 2025 06:35:17 +0000 Subject: [PATCH] add forceReleaseStopContainerFile --- .../input/docker/logmeta/metric_container_info.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/input/docker/logmeta/metric_container_info.go b/plugins/input/docker/logmeta/metric_container_info.go index 5ac5b27eb4..3f6c55078c 100644 --- a/plugins/input/docker/logmeta/metric_container_info.go +++ b/plugins/input/docker/logmeta/metric_container_info.go @@ -111,6 +111,8 @@ type InputDockerFile struct { matchList map[string]*helper.DockerInfoDetail CollectingContainersMeta bool firstStart bool + + forceReleaseStopContainerFile bool } func formatPath(path string) string { @@ -133,6 +135,8 @@ func (idf *InputDockerFile) Name() string { func (idf *InputDockerFile) Init(context pipeline.Context) (int, error) { idf.context = context + idf.forceReleaseStopContainerFile = os.Getenv("FORCE_RELEASE_STOP_CONTAINER_FILE") == "true" + idf.lastContainerInfoCache = make(map[string]ContainerInfoCache) idf.firstStart = true @@ -476,9 +480,14 @@ func (idf *InputDockerFile) Collect(collector pipeline.Collector) error { idf.deleteMetric.Add(1) idf.notifyStop(id) idf.deleteMapping(id) - } else if c.Status() != helper.ContainerStatusRunning && len(idf.LogPath) > 0 { - // input_file时会触发 - idf.notifyStop(id) + } else if c.Status() != helper.ContainerStatusRunning && len(idf.LogPath) > 0 { // input_file时会触发 + if idf.forceReleaseStopContainerFile { + idf.deleteMetric.Add(1) + idf.notifyStop(id) + idf.deleteMapping(id) + } else { + idf.notifyStop(id) + } } } if allCmd != nil {