Skip to content

Why don't we use container ID directly #3280

@tomatopunk

Description

@tomatopunk

Hi folks:

Although we can already obtain the container id by using the full container name, why isn't it exposed?

func ContainerNameToDockerId(name string) string {
id := path.Base(name)
if matches := dockerCgroupRegexp.FindStringSubmatch(id); matches != nil {
return matches[1]
}
return id
}

Why don't we use container ID directly, and instead use the container name as the label ID value in DefaultContainerLabels?

cadvisor/metrics/prometheus.go

Lines 1769 to 1784 in d91f2e6

func DefaultContainerLabels(container *info.ContainerInfo) map[string]string {
set := map[string]string{LabelID: container.Name}
if len(container.Aliases) > 0 {
set[LabelName] = container.Aliases[0]
}
if image := container.Spec.Image; len(image) > 0 {
set[LabelImage] = image
}
for k, v := range container.Spec.Labels {
set[ContainerLabelPrefix+k] = v
}
for k, v := range container.Spec.Envs {
set[ContainerEnvPrefix+k] = v
}
return set
}

The problem with this is that we cannot map back to Kubernetes information using the container ID

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions