-
Notifications
You must be signed in to change notification settings - Fork 418
Unify the file path formatting in container meta information into one function. #2256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -658,6 +653,21 @@ func (dc *ContainerCenter) CreateInfoDetail(info types.ContainerJSON, envConfigP | |||
return did | |||
} | |||
|
|||
func formatConttainerJSONPath(info *types.ContainerJSON, formatStdoutLogPath bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR centralizes path normalization by removing scattered filepath.Clean
calls and routing all container-related paths through a single helper function.
- Removed inline
filepath.Clean
calls in Docker log metadata and CRI adapter code - Introduced
formatConttainerJSONPath
to handle cleaning of log paths, mounts, and graph-driver data - Updated container center fetch and CRI adapter flows to invoke the new formatting function and added a unit test
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
plugins/input/docker/logmeta/metric_container_info.go | Dropped per-field Clean calls in favor of centralized formatting |
pkg/helper/containercenter/cri_adapter.go | Added call to formatConttainerJSONPath post-inspection |
pkg/helper/containercenter/container_center.go | Extracted cleaning logic into formatConttainerJSONPath and invoked in fetchAll |
pkg/helper/containercenter/container_center_test.go | Added TestFormatConttainerJsonPath to verify normalization |
@@ -216,8 +216,8 @@ func (idf *InputDockerFile) Description() string { | |||
func (idf *InputDockerFile) addMappingToLogtail(info *containercenter.DockerInfoDetail, containerInfo ContainerInfoCache, allCmd *DockerFileUpdateCmdAll) { | |||
var cmd DockerFileUpdateCmd | |||
cmd.ID = info.ContainerInfo.ID | |||
cmd.UpperDir = filepath.Clean(containerInfo.UpperDir) | |||
cmd.LogPath = filepath.Clean(containerInfo.LogPath) | |||
cmd.UpperDir = containerInfo.UpperDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing the inline filepath.Clean
here, containerInfo.UpperDir
may remain unnormalized. Consider calling the centralized formatting function or applying filepath.Clean
to ensure consistent paths.
cmd.UpperDir = containerInfo.UpperDir | |
cmd.UpperDir = filepath.Clean(containerInfo.UpperDir) |
Copilot uses AI. Check for mistakes.
Source: mount.Source, | ||
Destination: mount.Destination, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed the Clean
calls on mount.Source
and mount.Destination
—these values may no longer be normalized. Either reintroduce cleaning here or invoke the unified formatting helper.
Source: mount.Source, | |
Destination: mount.Destination, | |
Source: filepath.Clean(mount.Source), | |
Destination: filepath.Clean(mount.Destination), |
Copilot uses AI. Check for mistakes.
@@ -285,7 +285,7 @@ func (idf *InputDockerFile) updateAll(allCmd *DockerFileUpdateCmdAll) { | |||
} | |||
|
|||
func (idf *InputDockerFile) updateMapping(info *containercenter.DockerInfoDetail, allCmd *DockerFileUpdateCmdAll) { | |||
logPath := filepath.Clean(info.StdoutPath) | |||
logPath := info.StdoutPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without calling
8000
filepath.Clean
, info.StdoutPath
may include redundant separators. Ensure this path is normalized by the shared formatting function.
logPath := info.StdoutPath | |
logPath := filepath.Clean(info.StdoutPath) |
Copilot uses AI. Check for mistakes.
@@ -658,6 +653,21 @@ func (dc *ContainerCenter) CreateInfoDetail(info types.ContainerJSON, envConfigP | |||
return did | |||
} | |||
|
|||
func formatConttainerJSONPath(info *types.ContainerJSON, formatStdoutLogPath bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the function name: formatConttainerJSONPath
has an extra 't'. Renaming to formatContainerJSONPath
will improve readability and consistency.
func formatConttainerJSONPath(info *types.ContainerJSON, formatStdoutLogPath bool) { | |
func formatContainerJSONPath(info *types.ContainerJSON, formatStdoutLogPath bool) { |
Copilot uses AI. Check for mistakes.
@@ -77,6 +78,61 @@ func TestGetIpByHost_2(t *testing.T) { | |||
os.Remove(hostFileName) | |||
} | |||
|
|||
func TestFormatConttainerJsonPath(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test function name contains a typo (Conttainer
). Update it to TestFormatContainerJSONPath
once the helper is renamed.
func TestFormatConttainerJsonPath(t *testing.T) { | |
func TestFormatContainerJSONPath(t *testing.T) { |
Copilot uses AI. Check for mistakes.
… function. (alibaba#2256) * fix container path format * fix lint * fix commentf
… function. (alibaba#2256) * fix container path format * fix lint * fix commentf
No description provided.