Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax collision detection policy to allow collisions between deprecated namespaces and attributes (and vice-versa) #1642

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions policies/attribute_name_collisions.rego
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import rego.v1
attribute_names := { obj |
group := input.groups[_];
attr := group.attributes[_];
obj := { "name": attr.name, "const_name": to_const_name(attr.name), "namespace_prefix": to_namespace_prefix(attr.name) }
obj := { "name": attr.name, "const_name": to_const_name(attr.name), "namespace_prefix": to_namespace_prefix(attr.name), "deprecated": is_property_set(attr, "deprecated") }
}

# check that attribute constant names do not collide
Expand All @@ -29,11 +29,17 @@ deny contains attr_registry_collision(description, name) if {
# check that attribute names do not collide with namespaces
deny contains attr_registry_collision(description, name) if {
some i

# ignore deprecated attributes
not attribute_names[i].deprecated

name := attribute_names[i].name
prefix := attribute_names[i].namespace_prefix
not excluded_namespace_collisions[name]

collisions := [other.name |
other := attribute_names[_]
not other.deprecated

other.name != name
startswith(other.name, prefix)
]
Expand Down Expand Up @@ -72,13 +78,15 @@ to_const_name(name) = const_name if {
const_name := replace(name, ".", "_")
}

# These lists contain exceptions for existing collisions that were introduced unintentionally.
is_property_set(obj, property) = true if {
obj[property] != null
} else = false

# This list contains 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
# For now we'll exclude existing collisions from the checks.
# ADDING NEW EXCEPTIONS IS NOT ALLOWED.

# DO NOT ADD ATTRIBUTES TO THIS LIST
excluded_const_collisions := {"messaging.client_id"}
# DO NOT ADD ATTRIBUTES TO THIS LIST
excluded_namespace_collisions := {"messaging.operation", "db.operation", "deployment.environment"}
12 changes: 12 additions & 0 deletions policies_test/attribute_name_collisions_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ test_fails_on_namespace_collision if {
]}
count(deny) == 1 with input as collision
}

test_does_not_fail_on_deprecated_namespace_collision if {
collision := {"groups": [
{"id": "test1", "attributes": [{"name": "test.namespace.id"}]},
{"id": "test2", "attributes": [{"name": "test.namespace", "deprecated": "replaced by foo.bar.baz"}]},

{"id": "test3", "attributes": [{"name": "another_test.namespace.id", "deprecated": "replaced by another_test.namespace"}]},
{"id": "test4", "attributes": [{"name": "another_test.namespace"}]},
]}
count(deny) == 0 with input as collision
}

Loading