- Analyzed the PromSketch library at
/mydata/promsketch - Identified core API:
PromSketchesstruct 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
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
- Copied entire
/mydata/promsketchtointernal/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
- Core API:
- Dependencies fetched via
go mod tidy
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
- Created
go.modforgithub.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)
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
Created comprehensive documentation:
-
- Complete directory layout
- Component overview
- Integration strategy
- Design decisions
-
docs/PROMSKETCH_LIBRARY_ANALYSIS.md
- Library API reference
- Data structure details
- Query function mapping
- Integration examples
- Configuration recommendations
-
PHASE1_COMPLETE.md (this file)
- Phase 1 completion summary
- 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
// 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())
}| 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 |
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.
Now ready to implement the ingestion layer:
-
Remote Write Receiver (
internal/ingestion/remotewrite/)- Prometheus remote write protocol handler
- Snappy decompression
- Protobuf parsing
-
Backend Forwarder (
internal/backend/forwarder/)- Forward all samples to VictoriaMetrics/Prometheus
- Batching and retry logic
- Connection pooling
-
Ingestion Pipeline (
internal/ingestion/pipeline/)- Coordinate: remote write → sketch insert → backend forward
- Error handling and metrics
-
Storage Layer Init (
internal/storage/)- Initialize PromSketches instance
- Implement sketch target matching
- Consistent hashing for partitioning
- ✅ Language: Go
- ✅ Module: Initialized
- ✅ Library: Integrated
- ✅ Structure: Complete
- ✅ Config: Implemented
- ✅ Docs: Comprehensive
- ⏳ Implementation: Ready for Phase 2
# 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 helpNew files:
go.mod,go.sumcmd/promsketch-dropin/main.gocmd/pskctl/main.gointernal/config/config.goconfigs/promsketch-dropin.example.yamldocs/PROJECT_STRUCTURE.mddocs/PROMSKETCH_LIBRARY_ANALYSIS.mdPHASE1_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.