mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
github.com/hanzoai/metrics carries a NOTICE naming this module its successor, and it is archived and read-only. What the NOTICE did not say is that the code was still running: hanzoai/cloud went on importing the archive and mounting it for /v1/metrics, /v1/logs and /v1/traces, so a repository nobody can push to held eleven live routes and the store behind them. A succession is only finished when the successor has the code. It arrives whole — the per-tenant WAL store, the ZAP MetricBatch receiver, the routes and their tests — and the tests pass here unchanged but for the addresses. The addresses fold per HIP-1241: every route is under /v1/metrics, so the two foreign roots the archive answered on become /v1/metrics/logs/* and /v1/metrics/traces/*. Forward only; nothing answers at the old spelling. This store is its own. The event.* columnar plane the rest of this module reads is a different store of a different shape, and the succession note's claim that o11y already held this signal store was true only of that plane — these eleven routes had no home here until now. They share the module and nothing else. The tenant decision still comes from the host (Deps.Org), so the boundary that authenticates keeps naming the org and this package never reads a header.
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package metrics
|
|
|
|
import (
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
// tenantSet holds the three signal stores for one org/tenant.
|
|
type tenantSet struct {
|
|
Metrics *Store
|
|
Logs *LogStore
|
|
Traces *TraceStore
|
|
}
|
|
|
|
// Registry lazily creates per-tenant store sets. Each tenant's WALs live under
|
|
// <DataDir>/orgs/<org>/o11y/ (the HIP-0302 per-org convention), so one tenant's
|
|
// metrics/logs/traces never mingle with another's — the same binary serves
|
|
// lux.cloud and zoo.cloud with hard data isolation. A single-tenant deployment
|
|
// simply uses one org (the deployment brand).
|
|
type Registry struct {
|
|
mu sync.Mutex
|
|
dataDir string
|
|
tenants map[string]*tenantSet
|
|
}
|
|
|
|
// NewRegistry returns a registry rooted at dataDir ("" = in-memory, no durability).
|
|
func NewRegistry(dataDir string) *Registry {
|
|
return &Registry{dataDir: dataDir, tenants: make(map[string]*tenantSet)}
|
|
}
|
|
|
|
// For returns the store set for org, creating it (and enabling per-org WAL
|
|
// durability when dataDir is set) on first use. An empty org collapses to
|
|
// "default".
|
|
func (r *Registry) For(org string) *tenantSet {
|
|
if org == "" {
|
|
org = "default"
|
|
}
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
if ts := r.tenants[org]; ts != nil {
|
|
return ts
|
|
}
|
|
ts := &tenantSet{Metrics: NewStore(), Logs: NewLogStore(), Traces: NewTraceStore()}
|
|
if r.dataDir != "" {
|
|
dir := filepath.Join(r.dataDir, "orgs", org, "o11y")
|
|
_ = ts.Metrics.EnableDurability(filepath.Join(dir, "metrics.wal"))
|
|
_ = ts.Logs.EnableDurability(filepath.Join(dir, "logs.wal"))
|
|
_ = ts.Traces.EnableDurability(filepath.Join(dir, "traces.wal"))
|
|
}
|
|
r.tenants[org] = ts
|
|
return ts
|
|
}
|
|
|
|
// Tenants returns the org slugs that currently have stores (for /health/admin).
|
|
func (r *Registry) Tenants() []string {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
out := make([]string, 0, len(r.tenants))
|
|
for k := range r.tenants {
|
|
out = append(out, k)
|
|
}
|
|
return out
|
|
}
|