Skip to content

Add ddsketch metric type in otel-collector-contrib telemetrygen - #15

Merged
zzylol merged 1 commit into
mainfrom
zeying-telemetrygen-metric-types
Dec 10, 2025
Merged

zzylol merged 1 commit into
mainfrom
zeying-telemetrygen-metric-types

Conversation

@zzylol

@zzylol zzylol commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@zzylol zzylol linked an issue Dec 10, 2025 that may be closed by this pull request
@zzylol zzylol changed the title Add ddsketch metric type in otel-collector-contrib telemetrygen; close #13 Add ddsketch metric type in otel-collector-contrib telemetrygen Dec 10, 2025
@zzylol
zzylol merged commit cf34898 into main Dec 10, 2025
@zzylol
zzylol deleted the zeying-telemetrygen-metric-types branch December 10, 2025 21:47
zzylol added a commit that referenced this pull request Apr 15, 2026
Mirrors PR #158 for the CountSketch variant: replaces Gauge-with-
byte-attribute emission with typed `CountSketchDataPoint` messages so
ASAPQuery-backend's modified-OTLP sketch router sees them as
`Metric.data = CountSketch{...}` variants instead of anonymous
Gauges.

## Why

Before this PR the processor emitted:

  metric.SetEmptyGauge()
  dp := gauge.DataPoints().AppendEmpty()
  dp.Attributes().PutEmptyBytes("sketch_payload").FromRaw(payload)
  dp.Attributes().PutStr("encoding", "proto_full")
  dp.Attributes().PutStr("partition_key", partitionKey)
  dp.Attributes().PutDouble("epsilon", p.config.Epsilon)
  dp.Attributes().PutDouble("delta", p.config.Delta)

The ASAPQuery-backend's modified-OTLP decoder matches on
`Metric.data = CountSketch{data_points: [...]}` (oneof tag 15, typed
`CountSketchDataPoint` messages) and never looked at Gauge attribute
maps. The decoder for CountSketch (ASAPQuery PR #15) was ready but
nothing produced the typed data points it wanted.

After this PR the same loop emits `CountSketchDataPoint` with
`SetSketch` / `SetEncoding` / `SetDimension` / `SetEpsilon` / `SetDelta`,
and the previously-orphaned backend decoder starts seeing real sketch
bytes on the wire.

## What changed

### `processor.go`

Split emission on `p.config.TransmitSketch`:

  * **TransmitSketch = true** (production): typed
    `CountSketchDataPoint`. The processor's `partition_key` string
    maps naturally onto `CountSketchDataPoint.Dimension` (both
    identify which sub-population the sketch covers). `Epsilon` and
    `Delta` get dedicated setters on the typed DP. `sample_count`
    and `window_duration_seconds` remain attribute-map entries —
    the typed DP has no setter for them, and they're
    observability-only (the backend doesn't use them for routing).
    `AggregationTemporality` set to `Delta` because each emission
    represents one window's delta.
  * **TransmitSketch = false**: keep the legacy Gauge emission so
    existing scalar-series dashboards continue to work.

### `delta_transmission_test.go`

Same pattern as PR #158 — introduced a `csTestDataPoint` adapter
and rewrote `getCSOutputDPs` to dispatch on `pmetric.MetricTypeCountSketch`
(typed path) or `MetricTypeGauge` (legacy path) and synthesize the
legacy attribute keys (`sketch_payload`, `encoding`, `partition_key`,
`epsilon`, `delta`) from the typed fields, so every existing test
assertion that reads via `dps[0].Attributes().Get(...)` keeps
compiling without per-site rewrites.

`csEncodingToLegacyString` maps `CountSketchEncodingProto` →
"proto_full" / `CountSketchEncodingDelta` → "proto_delta" for the
legacy string comparisons.

### `processor_test.go`

Two tests (`TestGroupByPartitioning`, `TestWindowModeGroupBy`)
previously walked `ms.At(k).Gauge().DataPoints()` directly to
extract `partition_key` attributes from the output. Both now route
through the `getCSOutputDPs` adapter from `delta_transmission_test.go`
so they see the typed path transparently.

Incidental gofmt drift on pre-existing struct literal indentation
is included because `gofmt -w` fired on the whole file. None of it
is functional.

## Validation

Same pre-existing `go.opentelemetry.io/collector/processor/selfmonitor`
resolution issue as PR #158 blocks local `go build` in this worktree
layout — a go.mod replace directive gap that predates my changes.
`gofmt -l` is clean on my three touched files. All API methods used
(`SetEmptyCountSketch`, `SetSketch`, `SetEncoding`, `SetDimension`,
`SetEpsilon`, `SetDelta`, `CountSketchEncodingProto` / `Delta`,
`MetricTypeCountSketch`) are already exposed by pmetric — no new
API needed.

## Follow-ups

  * `hllprocessor` — same refactor next, then `kllprocessor`.
  * MSGPACK encoding option per-processor once all four typed
    refactors land — one-line branch selecting sketchlib-go's
    `SerializeMsgpack` and `CountSketchEncodingMsgpack` (from PR #157).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Apr 15, 2026
Mirrors PR #158 for the CountSketch variant: replaces Gauge-with-
byte-attribute emission with typed `CountSketchDataPoint` messages so
ASAPQuery-backend's modified-OTLP sketch router sees them as
`Metric.data = CountSketch{...}` variants instead of anonymous
Gauges.

## Why

Before this PR the processor emitted:

  metric.SetEmptyGauge()
  dp := gauge.DataPoints().AppendEmpty()
  dp.Attributes().PutEmptyBytes("sketch_payload").FromRaw(payload)
  dp.Attributes().PutStr("encoding", "proto_full")
  dp.Attributes().PutStr("partition_key", partitionKey)
  dp.Attributes().PutDouble("epsilon", p.config.Epsilon)
  dp.Attributes().PutDouble("delta", p.config.Delta)

The ASAPQuery-backend's modified-OTLP decoder matches on
`Metric.data = CountSketch{data_points: [...]}` (oneof tag 15, typed
`CountSketchDataPoint` messages) and never looked at Gauge attribute
maps. The decoder for CountSketch (ASAPQuery PR #15) was ready but
nothing produced the typed data points it wanted.

After this PR the same loop emits `CountSketchDataPoint` with
`SetSketch` / `SetEncoding` / `SetDimension` / `SetEpsilon` / `SetDelta`,
and the previously-orphaned backend decoder starts seeing real sketch
bytes on the wire.

## What changed

### `processor.go`

Split emission on `p.config.TransmitSketch`:

  * **TransmitSketch = true** (production): typed
    `CountSketchDataPoint`. The processor's `partition_key` string
    maps naturally onto `CountSketchDataPoint.Dimension` (both
    identify which sub-population the sketch covers). `Epsilon` and
    `Delta` get dedicated setters on the typed DP. `sample_count`
    and `window_duration_seconds` remain attribute-map entries —
    the typed DP has no setter for them, and they're
    observability-only (the backend doesn't use them for routing).
    `AggregationTemporality` set to `Delta` because each emission
    represents one window's delta.
  * **TransmitSketch = false**: keep the legacy Gauge emission so
    existing scalar-series dashboards continue to work.

### `delta_transmission_test.go`

Same pattern as PR #158 — introduced a `csTestDataPoint` adapter
and rewrote `getCSOutputDPs` to dispatch on `pmetric.MetricTypeCountSketch`
(typed path) or `MetricTypeGauge` (legacy path) and synthesize the
legacy attribute keys (`sketch_payload`, `encoding`, `partition_key`,
`epsilon`, `delta`) from the typed fields, so every existing test
assertion that reads via `dps[0].Attributes().Get(...)` keeps
compiling without per-site rewrites.

`csEncodingToLegacyString` maps `CountSketchEncodingProto` →
"proto_full" / `CountSketchEncodingDelta` → "proto_delta" for the
legacy string comparisons.

### `processor_test.go`

Two tests (`TestGroupByPartitioning`, `TestWindowModeGroupBy`)
previously walked `ms.At(k).Gauge().DataPoints()` directly to
extract `partition_key` attributes from the output. Both now route
through the `getCSOutputDPs` adapter from `delta_transmission_test.go`
so they see the typed path transparently.

Incidental gofmt drift on pre-existing struct literal indentation
is included because `gofmt -w` fired on the whole file. None of it
is functional.

## Validation

Same pre-existing `go.opentelemetry.io/collector/processor/selfmonitor`
resolution issue as PR #158 blocks local `go build` in this worktree
layout — a go.mod replace directive gap that predates my changes.
`gofmt -l` is clean on my three touched files. All API methods used
(`SetEmptyCountSketch`, `SetSketch`, `SetEncoding`, `SetDimension`,
`SetEpsilon`, `SetDelta`, `CountSketchEncodingProto` / `Delta`,
`MetricTypeCountSketch`) are already exposed by pmetric — no new
API needed.

## Follow-ups

  * `hllprocessor` — same refactor next, then `kllprocessor`.
  * MSGPACK encoding option per-processor once all four typed
    refactors land — one-line branch selecting sketchlib-go's
    `SerializeMsgpack` and `CountSketchEncodingMsgpack` (from PR #157).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SieDeta pushed a commit that referenced this pull request Apr 17, 2026
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.

add ddsketch metric type in telemetrygen

1 participant