Skip to content

Commit bfe6e1e

Browse files
authored
Add stability to network.interface.name and event fields, add temp policy check (#1781)
1 parent a5c879e commit bfe6e1e

File tree

7 files changed

+78
-10
lines changed

7 files changed

+78
-10
lines changed

model/device/events.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ groups:
3737
value: 'active'
3838
brief: >
3939
The app has become `active`. Associated with UIKit notification `applicationDidBecomeActive`.
40+
stability: development
4041
- id: inactive
4142
value: 'inactive'
4243
brief: >
4344
The app is now `inactive`. Associated with UIKit notification `applicationWillResignActive`.
45+
stability: development
4446
- id: background
4547
value: 'background'
4648
brief: >
4749
The app is now in the background.
4850
This value is associated with UIKit notification `applicationDidEnterBackground`.
51+
stability: development
4952
- id: foreground
5053
value: 'foreground'
5154
brief: >
5255
The app is now in the foreground.
5356
This value is associated with UIKit notification `applicationWillEnterForeground`.
57+
stability: development
5458
- id: terminate
5559
value: 'terminate'
5660
brief: >
5761
The app is about to terminate. Associated with UIKit notification `applicationWillTerminate`.
62+
stability: development
5863
- id: android.state
5964
stability: experimental
6065
requirement_level:
@@ -72,13 +77,16 @@ groups:
7277
brief: >
7378
Any time before Activity.onResume() or, if the app has no Activity, Context.startService()
7479
has been called in the app for the first time.
80+
stability: development
7581
- id: background
7682
value: 'background'
7783
brief: >
7884
Any time after Activity.onPause() or, if the app has no Activity,
7985
Context.stopService() has been called when the app was in the foreground state.
86+
stability: development
8087
- id: foreground
8188
value: 'foreground'
8289
brief: >
8390
Any time after Activity.onResume() or, if the app has no Activity,
8491
Context.startService() has been called when the app was in either the created or background states.
92+
stability: development

model/gen-ai/events.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ groups:
111111
- id: function
112112
value: 'function'
113113
brief: Function
114+
stability: development
114115
stability: experimental
115116
brief: >
116117
The type of the tool.
@@ -275,6 +276,7 @@ groups:
275276
- id: function
276277
value: 'function'
277278
brief: Function
279+
stability: development
278280
stability: experimental
279281
brief: >
280282
The type of the tool.

model/network/registry.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ groups:
236236
type: string
237237
brief: 'The network interface name.'
238238
examples: [ 'lo', 'eth0' ]
239+
stability: development
239240
- id: network.connection.state
240241
type:
241242
members:

policies/registry.rego

+19
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ deny contains attr_registry_violation(description, group.id, attr.id) if {
7070
description := sprintf("Attribute definition '%s' has requirement_level set to %s. Only attribute references can set requirement_level.", [attr.id, attr.requirement_level])
7171
}
7272

73+
# We require attribute definitions to have stability
74+
deny contains attr_registry_violation(description, group.id, attr.id) if {
75+
group := input.groups[_]
76+
attr := group.attributes[_]
77+
not attr.stability
78+
description := sprintf("Attribute definition '%s' does not contain stability field. All attribute definitions must include stability level.", [attr.id])
79+
}
80+
81+
# We require span, metrics, events, resources definitions to have stability
82+
deny contains attr_registry_violation(description, group.id, "") if {
83+
semconv_types := {"span", "metric", "event", "resource"}
84+
group := input.groups[_]
85+
86+
semconv_types[group.type] != null
87+
88+
not group.stability
89+
description := sprintf("Semconv group '%s' does not contain stability field. All semconv definitions must include stability level.", [group.id])
90+
}
91+
7392
get_attribute_name(attr, group) := name if {
7493
full_name := concat(".", [group.prefix, attr.id])
7594

policies_test/registry_test.rego

+40-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,55 @@ test_registry_attribute_groups if {
1111

1212
test_attribute_ids if {
1313
# This requires a prefix for use with opa, but weaver will fill in.
14-
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "not_registry", "prefix": "", "attributes": [{"id": "foo.bar"}]}]}
14+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "not_registry", "prefix": "", "attributes": [{"id": "foo.bar", "stability": "rc"}]}]}
1515
count(before_resolution.deny) == 0 with input as {"groups": [
16-
{"id": "registry.test", "prefix": "", "attributes": [{"id": "foo.bar"}]},
17-
{"id": "not_registry", "prefix": "", "attributes": [{"ref": "foo.bar"}]},
16+
{"id": "registry.test", "prefix": "", "attributes": [{"id": "foo.bar", "stability": "rc"}]},
17+
{"id": "not_registry", "prefix": "", "attributes": [{"ref": "foo.bar", "stability": "rc"}]},
1818
]}
1919
}
2020

21+
test_attribute_without_stability if {
22+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.text", "attributes": [{"id": "foo.bar"}]}]}
23+
count(before_resolution.deny) == 0 with input as {"groups": [
24+
{"id": "registry.test", "attributes": [{"id": "foo.bar", "stability": "alpha"}]},
25+
]}
26+
}
27+
28+
test_span_without_stability if {
29+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "span.group", "type": "span"}]}
30+
count(before_resolution.deny) == 0 with input as {"groups": [
31+
{"id": "span.group", "type": "span", "stability": "alpha"}]
32+
}
33+
}
34+
35+
test_event_without_stability if {
36+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "event.foo", "type": "event", "name": "foo"}]}
37+
count(before_resolution.deny) == 0 with input as {"groups": [
38+
{"id": "event.foo", "name": "foo", "type": "event", "stability": "alpha"}]
39+
}
40+
}
41+
42+
test_metric_without_stability if {
43+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "metric.foo", "type": "metric", "name": "foo"}]}
44+
count(before_resolution.deny) == 0 with input as {"groups": [
45+
{"id": "metric.foo", "name": "foo", "type": "metric", "stability": "development"}]
46+
}
47+
}
48+
49+
test_resource_without_stability if {
50+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "resource.foo", "type": "resource", "name": "foo"}]}
51+
count(before_resolution.deny) == 0 with input as {"groups": [
52+
{"id": "resource.foo", "name": "foo", "type": "resource", "stability": "stable"}]
53+
}
54+
}
55+
2156
test_attribute_refs if {
2257
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.foo", "attributes": [{"ref": "foo"}]}]}
2358
count(before_resolution.deny) == 0 with input as {"groups": [{"id": "not_registry", "attributes": [{"ref": "foo"}]}]}
2459
}
2560

2661
test_attribute_requirement_levels if {
27-
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.foo", "attributes": [{"id": "foo", "requirement_level": "required"}]}]}
28-
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.foo", "attributes": [{"id": "foo", "requirement_level": {"recommended": "if available"}}]}]}
62+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.foo", "attributes": [{"id": "foo", "requirement_level": "required", "stability": "rc"}]}]}
63+
count(before_resolution.deny) > 0 with input as {"groups": [{"id": "registry.foo", "attributes": [{"id": "foo", "requirement_level": {"recommended": "if available"}, "stability": "rc"}]}]}
2964
count(before_resolution.deny) == 0 with input as {"groups": [{"id": "not_registry", "attributes": [{"ref": "foo", "requirement_level": "required"}]}]}
3065
}

policies_test/yaml_schema_test.rego

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ test_fails_on_referenced_event_name_on_event if {
5252
event := [{ "id": "event.foo",
5353
"type": "event",
5454
"name": "foo",
55+
"stability": "rc",
5556
"attributes": [{"ref": "event.name"}]}]
5657
count(deny) == 1 with input as {"groups": event}
5758
}
@@ -101,22 +102,22 @@ test_fails_on_invalid_resource_id if {
101102
}
102103

103104
create_attribute_group(attr) = json if {
104-
json := [{"id": "yaml_schema.test", "attributes": [{"id": attr}]}]
105+
json := [{"id": "yaml_schema.test", "attributes": [{"id": attr, "stability": "rc"}]}]
105106
}
106107

107108
create_metric(name) = json if {
108109
id := sprintf("metric.%s", [name])
109-
json := [{"id": id, "type": "metric", "metric_name": name}]
110+
json := [{"id": id, "type": "metric", "metric_name": name, "stability": "rc"}]
110111
}
111112

112113
create_event(name) = json if {
113114
id := sprintf("event.%s", [name])
114-
json := [{"id": id, "type": "event", "name": name}]
115+
json := [{"id": id, "type": "event", "name": name, "stability": "rc"}]
115116
}
116117

117118
create_resource(name) = json if {
118119
id := sprintf("resource.%s", [name])
119-
json := [{"id": id, "type": "resource", "name": name}]
120+
json := [{"id": id, "type": "resource", "name": name, "stability": "rc"}]
120121
}
121122

122123
invalid_names := [

templates/registry/markdown/stability.j2

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{%- elif stability == "stable" %}![Stable](https://img.shields.io/badge/-stable-lightgreen)
55
{%- elif stability == "release_candidate" %}![Release Candidate](https://img.shields.io/badge/-rc-mediumorchid)
66
{%- elif stability == "deprecated" %}![Deprecated](https://img.shields.io/badge/-deprecated-red)
7-
{%- else %}![Experimental](https://img.shields.io/badge/-experimental-blue)
7+
{%- elif stability == "experimental" %}![Experimental](https://img.shields.io/badge/-experimental-blue)
8+
{%- elif stability == "development" %}![Experimental](https://img.shields.io/badge/-experimental-blue)
9+
{%- else %}{{ "Unknown stability." }}
810
{%- endif %}
911
{%- endmacro %}

0 commit comments

Comments
 (0)