ITADN

The build_info metric prevents use of namespaces that start with a number.

#2079Closedmclosson-lsf 创建于 2026-01-15
lifecycle/rotten
M
mclosson-lsfcommented
Hi Library-go team. Library go creates a build info metric that uses the namespace name. builder.go ``` if b.versionInfo != nil { buildInfo := metrics.NewGaugeVec( &metrics.GaugeOpts{ Name: strings.Replace(namespace, "-", "_", -1) + "_build_info", Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit, git tree state, build date, Go version, " + "and compiler from which " + b.componentName + " was built, and platform on which it is running.", StabilityLevel: metrics.ALPHA, }, []string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState", "buildDate", "goVersion", "compiler", "platform"}, ) legacyregistry.MustRegister(buildInfo) buildInfo.WithLabelValues(b.versionInfo.Major, b.versionInfo.Minor, b.versionInfo.GitVersion, b.versionInfo.GitCommit, b.versionInfo.GitTreeState, b.versionInfo.BuildDate, b.versionInfo.GoVersion, b.versionInfo.Compiler, b.versionInfo.Platform).Set(1) klog.Infof("%s version %s-%s", b.componentName, b.versionInfo.GitVersion, b.versionInfo.GitCommit) } ``` prometheus doesn't allow metric names that start with a number. But k8s namespaces can start with a number. From time to time the QA team I work with forgets this and uses a namespace that starts with a number. Some of the pods that use library-go fail to start up because the prometheus libraries panic. Its a minor annoyance that causes a small amount of extra work to recover. I've looked at ways to work around this. 1. Use metric relabeling. This doesn't work because the relabeling happens when the scrape happens. Not when the metric is registered. 2. Try to set b.versionInfo to nil. This isn't an option because library go creates the ControllerBuilder and calls its Run function close together. 3. Avoid using NewCommand() (controllercmd/cmd.go) and reimplement that in my own code. This might be a possibility. But its ugly not ideal for long term maintenance. 4. Replace the implementation of WithVersion at runtime. Seems go doesn't really support this. And its hacky. 5. Patch library-go at build time. This is probably what I will do. I'm logging this bug to solicit consideration to change this. For example, set the metric name to `ns<namespace>_build_info`, `_<namespace>_build_info`, `build_info_<namespace>`. Thanks.
关闭于 2026-06-16 4 条评论