feat(asap-precompute-go): SketchEnvelope MetricName/Count/Temporality + Sketch trait split - #224
Merged
Merged
Conversation
… + Sketch trait split - Add MetricName/Count/AggregationTemporality fields to in-process SketchEnvelope (wire format unchanged). - Split queries into QuantileSketch/CardinalitySketch/FrequencySketch sub-traits over base Sketch. - Remove _asap_metric_name label hack from OTel adapter encode. - Tests cover envelope population and sub-trait satisfaction. Phase 2 step 2.4b. Unblocks shim refactor PRs (steps 2.5–2.9). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 step 2.4b — extends the host-neutral
SketchEnvelopeand splits theSketchtrait so the upcoming OTel-shim refactor PRs (steps 2.5–2.9) candelegate to the runtime without resorting to side-channel labels.
1.
SketchEnvelopeenvelope.go — three new in-process fieldsMetricName string— the metric name the runtime emits each envelope for.Lets
Adapter.Encodestamppmetric.Metric.Name()directly instead offishing for the
_asap_metric_namelabel.Count uint64— total observation count this envelope represents (sum ofper-window samples). Used by the OTel adapter's
dp.SetCount()and as asanity field for downstream consumers.
AggregationTemporality int32— OTel temporality enum (0 unspecified / 1delta / 2 cumulative), stored as
int32notpmetric.AggregationTemporalityto keep the runtime free of the
pmetricimport (host-neutral invariantfrom ADR-0002).
These are in-process Go fields only — the proto wire format is unchanged
(
Payload []byteis still the canonical sketch state, per ADR-0002 §"Behaviorpreservation").
2.
Sketchtrait split — three new sub-interfaces in precompute.goThe base
Sketchinterface stays as the runtime's storage type(
Snapshot/ComputeDeltaAgainst/ApplyDelta/Merge/Reset— whatwindow.goandsnapshot_cache.goneed). Three sub-interfaces describe what each sketch cananswer:
QuantileSketch—Quantile(q float64) float64(DDSketch, KLL).CardinalitySketch—EstimateCardinality() float64(HLL).FrequencySketch—EstimateCount(key []byte) float64andTopK(k int) []FrequencyEntry(CountSketch, CountMinSketch).The runtime never type-asserts to the sub-traits — only adapter encode code
will (e.g.
s.(CardinalitySketch)for an HLL gauge).3. Wire the new envelope fields through the emit path
PrecomputeConfiggainsMetricName stringandTemporality int32.seriesEntrygainsCount uint64, incremented on each scalarObserveandaccumulated from
env.CountonObserveEnvelope.precompute.serializeSeriespopulatesMetricName/Count/AggregationTemporalityon every emitted envelope.4. OTel adapter encode — drop the
_asap_metric_namelabel hackotel/encode.go::metricNameForreadsenv.MetricNamedirectly; thelookupLabelhelper is removed.Encodenotes that the labels list no longer carries_asap_metric_namesince envelopes have a typed field.Tests
envelope_test.go(new) — pin zero-value defaults and field assignability.precompute_test.go— two new tests confirming envelopes carry MetricName /Count / Temporality (populated and zero-config cases), plus compile-time
var _ CardinalitySketch = (*hllStub)(nil)style assertions for all threesub-traits and a runtime smoke test.
otel/encode_test.go— existingMetricSuffix/MetricNametests updatedto use the typed
MetricNamefield instead of the legacy label.Test plan
cd asap-precompute-go && go build ./...cd asap-precompute-go && go test ./...cd asap-precompute-go && go test -race ./...cd asap-precompute-go && go vet ./...reverting to label-hack — verified once those PRs land.
Phase 2
Step 2.4b of the Phase 2 plan: see
docs/phase-2-execution-plan.md. Unblocksthe shim refactor PRs (steps 2.5–2.9) which will delegate windowing/snapshot/
delta logic to this runtime instead of duplicating it per-processor.