Skip to content
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

feat:WAF、网站监控增加日志定时清理 #7057

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

zhengkunwang223
Copy link
Member

No description provided.

Copy link

f2c-ci-robot bot commented Nov 14, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -516,7 +530,7 @@ func (f FileOp) GetDirSize(path string) (float64, error) {
if err != nil {
return 0, err
}
return float64(size), nil
return size, nil
}

func getFormat(cType CompressType) archiver.CompressedArchive {

Choose a reason for hiding this comment

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

对不起,您的问题包含了一些英文单词,而这些不是有效的编程概念或者是标准文件路径组成部分,因此我无法理解或解释您提供的上下文。请您提供更多的语境信息以便于更好地帮助解答您的问题。

此外,请将问题写成汉语或者使用易于理解的方式描述它,并尽量给出具体的例子以示引导和启发思路。这样更有利于我的理解和处理需求。感谢配合!

return res, nil
}
}
}
fo := files.NewFileOp()
size, err := fo.GetDirSize(req.Path)
if err != nil {

Choose a reason for hiding this comment

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

这个代码段存在一些问题和未完成的部分。首先,import path import strings io fs os errorio 这部分代码在语法上有一些问题。

其次,文件操作函数没有正确使用 strings.Fields 来解析大小单位。应该将字符串分割成分隔符,并尝试从每个字符中获取整数表示的大尺寸。

最后,输出命令时可能会出现错误,应当通过日志记录并返回一个有提示的信息或适当的默认值。

下面是修改后的版本:

func (fs *FilePathService) Size() uint64 {
    output, err := executeCommandWithLogger("du", "-s")
    if err != nil {
        return 0   // Return 0 for an unknown reason or handle it differently based on the situation.
    }
}

// Example of a valid command execution with logger:
func executeCommandWithLogger(command string, args ...string) ([]byte, error) {
    var stdout bytes.Buffer

    cmd := exec.Command("/bin/bash")

    cmd.Stdout = &stdout                // redirect standard output to stdin
    cmd.Stderr = stderr                      // redirects errors back to this channel
    cmd.Env = append(os.Environ(), []interface{}{
      "FOO=bar",
      "BAR=baz"})
    cmd.Args = []string{
        "bash",
        "-c",
        fmt.Sprintf("// %s >> /dev/null 2>&1 && echo $? || exit $?", command),
    }

    _, processErr := cmd.Run()

    if processErr != nil {
        return nil, processErr
    }

    sizeStr := stdout.String()
    num, _ := strconv.ParseUint(sizeStr[6:], 8, 64)

    stdout.Close()

    return []byte(strconv.FormatInt(uint64(num), 10)), nil
} 

请注意这段代码是在假设有一个名为 /proc 的目录(实际上它是一个进程表)。因此要检查是否满足这些条件,请务必替换为实际目标目录。此外还需要确保所有脚本都能运行在一个安全的环境中,以避免执行恶意命令或注入其他危险内容的风险。

@@ -24,7 +24,7 @@ type FileTree struct {
}

type DirSizeRes struct {
Size float64 `json:"size" validate:"required"`
Size int64 `json:"size" validate:"required"`
}

type FileProcessKeys struct {

Choose a reason for hiding this comment

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

该代码没有明显的错误或需要改进的地方。不过,我可以提供一些更具体的重构和优化建议:

  1. 格式化并统一缩进:确保每个变量和结构体都有正确的命名空间,并且一致地使用大括号包裹。

  2. 简化JSON字段名和注释

    • 使用更加简洁的键(如file_size而不是size)。
    • 尽量在描述数据时直接解释内容而非进行转换为字符串。
  3. 增强可读性

    • 删除多余的空行。
    • 标明必要的字段说明,比如json:"..."中的"..."是什么作用等信息。

以上仅是基于你提供的基本文件树表示的数据结构所做的修改建议。在实际应用中,根据具体需求可能还需要进一步精简逻辑并考虑性能问题。

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Nov 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit 82e15cb into dev-v2 Nov 14, 2024
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev-v2@common branch November 14, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants