Attempt to optimise attribute name collision checks. (#1328)

Co-authored-by: Liudmila Molkova <limolkova@microsoft.com>
This commit is contained in:
Josh Suereth 2024-08-19 11:05:56 -04:00 committed by GitHub
parent 9e7ce953e9
commit f7d30b1755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 16 deletions

View File

@ -1,25 +1,42 @@
package after_resolution
deny[attr_registry_collision(description, name)] {
names := attr_names_except(excluded_const_collisions)
name := names[_]
const_name := to_const_name(name)
collisions:= { n | n := attr_names_except(excluded_const_collisions)[_]; n != name; to_const_name(n) == const_name }
count(collisions) > 0
# Data structures to make checking things faster.
attribute_names := { data |
group := input.groups[_]
attr := group.attributes[_]
data := { "name": attr.name, "const_name": to_const_name(attr.name), "namespace_prefix": to_namespace_prefix(attr.name) }
}
deny[attr_registry_collision(description, name)] {
some i
name := attribute_names[i].name
const_name := attribute_names[i].const_name
not excluded_const_collisions[name]
collisions := [other.name |
other := attribute_names[_]
other.name != name
other.const_name == const_name
not excluded_const_collisions[other.name]
]
count(collisions) > 0
# TODO (https://github.com/open-telemetry/weaver/issues/279): provide other violation properties once weaver supports it.
description := sprintf("Attribute '%s' has the same constant name '%s' as '%s'.", [name, const_name, collisions])
}
deny[attr_registry_collision(description, name)] {
names := attr_names_except(excluded_namespace_collisions)
name := names[_]
collisions:= { n | n := input.groups[_].attributes[_].name; startswith(n, to_namespace_prefix(name)) }
some i
name := attribute_names[i].name
prefix := attribute_names[i].namespace_prefix
not excluded_namespace_collisions[name]
collisions := [other.name |
other := attribute_names[_]
other.name != name
startswith(other.name, prefix)
]
count(collisions) > 0
# TODO (https://github.com/open-telemetry/weaver/issues/279): provide other violation properties once weaver supports it.
description := sprintf("Attribute '%s' name is used as a namespace in the following attributes '%s'.", [name, collisions])
description := sprintf("Attribute '%s' is used as a namespace in '%s'.", [name, collisions])
}
attr_registry_collision(description, attr_name) = violation {
@ -40,10 +57,6 @@ to_const_name(name) = const_name {
const_name := replace(name, ".", "_")
}
attr_names_except(excluded) = names {
names := { n | n := input.groups[_].attributes[_].name } - excluded
}
# These lists contain exceptions for existing collisions that were introduced unintentionally.
# We'll have a way to specify how collision resolution happens in the schema -
# see phase 2 in https://github.com/open-telemetry/semantic-conventions/issues/1118#issuecomment-2173803006