Fix the issue of missing container information caused by the event sequence when docker compose is repeatedly up. #1875
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述: docker compose环境下,会发现容器信息发现模块会获取的created状态的容器,参见https://alidocs.dingtalk.com/i/nodes/N7dx2rn0JbxOaqnACxvaegn5WMGjLRb3
复现条件:
docker compose up -d命令,启动一个容器之后,修改docker-compose.yaml文件,然后再执行docker compose up -d
问题原因分析:
从事件顺序可以看到,新旧容器的交替顺序是这样的:
新容器create(其他名字),旧容器杀、停、删,新容器rename,新容器start
事件监听rename的时候,会fetchone,rename的时候,容器还没有start,此时fetchone获取的就是created状态的容器信息。标准输出的插件里面,会根据containerID缓存容器信息,所以及时后面fetchone又更新了容器信息,标准输出也感知不到
修复方案:
fetchone里强校验容器状态