Skip to content

Commit 71d13ff

Browse files
Fricounetdashpole
andauthored
Fix ContainerID detector on systemd with colon in cgroup path (open-telemetry#4449)
Co-authored-by: David Ashpole <[email protected]>
1 parent 3f74d77 commit 71d13ff

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ This release drops the compatibility guarantee of [Go 1.19].
280280
- Do not append `_total` if the counter already has that suffix for the Prometheus exproter in `go.opentelemetry.io/otel/exporter/prometheus`. (#4373)
281281
- Fix resource detection data race in `go.opentelemetry.io/otel/sdk/resource`. (#4409)
282282
- Use the first-seen instrument name during instrument name conflicts in `go.opentelemetry.io/otel/sdk/metric`. (#4428)
283+
- Fix `ContainerID` resource detection on systemd when cgroup path has a colon. (#4449)
283284

284285
### Deprecated
285286

sdk/resource/container.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type containerIDProvider func() (string, error)
2929

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

3535
type cgroupContainerIDDetector struct{}

sdk/resource/container_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func TestGetContainerIDFromLine(t *testing.T) {
6262
line: " 13:name=systemd:/pod/d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356 ",
6363
expectedContainerID: "d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356",
6464
},
65+
{
66+
name: "with colon",
67+
line: " 13:name=systemd:/kuberuntime/containerd/kubepods-pod872d2066_00ef_48ea_a7d8_51b18b72d739:cri-containerd:e857a4bf05a69080a759574949d7a0e69572e27647800fa7faff6a05a8332aa1",
68+
expectedContainerID: "e857a4bf05a69080a759574949d7a0e69572e27647800fa7faff6a05a8332aa1",
69+
},
6570
{
6671
name: "invalid hex string",
6772
line: "13:name=systemd:/podruntime/docker/kubepods/ac679f8a8319c8cf7d38e1adf263bc08d23zzzz",

0 commit comments

Comments
 (0)