Skip to content

Latest commit

 

History

History
240 lines (191 loc) · 7.81 KB

File metadata and controls

240 lines (191 loc) · 7.81 KB

Phase 1: Project Setup - COMPLETE ✅

What Was Done

1. Library Analysis ✅

  • Analyzed the PromSketch library at /mydata/promsketch
  • Identified core API: PromSketches struct with insertion and query methods
  • Documented three main sketch types:
    • ExpoHistogramKLL: For quantile queries (min, max, quantile_over_time)
    • ExpoHistogramUniv: For cardinality/entropy queries (distinct_over_time, entropy_over_time)
    • UniformSampling: For statistical queries (avg, sum, count, stddev)
  • Mapped 13 supported query functions to sketch types
  • Analyzed thread-safety, dependencies, and memory characteristics

Full analysis: docs/PROMSKETCH_LIBRARY_ANALYSIS.md

2. Project Structure ✅

Created complete directory structure following Go best practices:

PromSketch-Dropin/
├── cmd/
│   ├── promsketch-dropin/       # Main server (stub created)
│   └── pskctl/                  # CLI tool (stub created)
├── internal/
│   ├── promsketch/              # ✅ Copied PromSketch library
│   ├── config/                  # ✅ Config management implemented
│   ├── ingestion/               # Ready for Phase 2
│   ├── storage/                 # Ready for Phase 3
│   ├── query/                   # Ready for Phase 4
│   └── backend/                 # Ready for Phase 2
├── pkg/                         # Public libraries
├── grafana-plugin/              # Ready for Phase 5
├── configs/                     # ✅ Example config created
├── docker/compose/              # Ready for Phase 7
├── scripts/                     # Build scripts
└── docs/                        # ✅ Documentation created

Structure documentation: docs/PROJECT_STRUCTURE.md

3. PromSketch Library Integration ✅

  • Copied entire /mydata/promsketch to internal/promsketch/
  • Removed separate go.mod to make it part of main module
  • All 60+ Go files, including:
    • Core API: promsketches.go
    • Data structures: ExponentialHistogram.go, uniformsampling.go, UnivMon.go
    • Query functions: functions.go
    • Supporting utilities: heap.go, utils.go, value.go
  • Dependencies fetched via go mod tidy

4. Configuration System ✅

Created comprehensive configuration framework:

File: internal/config/config.go

  • Type-safe configuration structs
  • YAML-based configuration
  • Validation logic
  • Default value application
  • Support for all major components:
    • Server settings
    • Ingestion (remote write + scrape)
    • Backend forwarding
    • Sketch parameters
    • Query API

Example config: configs/promsketch-dropin.example.yaml

  • Production-ready configuration template
  • Documented all options
  • Includes sketch target matching examples

5. Go Module Initialization ✅

  • Created go.mod for github.com/promsketch/promsketch-dropin
  • Fetched all dependencies including:
    • Prometheus ecosystem libs
    • VictoriaMetrics types
    • Sketch dependencies (KLL, xxhash, roaring bitmaps)
    • YAML parsing (gopkg.in/yaml.v3)
  • Module is buildable (dependencies resolved)

6. Command Stubs ✅

Created entry points for both binaries:

cmd/promsketch-dropin/main.go:

  • Configuration loading
  • Version flag
  • Graceful shutdown handling
  • TODO markers for Phase 2+ implementation

cmd/pskctl/main.go:

  • Command structure: backfill, bench, check, version
  • Subcommands: bench insert, bench accuracy, check config
  • Usage documentation built-in
  • Ready for Phase 6 implementation

7. Documentation ✅

Created comprehensive documentation:

  1. docs/PROJECT_STRUCTURE.md

    • Complete directory layout
    • Component overview
    • Integration strategy
    • Design decisions
  2. docs/PROMSKETCH_LIBRARY_ANALYSIS.md

    • Library API reference
    • Data structure details
    • Query function mapping
    • Integration examples
    • Configuration recommendations
  3. PHASE1_COMPLETE.md (this file)

    • Phase 1 completion summary

Key Findings from Library Analysis

Language Decision: Go

  • PromSketch library is written in Go 1.22.5
  • Perfect fit for Prometheus ecosystem
  • Rich library support (will reuse Prometheus/VM libraries)
  • Excellent concurrency primitives for parallel sketch queries

Core API Usage Pattern

// 1. Initialize PromSketches instance
ps := promsketch.NewPromSketches()

// 2. Create sketch instance for a time series (based on config)
err := ps.NewSketchCacheInstance(
    labels,
    "quantile_over_time",  // function to optimize for
    1800 * 1000,           // 30-minute window in milliseconds
    100000,                // item window size
    1.0,                   // value scale
)

// 3. Insert samples
err = ps.SketchInsert(labels, timestamp, value)

// 4. Check query coverage
if ps.LookUp(labels, "quantile_over_time", mint, maxt) {
    // 5. Execute sketch query
    result, _ := ps.Eval("quantile_over_time", labels, 0.99, mint, maxt, time.Now().UnixMilli())
}

Sketch Types and Functions

Query Function Sketch Type Use Case
quantile_over_time EHKLL P50, P99 latency
avg_over_time USampling Average CPU, memory
sum_over_time USampling Total requests
count_over_time USampling Event counts
distinct_over_time EHUniv Unique users, IPs
entropy_over_time EHUniv Data distribution
max_over_time / min_over_time EHKLL Min/max values
stddev_over_time USampling Variance

Memory Characteristics

Per-series overhead (with default config):

  • EHKLL (quantiles): ~12KB (K=50, kll_k=256)
  • EHUniv (cardinality): ~varies by data
  • Sampling: ~160KB (max_size=10000, sampling_rate=0.2)

Recommendation: Use selective sketch creation based on sketch_targets config to control memory.

Next Steps (Phase 2)

Now ready to implement the ingestion layer:

  1. Remote Write Receiver (internal/ingestion/remotewrite/)

    • Prometheus remote write protocol handler
    • Snappy decompression
    • Protobuf parsing
  2. Backend Forwarder (internal/backend/forwarder/)

    • Forward all samples to VictoriaMetrics/Prometheus
    • Batching and retry logic
    • Connection pooling
  3. Ingestion Pipeline (internal/ingestion/pipeline/)

    • Coordinate: remote write → sketch insert → backend forward
    • Error handling and metrics
  4. Storage Layer Init (internal/storage/)

    • Initialize PromSketches instance
    • Implement sketch target matching
    • Consistent hashing for partitioning

Project Status

  • Language: Go
  • Module: Initialized
  • Library: Integrated
  • Structure: Complete
  • Config: Implemented
  • Docs: Comprehensive
  • Implementation: Ready for Phase 2

Build and Run

# Build server
go build -o bin/promsketch-dropin ./cmd/promsketch-dropin

# Build CLI
go build -o bin/pskctl ./cmd/pskctl

# Run server (will fail - not implemented yet)
./bin/promsketch-dropin -config.file configs/promsketch-dropin.example.yaml

# Show CLI help
./bin/pskctl help

Files Created/Modified in Phase 1

New files:

  • go.mod, go.sum
  • cmd/promsketch-dropin/main.go
  • cmd/pskctl/main.go
  • internal/config/config.go
  • configs/promsketch-dropin.example.yaml
  • docs/PROJECT_STRUCTURE.md
  • docs/PROMSKETCH_LIBRARY_ANALYSIS.md
  • PHASE1_COMPLETE.md

Copied:

  • internal/promsketch/ (entire library, 60+ files)

Directories created:

  • cmd/, internal/, pkg/, configs/, docker/compose/, grafana-plugin/, scripts/, docs/
  • internal/ingestion/, internal/storage/, internal/query/, internal/backend/

Phase 1 complete! Ready to proceed with Phase 2: Ingestion Layer Implementation.