Skip to content

feat(telegraf-patch): allsketches processor (Phase 4 step C) - #237

Merged
zzylol merged 1 commit into
mainfrom
phase4/telegraf-allsketches-plugin
May 4, 2026
Merged

zzylol merged 1 commit into
mainfrom
phase4/telegraf-allsketches-plugin

Conversation

@zzylol

@zzylol zzylol commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements processors.allsketches per docs/design-asap-telegraf-integration.md §3, §5, §6, §8 — a single unified Telegraf StreamingProcessor whose sketch_type config field dispatches into the existing asap-precompute-go/sketches/<type> wrappers. No build script, no submodule patch — those are Phase D.

File layout

telegraf-patch/processors/allsketches/:

  • allsketches.go (203 LoC) — StreamingProcessor impl: Start validates config + spawns flush ticker, Add decodes via Phase-B codec then calls Precompute.Observe, Stop drains pending window with now+2*window to force-rotate the tumbling window.
  • config.go (156 LoC) — toPrecomputeConfig / toAdapterConfig / sketchFactory dispatch table mapping sketch_type → wrapper constructor + observer.
  • factory.go (27 LoC) — processors.AddStreaming("allsketches", …) registration with codec defaults.
  • sample.conf (33 LoC) — canonical [[processors.allsketches]] block.
  • README.md (121 LoC) — user-facing config docs.
  • allsketches_test.go (204 LoC) — lifecycle coverage.
  • go.mod / go.sum — module rooted at github.com/influxdata/telegraf/plugins/processors/allsketches, with sibling-checkout replace directives for asap-precompute-go, sketchlib-go, and the patched pdata.

Dispatch table

sketch_type Factory Observer
ddsketch sketches.NewDDSketchWrapper(alpha) sketches.DDSketchObserver{}
kll sketches.NewKLLWrapper(k, seed) sketches.KLLObserver{}
hll sketches.NewHLLWrapper() sketches.HLLObserver{}
countsketch sketches.NewCountSketchWrapper(rows, cols) sketches.CountSketchObserver{DefaultKey}
countminsketch sketches.NewCMSWrapper(rows, cols, false) sketches.CMSObserver{}

Defaults applied per sketch when unset: ddsketch alpha=0.01, kll k=200, countsketch/cms rows=4 cols=2048.

Test summary

go test -race ./... — all green (1.145s):

  • TestStart_InvalidSketchType — unknown sketch_type rejected at Start.
  • TestStart_InvalidWindow — unparsable window_size rejected at Start.
  • TestDDSketch_HappyPath — Start → 32 scalar Adds → Stop emits envelope-bearing metrics on the accumulator; verifies _asap_envelope_b64 field is base64-decodable.
  • TestEnvelopeShortcut — feed pre-aggregated _asap_envelope_b64 field, decode-side envelope-shortcut path exercised without value_field.
  • TestStopWithoutStart — Stop is a safe no-op when Start was never called (Telegraf reload race protection).
  • TestAllSketchTypes — loops over all five sketch_types, each constructs and processes 8 scalars and emits at least one envelope on Stop.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test -race ./... all pass
  • Phase D: build_sketchtelegraf.sh builds binary including the registered plugin
  • Phase E: cross-host envelope parity vs sketchcollector

🤖 Generated with Claude Code

… (Phase 4 step C)

Implements processors.allsketches per design-asap-telegraf-integration.md.
One Telegraf StreamingProcessor with sketch_type config dispatching to
asap-precompute-go/sketches/ wrappers. Lifecycle: Start spawns ticker;
Add observes via Phase-B codec; Stop drains pending windows.

NO build script, NO submodule patch — Phase D separately.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 7c2c685 into main May 4, 2026
@zzylol
zzylol deleted the phase4/telegraf-allsketches-plugin branch May 4, 2026 19:52
zzylol added a commit that referenced this pull request May 5, 2026
The processors.allsketches unified plugin (PR #237) supersedes the
older per-sketch aggregator-based attempt at Telegraf integration.
Remove the dead scaffolding:
- telegraf-patch/plugins/aggregators/{ddsketch,kll,countmin,gorilla,sketchutil}/
- telegraf-patch/plugins/aggregators/all/* (registration overlays)
- telegraf-patch/plugins/outputs/gorilla_s3/ (was wired to deleted gorilla)

Restore script and build pipeline already skip these per PR #240.
Three stale reference comments updated (matched_accuracy/main.go,
matched_accuracy/README.md, design-asap-edge-framework.md §7 table).

Net: 2420 LoC removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 5, 2026
The processors.allsketches unified plugin (PR #237) supersedes the
older per-sketch aggregator-based attempt at Telegraf integration.
Remove the dead scaffolding:
- telegraf-patch/plugins/aggregators/{ddsketch,kll,countmin,gorilla,sketchutil}/
- telegraf-patch/plugins/aggregators/all/* (registration overlays)
- telegraf-patch/plugins/outputs/gorilla_s3/ (was wired to deleted gorilla)

Restore script and build pipeline already skip these per PR #240.
Three stale reference comments updated (matched_accuracy/main.go,
matched_accuracy/README.md, design-asap-edge-framework.md §7 table).

Net: 2420 LoC removed.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request May 5, 2026
Phase 5 step C of the OTAP-Rust integration: full asap_sketches
plugin lifecycle on top of the Phase B codec. Adds Tokio-driven
input task + Wakeup-style flush ticker + control-channel poll task
+ graceful drain, with 5-sketch dispatch (DDSketch / KLL / HLL /
CountSketch / CountMinSketch) selected by the sketch_type config
knob, mirroring the Telegraf-side allsketches processor (#237).

New code:
- src/otap/config.rs: PluginConfig + 5-sketch sketch_type dispatch
  factory, mapping the user-facing string to (PrecomputeConfig,
  SketchFactory, SketchObserver). Mirrors Telegraf's
  toPrecomputeConfig + sketchFactory.
- src/otap/records.rs: local OtapMetricRecords model with the
  bidirectional sibling-batch <-> flat-batch projection that Phase
  B deferred. flatten() lowers per-row attribute rows into top-level
  Strategy-B columns the codec consumes; lift() raises Strategy-B
  columns onto the per-row attribute child batch on emit so OTAP's
  strict schema validator (crates/pdata/src/schema/payloads.rs::
  check_match) accepts the result. The upstream OtapArrowRecords
  binding lands in Phase D once the OTAP submodule is wired in.
- src/otap/lifecycle.rs: AsapSketchesPlugin Tokio runtime —
  three concurrent tasks (input stream consumer, interval-driven
  flush ticker, control-channel poll) plus oneshot-driven graceful
  shutdown that invokes Precompute::drain before exit so terminating
  before the natural window boundary doesn't drop in-flight
  observations.
- tests/otap_lifecycle.rs: end-to-end harness with one test per
  sketch_type (5 tests), drain-before-window-boundary test,
  control-channel plan-change test, plus shutdown smoke tests.

Plugin shell scaffolding (Phase D wires the linkme registration):
- otap-patch/plugins/asap_sketches/sample.toml: canonical TOML
  config block.
- otap-patch/plugins/asap_sketches/README.md: user-facing config +
  lifecycle docs.
- otap-patch/plugins/asap_sketches/src/mod.rs: placeholder for
  Phase D's linkme distributed-slice entry.

Cargo.toml: tokio (rt + sync + time + macros) and futures gated
under the existing `otap` feature; no new top-level features.

NOT in this PR (Phase D / E):
- build_sketchotap.sh build script.
- otap-patch/all/mod.rs linkme registration.
- Cross-host envelope parity test.

Verification:
- cargo test --release -p asap-precompute-rs --features otap: 127
  tests pass (was 118; added 9 lifecycle tests).
- cargo test --release -p asap-precompute-rs (no features): 88
  tests pass — otap-gated code is absent from the default build.
- cargo clippy --release -p asap-precompute-rs --features otap
  --all-targets -- -D warnings: clean.
- RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p
  asap-precompute-rs --features otap: clean.

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.

1 participant