Skip to content

Commit

Permalink
Fix ContainerID detector on systemd with colon in cgroup path (#4449)
Browse files Browse the repository at this point in the history
Co-authored-by: David Ashpole <dashpole@google.com>
  • Loading branch information
Fricounet and dashpole committed Jan 23, 2024
1 parent 3f74d77 commit 71d13ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ This release drops the compatibility guarantee of [Go 1.19].
- Do not append `_total` if the counter already has that suffix for the Prometheus exproter in `go.opentelemetry.io/otel/exporter/prometheus`. (#4373)
- Fix resource detection data race in `go.opentelemetry.io/otel/sdk/resource`. (#4409)
- Use the first-seen instrument name during instrument name conflicts in `go.opentelemetry.io/otel/sdk/metric`. (#4428)
- Fix `ContainerID` resource detection on systemd when cgroup path has a colon. (#4449)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion sdk/resource/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type containerIDProvider func() (string, error)

var (
containerID containerIDProvider = getContainerIDFromCGroup
cgroupContainerIDRe = regexp.MustCompile(`^.*/(?:.*-)?([0-9a-f]+)(?:\.|\s*$)`)
cgroupContainerIDRe = regexp.MustCompile(`^.*/(?:.*[-:])?([0-9a-f]+)(?:\.|\s*$)`)
)

type cgroupContainerIDDetector struct{}
Expand Down
5 changes: 5 additions & 0 deletions sdk/resource/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func TestGetContainerIDFromLine(t *testing.T) {
line: " 13:name=systemd:/pod/d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356 ",
expectedContainerID: "d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356",
},
{
name: "with colon",
line: " 13:name=systemd:/kuberuntime/containerd/kubepods-pod872d2066_00ef_48ea_a7d8_51b18b72d739:cri-containerd:e857a4bf05a69080a759574949d7a0e69572e27647800fa7faff6a05a8332aa1",
expectedContainerID: "e857a4bf05a69080a759574949d7a0e69572e27647800fa7faff6a05a8332aa1",
},
{
name: "invalid hex string",
line: "13:name=systemd:/podruntime/docker/kubepods/ac679f8a8319c8cf7d38e1adf263bc08d23zzzz",
Expand Down

0 comments on commit 71d13ff

Please sign in to comment.