Skip to content

Commit 47bba7a

Browse files
authored
Moves away from strict Violation enum to open Violation based on Advice (#1038)
* Update weaver_checker to have more flexible violation deserialziation. * Fix live check to use new violation spec. * Last cleanups of Advice->Violation. * Fix clippy. * Fix spellcheck. * Update rendering templates for new generic violations. * Fix jinja filter. * Fix error diagnostic output. * Fix live check templates. * Rename Violation to PolicyFinding. Hide sub-mod in weaver-checker. * cargo fmt * First crack at updating docs. * Add changelog. * Fix spelling issues. * Update examples for now, will need to revisit to remove the old-school otel policies when we move to v2 schema.
1 parent 3899a9a commit 47bba7a

File tree

15 files changed

+534
-405
lines changed

15 files changed

+534
-405
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.
88
- Add support for V2 schema in `weaver check` ([#1016](https://github.com/open-telemetry/weaver/pull/1016) by @jsuereth)
99
- Add support for V2 schema in `emit` ([#1019](https://github.com/open-telemetry/weaver/pull/1019) by @jerbly)
1010
- Add support for V2 schema in `live-check` ([#1022](https://github.com/open-telemetry/weaver/pull/1022) by @jerbly)
11+
- 💥 BREAKING CHANGE 💥 `Violation` and `Advice` have been renamed
12+
to `PolicyFinding`. We now use the same structure between all
13+
rego policies in weaver. ([#1038](https://github.com/open-telemetry/weaver/pull/1038) by @jsuereth)
1114

1215
# [0.19.0] - 2025-11-04
1316

crates/weaver_checker/README.md

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [Policy Definition and Verification](#policy-definition-and-verification)
88
- [Usage](#usage)
99
- [Policy Examples](#policy-examples)
10-
- [Creating Rules for Violation Detection](#creating-rules-for-violation-detection)
10+
- [Creating Rules for Findings](#creating-rules-for-findings)
1111
- [Understanding the `deny` Rule](#understanding-the-deny-rule)
1212
- [Key Concepts for Rule Development](#key-concepts-for-rule-development)
1313
- [Step-by-Step Guide to Creating a New Rule](#step-by-step-guide-to-creating-a-new-rule)
@@ -61,8 +61,8 @@ by the Weaver tool during various phases of the development process.
6161

6262
The policy verification process involves:
6363
- Reading the semconv files of both the new and previous versions.
64-
- Applying Rego policies to these files to identify violations.
65-
- Displaying any detected policy violations, aiding in the resolution before
64+
- Applying Rego policies to these files to identify findings (can be `violation`, `informational` or `warning`).
65+
- Displaying any detected policy findings, aiding in the resolution before
6666
publication.
6767

6868
The following diagram illustrates the policy verification process:
@@ -255,88 +255,98 @@ groups:
255255
deprecated: true
256256
```
257257
258-
... will generate the following violations.
258+
... will generate the following findings.
259259
260260
```json
261261
[
262262
{
263263
"type": "semconv_attribute",
264-
"id": "attr_stability_deprecated",
265-
"category": "attribute",
266-
"group": "registry.network1",
267-
"attr": "protocol.name"
264+
"context": {
265+
"id": "attr_stability_deprecated",
266+
"category": "attribute",
267+
"group": "registry.network1",
268+
"attr": "protocol.name",
269+
},
270+
"message": "...",
271+
"level": "violation",
268272
},
269273
{
270-
"type": "semconv_attribute",
271-
"id": "attr_removed",
272-
"category": "schema_evolution",
273-
"group": "registry.network1",
274-
"attr": "protocol.name.3"
274+
"id": "semconv_attribute",
275+
"context": {
276+
"id": "attr_stability_deprecated",
277+
"category": "attribute",
278+
"group": "registry.network1",
279+
"attr": "protocol.name",
280+
},
281+
"message": "...",
282+
"level": "violation",
275283
},
276284
{
277-
"type": "semconv_attribute",
278-
"id": "registry_with_ref_attr",
279-
"category": "attribute_registry",
280-
"group": "registry.network1",
281-
"attr": "protocol.port"
285+
"id": "semconv_attribute",
286+
"context": {
287+
"id": "attr_stability_deprecated",
288+
"category": "attribute",
289+
"group": "registry.network1",
290+
"attr": "protocol.name",
291+
},
292+
"message": "...",
293+
"level": "violation",
282294
}
283295
]
284296
```
285297

286-
## Creating Rules for Violation Detection
298+
## Creating Rules for Findings
287299

288300
The Weaver Policy Engine allows for the dynamic creation and enforcement of
289301
rules to maintain the integrity and consistency of semantic conventions and
290302
telemetry schemas. By leveraging the Rego language, developers can specify
291-
policies that define what constitutes a violation within these domains. This
292-
section explains how to craft rules for detecting new violations, enhancing the
303+
policies that define what constitutes a finding within these domains. This
304+
section explains how to craft rules for detecting new finding, enhancing the
293305
engine's capability to safeguard the quality and coherence of semantic
294306
conventions and application telemetry schemas.
295307

296308
### Understanding the `deny` Rule
297309

298-
The `deny` rule serves as the cornerstone for defining policy violations. When
310+
The `deny` rule serves as the cornerstone for defining policy finding. When
299311
the conditions specified within a `deny` rule are met, it indicates a policy
300-
violation. Each `deny` rule must uniquely identify the violation it detects by
312+
finding. Each `deny` rule must uniquely identify the finding it detects by
301313
producing a descriptive message or a structured object that outlines the nature
302-
of the violation.
314+
of the finding.
303315

304316
### Key Concepts for Rule Development
305317

306-
- **Rule Name**: Rules detecting violations must be named `deny`. This is a
307-
convention chosen by the Weaver project to facilitate the use and management of
308-
these policy files.
309-
- **Violation Conditions**: The body of a `deny` rule contains one or more
310-
conditions that, when true, signal a violation. These conditions can range from
318+
- **Rule Name**: Rules detecting a finding (e.g. detecting issues or violations)
319+
must be named `deny`. This is a convention chosen by the Weaver project to
320+
facilitate the use and management of these policy files.
321+
- **Finding Conditions**: The body of a `deny` rule contains one or more
322+
conditions that, when true, signal a finding. These conditions can range from
311323
simple checks, like the presence of a deprecated attribute, to complex validations
312324
involving multiple components of the semantic conventions or telemetry schemas.
313-
- **Violation Message**: Upon detecting a violation, the rule should generate a
314-
message or an object that provides detailed information about the violation,
315-
including the type of violation, relevant identifiers (e.g., attribute or group
316-
ID), and a brief description of the issue.
325+
- **Finding Message**: Upon detecting a finding, the rule should generate a
326+
message or an object that provides detailed information about the finding,
327+
including an id, the severity level, a human readable description, and
328+
any other relevant context you would like to attach.
317329

318330
### Step-by-Step Guide to Creating a New Rule
319331

320-
1. **Identify the Violation**: Determine the specific condition or practice that
321-
should be flagged as a violation. This could be a new policy requirement, a best
332+
1. **Identify the Finding**: Determine the specific condition or practice that
333+
should be flagged as a finding. This could be a new policy requirement, a best
322334
practice, or an identified gap in the current policy enforcement.
323335

324336
2. **Define the Rule Conditions**: Craft a set of conditions that accurately
325-
capture the criteria for the violation. Utilize the Rego language to express
337+
capture the criteria for the finding. Utilize the Rego language to express
326338
these conditions, making use of variables, functions, and operators as necessary.
327339

328-
3. **Construct the Violation Output**: For defining the structure of the violation
329-
object, you can either reuse one of the already defined categories (i.e.,
330-
attr_registry_violation, attr_violation, schema_evolution_violation), or define
331-
a new one if the category of this violation has not already been defined.
340+
3. **Construct the Finding Output**: For defining the structure of the finding
341+
object.
332342

333343
4. **Implement the Rule in Rego**: Write the `deny` rule in Rego, encapsulating
334-
the conditions and violation output you've defined. Ensure the rule is clearly
344+
the conditions and finding output you've defined. Ensure the rule is clearly
335345
commented and documented to facilitate understanding and maintenance.
336346

337347
5. **Test the Rule**: Before integrating the new rule into the Weaver Policy
338348
Engine, test it with various input scenarios to ensure it accurately detects
339-
violations without producing false positives or negatives. A unit test
349+
finding without producing false positives or negatives. A unit test
340350
framework will be provided to facilitate this process in a future PR.
341351

342352
## Links

crates/weaver_checker/data/policies/otel_policies.rego

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ attr_exists_in_new_group(group_id, attr_id) if {
4848

4949
# Build an attribute registry violation
5050
attr_registry_violation(violation_id, group_id, attr_id) := violation if {
51+
# Uses legacy semconv attribute type.
5152
violation := {
5253
"id": violation_id,
5354
"type": "semconv_attribute",
@@ -59,6 +60,7 @@ attr_registry_violation(violation_id, group_id, attr_id) := violation if {
5960

6061
# Build an attribute violation
6162
attr_violation(violation_id, group_id, attr_id) := violation if {
63+
# Uses legacy semconv attribute type.
6264
violation := {
6365
"id": violation_id,
6466
"type": "semconv_attribute",
@@ -70,11 +72,15 @@ attr_violation(violation_id, group_id, attr_id) := violation if {
7072

7173
# Build a schema evolution violation
7274
schema_evolution_violation(violation_id, group_id, attr_id) := violation if {
75+
# Uses New policy violations
7376
violation := {
7477
"id": violation_id,
75-
"type": "semconv_attribute",
76-
"category": "schema_evolution",
77-
"group": group_id,
78-
"attr": attr_id,
78+
"context": {
79+
"id": "schema_evolution",
80+
"group": group_id,
81+
"attr": attr_id,
82+
},
83+
"message": "Schema evolution violation",
84+
"level": "violation",
7985
}
8086
}

0 commit comments

Comments
 (0)