You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +02:00
attribute: preallocate map in NewAllowKeysFilter and NewDenyKeysFilter (#6455)
preallocate map in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid necessary allocations
This commit is contained in:
@@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`.
|
- ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`.
|
||||||
This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores.
|
This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores.
|
||||||
This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433)
|
This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433)
|
||||||
|
- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid unnecessary allocations in `go.opentelemetry.io/otel/attribute`. (#6455)
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func NewAllowKeysFilter(keys ...Key) Filter {
|
|||||||
return func(kv KeyValue) bool { return false }
|
return func(kv KeyValue) bool { return false }
|
||||||
}
|
}
|
||||||
|
|
||||||
allowed := make(map[Key]struct{})
|
allowed := make(map[Key]struct{}, len(keys))
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
allowed[k] = struct{}{}
|
allowed[k] = struct{}{}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ func NewDenyKeysFilter(keys ...Key) Filter {
|
|||||||
return func(kv KeyValue) bool { return true }
|
return func(kv KeyValue) bool { return true }
|
||||||
}
|
}
|
||||||
|
|
||||||
forbid := make(map[Key]struct{})
|
forbid := make(map[Key]struct{}, len(keys))
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
forbid[k] = struct{}{}
|
forbid[k] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user