Skip to content

Add zswap metrics: pool percent and writeback pages - #1383

Draft
mariafromano-25 wants to merge 1 commit into
kubernetes:masterfrom
mariafromano-25:add-zswap-pool-and-writeback-metrics
Draft

mariafromano-25 wants to merge 1 commit into
kubernetes:masterfrom
mariafromano-25:add-zswap-pool-and-writeback-metrics

Conversation

@mariafromano-25

Copy link
Copy Markdown

Add zswap pool percent and writeback pages metrics to system-stats-monitor

Followup work from: #1337 (already merged)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 21, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mariafromano-25
Once this PR has been reviewed and has the lgtm label, please assign klueska for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ajaysundark

Copy link
Copy Markdown
Contributor

/cc @ajaysundark

@kubernetes-prow
kubernetes-prow Bot requested a review from ajaysundark October 21, 2026 22:18
@mariafromano-25
mariafromano-25 force-pushed the add-zswap-pool-and-writeback-metrics branch from 4e5a0a9 to 5e91a63 Compare October 21, 2026 22:28
@mariafromano-25

Copy link
Copy Markdown
Author

/test all

@mariafromano-25
mariafromano-25 force-pushed the add-zswap-pool-and-writeback-metrics branch from 5e91a63 to 8466be9 Compare November 18, 2026 19:59

@hakman hakman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR @mariafromano-25. It mostly looks fine, but needs a few small things fixed before merging.

mc.collect()
}

func TestCalculateZswapPoolPercent(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file has no build tag, but these three tests call helpers that only exist in memory_collector_unix.go, so GOOS=windows go vet ./pkg/systemstatsmonitor/ fails with undefined: calculateZswapPoolPercent. CI doesn't catch it because we only test on Linux. Please move them to a memory_collector_unix_test.go with //go:build unix.

Comment on lines +199 to +201
if delta < 0 {
delta = current
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

readZswapWritebackPages returns 0 on any read or parse failure, and this treats that 0 as a counter reset. The next good read then adds the whole since-boot value again (100 → 0 → 105 exports 205). The same happens if a read falls back from vmstat to a slightly lower debugfs value.

The kernel counter can't go backwards while the node is up, so I'd drop the reset handling and keep the last value:

Suggested change
if delta < 0 {
delta = current
}
if delta < 0 {
return 0
}

The comment above and the last assertion in TestZswapWritebackPagesDelta need updating to match.

Comment on lines +49 to +50
MemoryZswapPoolPercentID MetricID = "memory/zswap_pool_percent"
MemoryZswapWritebackPagesID MetricID = "memory/zswap_writeback_pages"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two aren't in NPDMetricToSDMetric. With the default empty customMetricPrefix the type formatter returns "", and the GCP exporter sends that as-is, so I'd expect every export from the metric-only service to carry two time series that CreateTimeSeries rejects.

Do guest/memory/zswap/pool_percent and guest/memory/zswap/writeback_pages descriptors exist? If so, please add the mappings and the TestNPDMetricToSDMetric rows. If not, either leave the metrics out of the default config for now, or filter empty-type metrics in the Stackdriver exporter.

}
data, err := os.ReadFile(maxPoolPctPath)
if err != nil {
return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: an unreadable max_pool_percent is reported as 0%, which looks the same as an empty pool. Worth a log line at least.

return 0
}
maxPoolKB := float64(*meminfo.MemTotal) * (maxPoolPct / 100.0)
if maxPoolKB <= 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this can't be true, MemTotal and maxPoolPct are both checked positive above.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants