Member collisions policies: id, value, const name#2456
Member collisions policies: id, value, const name#2456lmolkova wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
| startswith(group.id, "registry.") | ||
| attr := group.attributes[_] | ||
| member := attr.type.members[_] | ||
| not is_property_set(member, "deprecated") |
There was a problem hiding this comment.
I can never understand the difference between not obj.prop vs obj.prop == null vs this hack. For whatever reason this works and not obj.prop, obj.prop == null don't 😿
There was a problem hiding this comment.
Pull Request Overview
This PR extends the registry policy to catch duplicate definitions and adds tests for those collision scenarios.
- Adds Rego rules to enforce unique attribute names and unique member IDs, values (excluding deprecated), and constant names
- Introduces
to_const_nameandis_property_sethelpers and corresponding tests inregistry_test.rego
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| policies/registry.rego | New deny rules for duplicate attribute names and member ID/value/const-name collisions; helper functions added |
| policies_test/registry_test.rego | Tests covering member ID, member value (with/without deprecated), and const-name collision cases |
Comments suppressed due to low confidence (2)
policies_test/registry_test.rego:61
- [nitpick] We’ve added a rule to detect duplicate attribute names, but there’s no test covering this case. Please add a registry_test that defines the same attribute twice and asserts
before_resolution.denycatches it.
test_attribute_requirement_levels if {
policies/registry.rego:97
- The
attr.namefield is not defined on attributes. You should useattr.idor derive the full name viaget_attribute_name(attr, group).
name := attr.name
|
|
||
| # check that attribute is not defined or referenced more than once within the same group | ||
| deny contains attr_registry_violation(description, group.id, name) if { | ||
| group := input.groups[_] |
There was a problem hiding this comment.
The attribute-duplicate rule applies to every group. To match other member-collision rules, add a filter like startswith(group.id, "registry.") so non-registry groups aren’t inadvertently flagged.
| group := input.groups[_] | |
| group := input.groups[_] | |
| startswith(group.id, "registry.") |
|
replaced by #2477 |
Fixes #2448
Related to #2455
Blocked on open-telemetry/weaver#812