8000 Unify the file path formatting in container meta information into one function. by linrunqi08 · Pull Request #2256 · alibaba/loongcollector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

linrunqi08
Copy link
Collaborator

No description provided.

@yyuuttaaoo yyuuttaaoo requested a review from Copilot June 13, 2025 08:34
@@ -658,6 +653,21 @@ func (dc *ContainerCenter) CreateInfoDetail(info types.ContainerJSON, envConfigP
return did
}

func formatConttainerJSONPath(info *types.ContainerJSON, formatStdoutLogPath bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container

Copy link
Contributor
@Copilot Copilot AI left a 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
Copy link
Preview
Copilot AI Jun 13, 2025

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.

Suggested change
cmd.UpperDir = containerInfo.UpperDir
cmd.UpperDir = filepath.Clean(containerInfo.UpperDir)

Copilot uses AI. Check for mistakes.

Comment on lines +237 to +238
Source: mount.Source,
Destination: mount.Destination,
Copy link
Preview
Copilot AI Jun 13, 2025

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.

Suggested change
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
Copy link
Preview
Copilot AI Jun 13, 2025

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.

Suggested change
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) {
Copy link
Preview
Copilot AI Jun 13, 2025

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.

Suggested change
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) {
Copy link
Preview
Copilot AI Jun 13, 2025

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.

Suggested change
func TestFormatConttainerJsonPath(t *testing.T) {
func TestFormatContainerJSONPath(t *testing.T) {

Copilot uses AI. Check for mistakes.

@linrunqi08 linrunqi08 merged commit adccc13 into main Jun 13, 2025
27 checks passed
@yyuuttaaoo yyuuttaaoo deleted the feature/taiye/fix_acs_stdout branch June 13, 2025 09:59
WRPStephanie pushed a commit to WRPStephanie/loongcollector that referenced this pull request Jun 20, 2025
… function. (alibaba#2256)

* fix container path format

* fix lint

* fix commentf
xiongyunn pushed a commit to xiongyunn/loongcollector that referenced this pull request Jun 27, 2025
… function. (alibaba#2256)

* fix container path format

* fix lint

* fix commentf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0