Skip to content

bug: slog format string with %s placeholder in endpoint_api_manager.go #27

Description

@fennoai

问题描述

来源:PR #26 (7niu v1.19) code review 遗留问题

文件: pkg/endpoint/api/endpoint_api_manager.go:255

m.logger.Warn("Endpoint has %s annotation, but BPF bandwidth manager is disabled. This annotation is ignored.",
    logfields.K8sPodName, epTemplate.K8sNamespace+"/"+epTemplate.K8sPodName,
    logfields.Annotation, bandwidth.EgressBandwidth,
    logfields.Annotations, pod.Annotations,
)

问题原因

slog 不会插值 %s 格式占位符——生产日志中会直接打印出字面字符串 "Endpoint has %s annotation...",而非实际的注解名称。

上方的 ingress 变体(约第 248 行)使用的是正确的纯字符串消息,两者存在不一致。

修复建议

将消息中的 %s 去掉,直接把注解名称作为独立的 slog key-value 传入,或使用 fmt.Sprintf 拼接后作为消息字符串,例如:

m.logger.Warn("Endpoint has egress bandwidth annotation, but BPF bandwidth manager is disabled. This annotation is ignored.",
    logfields.K8sPodName, epTemplate.K8sNamespace+"/"+epTemplate.K8sPodName,
    logfields.Annotation, bandwidth.EgressBandwidth,
    logfields.Annotations, pod.Annotations,
)

影响

生产环境日志中该警告消息会出现 %s 未替换的情况,影响日志可读性和排查效率。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions