mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* [Generator] Add DRAIN span_name sanitizer * Fix linter * Fix formatting * Update default manifest * Fix build error in update-fixtures * Remove bad test * Remove misleading comment * Add per-tenant override for drain mode * Do a machines job * Address PR feedback * Address PR review: rename drain_mode config and improve sanitizer - Rename `drain_mode` to `span_name_sanitization` across all config, legacy config, interfaces, and overrides for better user-facing clarity - Add explicit default value "disabled" in RegisterFlagsAndApplyDefaults - Add ValidateSpanNameSanitization function in validation/fields.go - Rename metrics to remove DRAIN reference: `drain_spans_compacted_total` -> `spans_sanitized_total` `post_drain_demand_estimate` -> `post_sanitization_demand_estimate` - Pass configured staleDuration to NewDrainSanitizer instead of hardcoded 15min, consistent with other registry components - Extract "span_name" magic string to labelSpanName constant - Update all tests with new names and signatures * Update manifest * Use empty string as disabled * Update CHANGELOG.md Co-authored-by: Suraj Nath <[email protected]> * Update manifest --------- Co-authored-by: Suraj Nath <[email protected]>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package drain
|
|
|
|
import (
|
|
"iter"
|
|
"time"
|
|
|
|
"github.com/maypok86/otter/v2"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
type logClusterCache struct {
|
|
cache *otter.Cache[int, *LogCluster]
|
|
}
|
|
|
|
func newLogClusterCache(maxAge time.Duration, maxSize int, evictions prometheus.Counter, expired prometheus.Counter) *logClusterCache {
|
|
return &logClusterCache{
|
|
cache: otter.Must(&otter.Options[int, *LogCluster]{
|
|
MaximumSize: maxSize,
|
|
ExpiryCalculator: otter.ExpiryAccessing[int, *LogCluster](maxAge),
|
|
OnAtomicDeletion: func(e otter.DeletionEvent[int, *LogCluster]) {
|
|
switch e.Cause {
|
|
case otter.CauseOverflow:
|
|
evictions.Inc()
|
|
case otter.CauseExpiration:
|
|
expired.Inc()
|
|
}
|
|
},
|
|
}),
|
|
}
|
|
}
|
|
|
|
func (c *logClusterCache) Values() iter.Seq[*LogCluster] {
|
|
return c.cache.Values()
|
|
}
|
|
|
|
// Set adds a cluster to the cache. This method may evict other clusters from the cache if it's full.
|
|
func (c *logClusterCache) Put(cluster *LogCluster) {
|
|
c.cache.Set(cluster.id, cluster)
|
|
}
|
|
|
|
// Remove invalidates a cluster from the cache.
|
|
func (c *logClusterCache) Remove(key int) {
|
|
c.cache.Invalidate(key)
|
|
}
|
|
|
|
// Get retrieves a cluster from the cache and updates the access time to prevent ttl-based eviction.
|
|
func (c *logClusterCache) Get(key int) *LogCluster {
|
|
cluster, ok := c.cache.GetIfPresent(key)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return cluster
|
|
}
|
|
|
|
// GetQuietly retrieves a cluster from the cache without updating the access time.
|
|
func (c *logClusterCache) GetQuietly(key int) *LogCluster {
|
|
entry, ok := c.cache.GetEntryQuietly(key)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return entry.Value
|
|
}
|
|
|
|
// NotExists checks if a cluster does not exist in the cache without updating the access time.
|
|
func (c *logClusterCache) NotExists(key int) bool {
|
|
_, ok := c.cache.GetEntryQuietly(key)
|
|
return !ok
|
|
}
|