How trickstercache/trickster works
Project type and purpose
• Trickster is a high-performance HTTP reverse proxy/cache and time-series database accelerator, implemented as a single Go binary.
• It sits between dashboard clients (e.g., Grafana) or generic HTTP clients and time-series backends (Prometheus, InfluxDB, ClickHouse) or any HTTP origin.
File structure
• Top-level modules:
• cmd/trickster: application entry point
• pkg/proxy: core reverse proxy, routing, request/response engines
• pkg/cache: pluggable cache backends (memory, filesystem, Redis, bbolt)
• pkg/backends: per-provider clients & logic (prometheus, influxdb, clickhouse, generic reverse proxy)
• pkg/config: loader, defaults, reload, flags, TLS settings
• pkg/observability: metrics, logging, tracing exporters & registry
• deploy/: Dockerfiles, Helm charts, Kubernetes manifests
• Patterns: layered architecture (listener → router → engines → cache → backend), plugin registries for caches/backends/auth/tracing.
Insights from README
• Trickster supports TLS/HTTP2 frontend termination, configurable caching & negative-caching, collapsed forwarding, byte-range requests, delta proxy cache, step-boundary normalization, fast-forward.
• Exposes Prometheus metrics, health endpoints, supports OpenTelemetry/Zipkin tracing.
• Deployable via Docker, Kubernetes, Helm; configured via YAML.
Main components & interactions
a. Components
• Clients: Dashboard UIs or generic HTTP clients
• Frontend Listener & TLS Termination (pkg/daemon, pkg/proxy/tls)
• Router & Path Matching (pkg/proxy/router)
• Authentication (pkg/proxy/authenticator)
• Request Engines (pkg/proxy/engines):
– Delta Proxy Cache
– Byte-range handling
– Collapsed forwarding
– Document & HTTP proxy modes
• Cache Layer (pkg/cache/*):
– In-memory, filesystem, Redis, bbolt, clustered index
• Backend Providers (pkg/backends/*): Prometheus, InfluxDB, ClickHouse, generic reverse proxy
• Observability (pkg/observability): metrics endpoint, logging, tracing exporters (OTLP, Zipkin, stdout)
• Configuration Management (pkg/config): loader, reloadable settings
• Deployment Packaging: Docker image, Helm chart, Kubernetes manifests
b. Relationships / Data Flows
1) Client → Listener/TLS → Router
2) Router → Authenticator → Request Rewriters
3) Request Engines check Cache Layer
– On hit: serve cached response
– On miss/partial hit: forward to Backend Provider
4) Backend Provider pools & ALB logic → Upstream TSDB or HTTP origin
5) Response merges (chunked, timeseries merge) → Cache write-through/negative caching
6) Response → Client
7) Each stage emits metrics & trace spans → Observability exporters
8) Config changes trigger dynamic reload
c. Architectural patterns & principles
• Layered, modular design with clear separation of concerns
• Plugin/registry pattern for extensibility (caches, backends, auth, tracing)
• Stateless proxy service; stateful cache can be external (Redis, bbolt)
• Defensive design: negative caching, health checks
d. Key technologies & libraries
• Go modules, standard net/http, OpenTelemetry
• YAML configuration
• Docker, Helm, Kubernetes