Skip to content

collector/slabinfo: index duplicate slab entries - #3784

Open
machismo0311 wants to merge 1 commit into
prometheus:masterfrom
machismo0311:fix/slabinfo-duplicate-index
Open

collector/slabinfo: index duplicate slab entries#3784
machismo0311 wants to merge 1 commit into
prometheus:masterfrom
machismo0311:fix/slabinfo-duplicate-index

Conversation

@machismo0311

Copy link
Copy Markdown

Fixes #3506.

/proc/slabinfo may contain repeated slab names, for example one cache per
device instance. The collector currently labels series only by slab name, so
duplicates produce identical label sets and cause Gather() to fail for the
entire scrape.

This change adds an index label, following the direction agreed in the issue,
so every cache keeps its own series, counts, and geometry.

Notes for review:

  • index is assigned after the include/exclude filter, so an excluded slab does
    not leave a gap in the ordinals.
  • The ordinal is positional and is not a stable identity. If a cache appears or
    disappears, subsequent indices can shift.
  • Geometry remains per entry. The kernel does not guarantee that same-named
    caches share object_size, so the exporter does not choose a representative
    value.
  • This collector previously had no dedicated test file. Four tests are added
    covering duplicate names, distinct names, differing geometry, and the
    filter/index interaction.
  • Both e2e golden files are updated. Values are unchanged. Only the new label is
    added.

Validated with:

  • gofmt
  • go vet ./...
  • go test -short ./...
  • golangci-lint using the repository-pinned version
  • amd64, 386, and arm64 builds
  • exact comparison of slabinfo fixture output

@nicolastakashi

Copy link
Copy Markdown

collector/slabinfo_linux_test.go:1 uses // Copyright 2026 The Prometheus Authors. New files need the year-less form, // Copyright The Prometheus Authorsmake check_license rejects 2026 or later.

Everything else looks good, including the index label: it matches the precedent already shipped in rapl_linux.go and sysctl_linux.go (both use a bare index label alongside a descriptive companion label), so no rename needed there.

@nicolastakashi

Copy link
Copy Markdown

/workflow-approve

/proc/slabinfo can list the same slab name more than once, for example one
cache per device instance. Labelling only by slab name therefore produces
duplicate label sets, causing the registry to reject the scrape.

Add an index label carrying each entry's position among entries sharing the
same slab name. This preserves one series per kernel cache and keeps each
entry's own counts and geometry.

The label name matches the existing ordinal index convention used by other
collectors. The ordinal follows /proc/slabinfo ordering and is not a stable
identity. It is assigned after filtering so excluded slabs do not consume an
index.

Fixes prometheus#3506

Signed-off-by: Kyle Mason <kyle@kylemason.org>
@machismo0311
machismo0311 force-pushed the fix/slabinfo-duplicate-index branch from 39d28bc to 0b94860 Compare August 6, 2026 12:48
@machismo0311

Copy link
Copy Markdown
Author

Fixed, thanks. The test file now uses the year-less header; check_license and the future-year grep in Makefile.common both pass locally. Amended in place, no other changes.

@nicolastakashi

Copy link
Copy Markdown

/workflow-approve

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The slabinfo collector produces duplicate metrics on a host with Mellanox cards

2 participants