Skip to content

feat(besreceiver): stamp bazel.patterns on root span from PatternExpanded - #71

Merged
chagui merged 1 commit into
mainfrom
chagui/besreceiver/issue-62-patterns
Apr 25, 2026
Merged

chagui merged 1 commit into
mainfrom
chagui/besreceiver/issue-62-patterns

Conversation

@chagui

@chagui chagui commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Surfaces PatternExpanded events as a Slice[Map] attribute bazel.patterns on the root bazel.build span. Each entry is {pattern, target_count} aggregated by pattern across the invocation. Test-heavy repos that invoke bazel test //... get a self-describing trace — the difference between "asked for one thing" and "ran 1,400 tests" is now visible without correlating against external logs. Empty patterns and zero-target expansions are skipped.

Capped under high_cardinality_caps.patterns (default 50) following the #29 pattern. Truncation surfaces a warning log via the new []truncationRecord return from writeRootSpan — same shape as the BuildMetrics truncation pipeline. Aggregation is done over a map[string]int64 buffered on invocationState and stamped during writeRootSpan, identical to the workspace_items / build_metadata buffering. Empty buffer → no attribute, so absent vs present-but-empty stays a meaningful distinction.

One proto-shape note worth flagging: the pattern strings live on BuildEventId.pattern.pattern (repeated on the id), not on the PatternExpanded payload itself. The payload only carries test_suite_expansions. target_count is derived from len(event.children) — each child id is a target (or nested pattern) the expansion resolved to.

Required signature changes for the truncation plumbing: writeRootSpan now returns []truncationRecord, which threads through finalize and flushOrphaned. Both existing callers in tracebuilder.go updated to consume and warn-log the records. Distinct log message ("Truncated high-cardinality root-span attribute") so operators can filter from the BuildMetrics-side warning by namespace.

Closes #62.

@chagui
chagui marked this pull request as ready for review April 25, 2026 08:01
@chagui
chagui force-pushed the chagui/besreceiver/issue-62-patterns branch 2 times, most recently from df68ad6 to 6b0922a Compare April 25, 2026 12:44
…nded

Buffer PatternExpanded events per invocation (map pattern -> target_count)
and emit them as a bazel.patterns Slice[Map] on the root bazel.build span
during writeRootSpan. Entries are aggregated by pattern string across
events, sorted lexicographically, and capped by the new
high_cardinality_caps.patterns field (default 50). Truncation appends a
truncationRecord and the trace-builder logs a warning matching the #29
shape (invocation_id, attribute, original_count, kept).

Closes #62.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@chagui
chagui force-pushed the chagui/besreceiver/issue-62-patterns branch from 6b0922a to 20ead1f Compare April 25, 2026 13:18
@chagui
chagui merged commit 0680424 into main Apr 25, 2026
5 checks passed
@chagui
chagui deleted the chagui/besreceiver/issue-62-patterns branch April 25, 2026 13:23
chagui added a commit that referenced this pull request Apr 25, 2026
…rn_skipped (#75)

Three P0 corrections to bazel.patterns from the post-merge review of #71:

1. target_count filters to TargetConfigured children. Previously len(children)
   counted nested PatternExpanded ids and UnconfiguredLabel failure markers,
   inflating the reported count of resolved targets.

2. Multi-pattern events even-split target_count across the event's non-empty
   patterns (floor(M/N)). The proto carries no per-pattern attribution; the
   prior code stamped the full count to each pattern, summing to N×M across
   the slice. Single-pattern events — Bazel's dominant case — keep the exact
   count. Eliminates the inflation that the prior multi-pattern test had
   cemented as the contract.

3. pattern_skipped events route to a new bazel.patterns_skipped Slice[string]
   on the root span, instead of being silently dropped. Bazel emits these
   under --keep_going for parts of a top-level pattern whose expansion was
   skipped. eventTypeName surfaces them under a distinct event_type label
   so bes.events.processed counts the two id shapes separately.

Test coverage added: NonTargetConfiguredChildren_NotCounted,
PatternSkipped_EmitsSkippedAttribute, PatternSkippedOnly_NoPatternsAttribute,
PostFlush_Dropped. The existing multi-pattern test is renamed and updated to
assert the corrected even-split semantics. docs/attributes.md drops the
"1,400 tests" example and documents the new semantics + the new attribute.

Refs #62, follow-up to #71.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Record PatternExpanded as a slice attribute on the root span

1 participant