Skip to content

[17.0-stable] Ask pubsub whether the metrics fit - #6476

Merged
eriknordmark merged 1 commit into
lf-edge:17.0-stablefrom
eriknordmark:metrics-pubsub-size-guard-17.0-stable
Sep 8, 2026
Merged

eriknordmark merged 1 commit into
lf-edge:17.0-stablefrom
eriknordmark:metrics-pubsub-size-guard-17.0-stable

Conversation

@eriknordmark

@eriknordmark eriknordmark commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Backport of #6434 to 17.0-stable, of the single commit
b5da0e0, as requested there: a customer on
this branch is hitting the pubsub fatal that large URL metrics cause.

makeRoomForNewURL caps how many URLCounters entries are kept, but what
pubsub limits is the encoded size of the published map, which the length of the
URL keys dominates. A run of long URLs -- a registry blob URL, or a datastore
URL carrying a query string -- puts the map over the limit at an entry count the
cap still allows, and pubsub answers an oversized value with a fatal rather than
an error, taking down an agent that was only reporting on itself. Publish now
asks whether the value fits, gives up the least recently used entries until what
is left does, and reports rather than publishes if even an empty set does not.

The commit sits on top of the rest of #6434, which is not being backported, so
it was first rebased onto master and then cherry-picked here. Dropped in the
rebase: the net/http import and the two RecordAnswer hunks git offered
alongside, which belong to an earlier commit of #6434. Nothing the fix does was
changed, and the pick onto this branch was clean -- both touched files are
identical between master and 17.0-stable.

PR dependencies

Builds on the URLCounters entry cap from #6409, already merged here.

#6434 has not merged, so the commit carries no (cherry picked from commit ...) trailer -- there is no master SHA to reference yet, and the fork-branch
SHA is not the one that will land. This PR stays in draft until then; the commit
will be re-created with git cherry-pick -x <landed sha> and force-pushed once
#6434 merges.

How to test and validate this PR

Covered by automated unit tests, make -C pkg/pillar test: three new cases in
controllerconn -- a map that fits publishes untouched, one that does not is
trimmed least recently used first until it does, and one that cannot fit at all
is reported rather than published. fakePublication applies the limit the way
the socket driver does, base64-encoding the value before measuring it, so the
tests exercise the real framing rather than the raw JSON length.

Validated against un-fixed code on this branch: removing the CheckMaxSize
loop from Publish makes TestAgentMetricsPublishEvictsUntilItFits and
TestAgentMetricsPublishGivesUpWhenNothingLeftToDrop fail on their assertions,
and both pass again once restored.

Per-branch verification: gofmt -l controllerconn/, go build ./...,
go vet ./controllerconn/ ./types/ and go test ./controllerconn/ ./types/ all
exit 0.

Changelog notes

An agent reporting many distinct URLs -- most often the downloader, pulling
image blobs -- no longer dies when its metrics grow past the size a pubsub
message can carry. The oldest per-URL entries are given up instead, and counted
as redacted.

PR Backports

  • 17.0-stable: This PR.
  • 16.0-stable: Yes -- see [16.0-stable] Ask pubsub whether the metrics fit #6477.
  • 14.5-stable: No, the URLCounters cap this builds on is not present there.
  • 13.4-stable: No, the URLCounters cap this builds on is not present there,
    and the code still lives in the pre-rename pkg/pillar/zedcloud package.

Checklist

  • I've provided a proper description
  • I've added the proper documentation -- none needed; no user-visible
    interface changes.
  • I've tested my PR on amd64 device -- unit tests only, as above.
  • I've tested my PR on arm64 device -- not tested; the change is
    architecture independent.
  • I've written the test verification instructions
  • I've set the proper labels to this PR

For backport PRs:

  • I've added a reference link to the original PR
  • PR's title follows the template

The URLCounters cap counts entries, but what it defends is the encoded
size of the published map, and the length of the URL keys dominates that.
A run of long URLs -- a registry blob URL, or a datastore URL carrying a
query string -- puts the map over the limit at an entry count the cap
still allows, and pubsub answers an oversized value with a fatal rather
than an error, taking down an agent that was only reporting on itself.

Ask before publishing, and give up the least recently used entries,
counting each as redacted, until what is left fits. If even an empty set
of URL counters does not fit, report that and skip the publication
instead of letting it be fatal.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@eriknordmark eriknordmark added the bug Something isn't working label Sep 7, 2026
@eriknordmark
eriknordmark marked this pull request as ready for review September 7, 2026 22:04
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.76%. Comparing base (49d3d4e) to head (4b544da).

Additional details and impacted files
@@               Coverage Diff               @@
##           17.0-stable    #6476      +/-   ##
===============================================
+ Coverage        21.36%   21.76%   +0.40%     
===============================================
  Files              500      510      +10     
  Lines            92628    94345    +1717     
===============================================
+ Hits             19786    20538     +752     
- Misses           71197    71979     +782     
- Partials          1645     1828     +183     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eriknordmark
eriknordmark merged commit 7b36821 into lf-edge:17.0-stable Sep 8, 2026
55 of 57 checks passed
@eriknordmark
eriknordmark deleted the metrics-pubsub-size-guard-17.0-stable branch September 9, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants