Files
traces/pkg/drain/log_cluster.go
76c2c85b97 [Generator] Add DRAIN span_name sanitizer (#6098)
* [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]>
2026-02-22 00:55:22 -08:00

58 lines
1.2 KiB
Go

package drain
type LogCluster struct {
id int
Size int
Tokens []string
Stringer func([]string) string
ParamString string
cache string
}
func (c *LogCluster) ingestTokens(tokens []string) {
if len(tokens) != len(c.Tokens) {
panic("attempt to create template from sequences with different token lengths")
}
for i := range tokens {
if tokens[i] != c.Tokens[i] && c.Tokens[i] != c.ParamString {
c.Tokens[i] = c.ParamString
c.cache = ""
}
}
c.Size++
}
func (c *LogCluster) tokenDistance(tokens []string) (float64, int) {
if len(c.Tokens) != len(tokens) {
panic("attempt to compare sequences with different token lengths")
}
similarTokens := 0
paramCount := 0
for i := range c.Tokens {
clusterToken := c.Tokens[i]
inputToken := tokens[i]
switch clusterToken {
case c.ParamString:
paramCount++
case inputToken:
similarTokens++
}
}
retVal := float64(similarTokens) / float64(len(c.Tokens))
return retVal, paramCount
}
func (c *LogCluster) String() string {
if c.cache != "" {
return c.cache
}
c.cache = c.Stringer(c.Tokens)
return c.cache
}
func (c *LogCluster) GetTokens() []string {
return c.Tokens
}