PromSketch-Dropin is a sketch-augmented metrics proxy that provides drop-in compatibility with the Prometheus/VictoriaMetrics ecosystem while leveraging approximate query techniques for improved performance.
PromSketch-Dropin/
├── cmd/
│ ├── promsketch-dropin/ # Main server binary
│ │ └── main.go # Entry point for the server
│ └── pskctl/ # CLI tool for management and benchmarking
│ └── main.go # Entry point for the CLI
│
├── internal/ # Private application code
│ ├── promsketch/ # Copy of the PromSketch library
│ │ ├── promsketches.go # Main PromSketch API
│ │ ├── ExponentialHistogram.go # EH data structures
│ │ ├── uniformsampling.go # Uniform sampling implementation
│ │ ├── functions.go # Query functions
│ │ └── ... # Other sketch components
│ │
│ ├── config/ # Configuration management
│ │ └── config.go # Config parsing and validation
│ │
│ ├── ingestion/ # Ingestion layer
│ │ ├── remotewrite/ # Prometheus remote write receiver
│ │ ├── scrape/ # Built-in scrape manager
│ │ └── pipeline/ # Ingestion pipeline (sketch insertion + backend forwarding)
│ │
│ ├── storage/ # PromSketch instance management
│ │ ├── partition/ # Consistent hashing and partitioning
│ │ ├── matcher/ # Metric matching for sketch target selection
│ │ └── lifecycle/ # Instance creation and cleanup
│ │
│ ├── query/ # Query API and routing
│ │ ├── api/ # HTTP API handlers (/api/v1/query, /api/v1/query_range, etc.)
│ │ ├── router/ # Query routing logic (sketch vs. fallback)
│ │ ├── parser/ # MetricsQL/PromQL parser integration
│ │ └── engine/ # Sketch query execution engine
│ │
│ └── backend/ # Backend abstraction
│ ├── interface.go # Backend interface definition
│ ├── victoriametrics/ # VictoriaMetrics backend implementation
│ ├── prometheus/ # Prometheus backend implementation
│ └── forwarder/ # Backend sample forwarding logic
│
├── pkg/ # Public libraries (if any)
│
├── grafana-plugin/ # Grafana datasource plugin
│ ├── src/ # Plugin source code
│ ├── package.json # Node.js dependencies
│ └── README.md # Plugin documentation
│
├── configs/ # Configuration examples
│ ├── promsketch-dropin.example.yaml # Example config
│ └── scrape_config.example.yaml # Example scrape config
│
├── docker/ # Docker and deployment files
│ ├── Dockerfile # Dockerfile for promsketch-dropin
│ └── compose/ # Docker Compose examples
│ └── docker-compose.yaml # Full stack demo
│
├── scripts/ # Build and deployment scripts
│ ├── build.sh # Build script
│ └── test.sh # Test script
│
├── docs/ # Documentation
│ ├── PROJECT_STRUCTURE.md # This file
│ ├── ARCHITECTURE.md # Architecture overview
│ ├── API.md # API documentation
│ └── DEVELOPMENT.md # Development guide
│
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── LICENSE # Apache 2.0 License
└── README.md # Project README
Handles two ingestion modes:
- Remote Write Receiver: Accepts Prometheus remote write at
/api/v1/write - Built-in Scrape Manager: Directly scrapes configured targets
Both modes feed into the same pipeline that:
- Inserts samples into PromSketch instances (based on sketch targets config)
- Forwards all raw samples to the backend storage system
Manages PromSketch instances:
- Partitioning: Consistent hashing by metric name across N partitions
- Matching: Evaluates incoming metrics against
sketch_targetsconfig - Lifecycle: Creates new instances for matching metrics, expires stale instances
Implements Prometheus-compatible query API:
- API Handlers:
/api/v1/query,/api/v1/query_range,/api/v1/series,/api/v1/labels, etc. - Query Router: Analyzes queries to determine if sketch can answer
- If YES: Route to sketch engine
- If NO: Proxy to backend
- Parser: MetricsQL/PromQL parsing (likely reusing VictoriaMetrics parser)
- Engine: Executes sketch-based queries
Pluggable backend abstraction:
- Interface: Common interface for all backends
- Implementations: VictoriaMetrics, Prometheus, (future: InfluxDB, ClickHouse)
- Forwarder: Forwards ingested samples to backend via remote write
Copy of the original /mydata/promsketch library, providing:
- Core API:
PromSketchesstruct for managing sketch instances - Data Structures: Exponential Histogram (EH), UnivMon, KLL, Uniform Sampling
- Query Functions:
avg_over_time,quantile_over_time,entropy_over_time, etc.
Unified CLI for operations:
pskctl backfill: Backfill historical data from backendspskctl bench insert: Insertion throughput benchmarkingpskctl bench accuracy: Query accuracy comparisonpskctl check: Configuration validation
Custom Grafana datasource plugin:
- Based on Prometheus datasource type
- Branded as "PromSketch"
- Extensible for future sketch-specific features
- PromSketch library is written in Go
- Natural fit for Prometheus ecosystem
- Rich library support (Prometheus client libs, MetricsQL parser)
- Excellent concurrency and performance
- Copy PromSketch library into
internal/promsketch/ - Allows independent development
- No dependency on external PromSketch repo
- Can modify as needed for integration
- Not all time series get sketch instances
sketch_targetsconfig controls which metrics are sketched- Supports exact matches, regex, label matchers, wildcard
- Unmatched metrics still forwarded to backend (no overhead)
- Pluggable interface for multiple backends
- Easy to add new backends (InfluxDB, ClickHouse)
- Separation of concerns: ingestion, sketch, backend
- Phase 2: Implement ingestion layer (remote write + backend forwarding)
- Phase 3: Wire up PromSketch insertion on ingestion
- Phase 4: Implement query API endpoints with router
- Phase 5: Test with Grafana
- Phase 6: Build
pskctlCLI - Phase 7: Docker-compose demo setup
- Phase 8: Built-in scrape manager (optional)
See DEVELOPMENT.md for build instructions, testing, and contribution guidelines.