Skip to content

Diskstats/size bytes ci fix#9

Merged
anulika-asama merged 2 commits into
masterfrom
diskstats/size_bytes-ci-fix
Jun 23, 2026
Merged

Diskstats/size bytes ci fix#9
anulika-asama merged 2 commits into
masterfrom
diskstats/size_bytes-ci-fix

Conversation

@anulika-asama

@anulika-asama anulika-asama commented Jun 23, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Disk information metrics now include a size_bytes label for block devices.
    • New kernel modules collector exposing per-module metrics including size, refcount, and state.

anulika-asama and others added 2 commits June 23, 2026 15:41
Add the standard Apache license block to kernelmodules and systemdservices
collectors, and separate the local module import group in node_exporter.go.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PR adds a size_bytes label to the existing node_disk_info metric by reading sysfs block device size in diskstats_linux.go, with test and fixture updates. It also introduces a new kernelmodules collector in kernelmodules_linux.go that parses /proc/modules and emits per-module state, size, and refcount gauges. Minor housekeeping edits (license header, blank line) are also included.

Changes

diskstats size_bytes label

Layer / File(s) Summary
Descriptor, sysfs read, emission, tests, and fixtures
collector/diskstats_linux.go, collector/diskstats_linux_test.go, collector/fixtures/sys.ttar
Adds size_bytes to infoDesc label names, reads each device's block size from sysfs in Update with os.IsNotExist and debug-log fallback, passes the value to mustNewConstMetric, updates golden test expectations for all devices, adds the sys/block/sda/size fixture entry, and relocates NVMe fixture entries.

kernelmodules collector

Layer / File(s) Summary
Struct, init registration, and constructor
collector/kernelmodules_linux.go
Defines kernelModulesCollector with moduleStateDesc, moduleSizeDesc, and moduleRefcountDesc Prometheus descriptors plus a *slog.Logger; registers NewKernelModulesCollector via init(); constructor builds all three descriptors with a module label.
Update: /proc/modules parsing and metric emission
collector/kernelmodules_linux.go
Opens /proc/modules with a bufio.Scanner, parses size and refcount as floats, maps Live/Loading/Unloading state strings to 1/0/-1, skips malformed lines with a warning log, emits three gauge metrics per module, and returns scanner.Err().

Sequence Diagram(s)

sequenceDiagram
  participant Prometheus
  participant kernelModulesCollector
  participant procModules as /proc/modules

  Prometheus->>kernelModulesCollector: Update(ch)
  kernelModulesCollector->>procModules: Open and scan lines
  loop per module line
    procModules-->>kernelModulesCollector: name, size, refcount, state fields
    kernelModulesCollector->>kernelModulesCollector: parse size/refcount, map state string→numeric
    kernelModulesCollector->>Prometheus: emit state gauge (module label)
    kernelModulesCollector->>Prometheus: emit size_bytes gauge (module label)
    kernelModulesCollector->>Prometheus: emit refcount gauge (module label)
  end
  kernelModulesCollector-->>Prometheus: return scanner.Err()
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the disk now tells its size,
A sysfs read before your eyes.
And kernel modules? Now they speak—
Live, Loading, Unloading, peek!
Three gauges bloom from /proc/modules bright,
The rabbit checks the metrics right. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references a main change (diskstats and size_bytes) present in the changeset, though it uses informal language ('ci fix') that is somewhat unclear.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch diskstats/size_bytes-ci-fix

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
collector/kernelmodules_linux.go (1)

79-80: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Increase scanner token limit to avoid scrape-time failure on long /proc/modules lines.

bufio.Scanner uses a 64 KiB token cap by default. If a module line exceeds that, scanning aborts and Update returns an error (collector scrape failure). Set a larger buffer explicitly at scanner initialization.

Suggested patch
 	scanner := bufio.NewScanner(file)
+	// /proc/modules lines are typically short, but raise the token limit defensively
+	// so one oversized line doesn't fail the entire collector scrape.
+	scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
 	for scanner.Scan() {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@collector/kernelmodules_linux.go` around lines 79 - 80, The bufio.Scanner at
the scanner initialization point in kernelmodules_linux.go uses the default 64
KiB token limit, which can cause scanning to fail if lines in /proc/modules
exceed this size and result in collector scrape errors. After creating the
scanner with bufio.NewScanner, call the scanner.Buffer method to set a larger
maximum token size to accommodate longer module lines and prevent scrape-time
failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@collector/kernelmodules_linux.go`:
- Around line 79-80: The bufio.Scanner at the scanner initialization point in
kernelmodules_linux.go uses the default 64 KiB token limit, which can cause
scanning to fail if lines in /proc/modules exceed this size and result in
collector scrape errors. After creating the scanner with bufio.NewScanner, call
the scanner.Buffer method to set a larger maximum token size to accommodate
longer module lines and prevent scrape-time failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95fd258c-62a1-4aed-8584-285e6bbd47a7

📥 Commits

Reviewing files that changed from the base of the PR and between d5f39dc and 9e58579.

📒 Files selected for processing (6)
  • collector/diskstats_linux.go
  • collector/diskstats_linux_test.go
  • collector/fixtures/sys.ttar
  • collector/kernelmodules_linux.go
  • collector/systemdservices_linux.go
  • node_exporter.go
👮 Files not reviewed due to content moderation or server errors (1)
  • collector/fixtures/sys.ttar

@anulika-asama anulika-asama merged commit 4d0ce53 into master Jun 23, 2026
18 of 21 checks passed
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.

1 participant