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

(chore) Move backwards compatibility checks to weaver. #1327

Merged
merged 22 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a5f6389
Initial cut at backwards compatibility check moving to weaver.
jsuereth Aug 7, 2024
737df29
Add policies to enforce attribute/enum backwards compatibility.
jsuereth Aug 8, 2024
f3acf8c
Add some metric policies.
jsuereth Aug 8, 2024
d1f56be
Finish implementing policies.
jsuereth Aug 8, 2024
f7cb36a
Update makefile to only have one policy check.
jsuereth Aug 8, 2024
f20ec2c
Fix nits.
jsuereth Aug 8, 2024
0a141fc
Merge branch 'main' into wip-backwards-compat-weaver
jsuereth Aug 8, 2024
6f1ed90
Update docs.
jsuereth Aug 8, 2024
9b77e46
Move to using policies directory.
jsuereth Aug 9, 2024
ba366a9
Add old backwards compat checks back.
jsuereth Aug 9, 2024
1a77174
Fix lint issues.
jsuereth Aug 9, 2024
5fa1fbd
Merge main - Fix test policies to not conflict.
jsuereth Aug 16, 2024
ac39d30
Add some tests for stability checks.
jsuereth Aug 16, 2024
2a18e5a
Added tests.
jsuereth Aug 16, 2024
f0f8508
Add policy unit tests to github actions.
jsuereth Aug 16, 2024
9ea051b
Merge branch 'main' into wip-backwards-compat-weaver
lmolkova Aug 19, 2024
f55a27d
Update attribute name rules to v1 syntax and fix shadowing issue.
jsuereth Aug 19, 2024
a2e8719
Minor formatting.
jsuereth Aug 19, 2024
3d358b1
Merge branch 'main' into wip-backwards-compat-weaver
jsuereth Aug 19, 2024
fa633ba
Merge branch 'main' into wip-backwards-compat-weaver
jsuereth Aug 19, 2024
293d472
Merge branch 'main' into wip-backwards-compat-weaver
jsuereth Aug 19, 2024
395ec0c
Merge branch 'main' into wip-backwards-compat-weaver
jsuereth Aug 20, 2024
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
22 changes: 15 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ jobs:
make attribute-registry-generation
git diff --exit-code './docs/attributes-registry/*.md' || (echo 'Attribute registry markdown is out of date, please run "make attribute-registry-generation" and commit the changes in this PR.' && exit 1)

semantic-conventions-compatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: verify semantic convention compatibility with latest released version
run: make compatibility-check

schemas-check:
runs-on: ubuntu-latest
steps:
Expand All @@ -115,3 +108,18 @@ jobs:
- uses: actions/checkout@v1
- name: verify semantic conventions yaml definitions
run: make check-policies

polices-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: verify semantic conventions yaml definitions
run: make test-policies

# TODO: Remove this once policies-check is the only enforcement on github.
semantic-conventions-compatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: verify semantic convention compatibility with latest released version
run: make compatibility-check
75 changes: 37 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ CHLOGGEN_CONFIG := .chloggen/config.yaml
# see https://github.com/open-telemetry/build-tools/releases for semconvgen updates
# Keep links in model/README.md and .vscode/settings.json in sync!
SEMCONVGEN_VERSION=0.25.0
WEAVER_VERSION=0.7.0

# see https://github.com/open-telemetry/weaver/releases for weaver updates
WEAVER_VERSION=0.8.0

OPA_POLICY_AGENT_VERSION=0.67.1

# From where to resolve the containers (e.g. "otel/weaver").
CONTAINER_REPOSITORY=docker.io
Expand Down Expand Up @@ -111,20 +115,6 @@ install-yamllint:
yamllint:
yamllint .

# Check semantic convention policies on YAML files
.PHONY: check-policies
check-policies:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/policies:/policies -v $(PWD)/templates:/templates \
otel/weaver:${WEAVER_VERSION} registry check \
--registry=/source \
--diagnostic-format=ansi \
--policy=/policies/registry.rego

# Test rego policies
.PHONY: test-policies
test-policies:
docker run --rm -v $(PWD)/policies:/policies openpolicyagent/opa:0.67.1 test --explain fails /policies

# Generate markdown tables from YAML definitions
.PHONY: table-generation
table-generation:
Expand Down Expand Up @@ -159,26 +149,6 @@ table-check:
--dry-run \
/spec


# A previous iteration of calculating "LATEST_RELEASED_SEMCONV_VERSION"
# relied on "git describe". However, that approach does not work with
# light-weight developer forks/branches that haven't synced tags. Hence the
# more complex implementation of this using "git ls-remote".
#
# The output of "git ls-remote" looks something like this:
#
# e531541025992b68177a68b87628c5dc75c4f7d9 refs/tags/v1.21.0
# cadfe53949266d33476b15ca52c92f682600a29c refs/tags/v1.22.0
# ...
#
# .. which is why some additional processing is required to extract the
# latest version number and strip off the "v" prefix.
LATEST_RELEASED_SEMCONV_VERSION := $(shell git ls-remote --tags https://github.com/open-telemetry/semantic-conventions.git | cut -f 2 | sort --reverse | head -n 1 | tr '/' ' ' | cut -d ' ' -f 3 | $(SED) 's/v//g')
.PHONY: compatibility-check
compatibility-check:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \
$(SEMCONVGEN_CONTAINER) -f /source compatibility --previous-version $(LATEST_RELEASED_SEMCONV_VERSION)

.PHONY: schema-check
schema-check:
$(TOOLS_DIR)/schema_check.sh
Expand Down Expand Up @@ -234,11 +204,40 @@ chlog-update: $(CHLOGGEN)
generate-gh-issue-templates:
$(TOOLS_DIR)/scripts/update-issue-template-areas.sh

# A previous iteration of calculating "LATEST_RELEASED_SEMCONV_VERSION"
# relied on "git describe". However, that approach does not work with
# light-weight developer forks/branches that haven't synced tags. Hence the
# more complex implementation of this using "git ls-remote".
#
# The output of "git ls-remote" looks something like this:
#
# e531541025992b68177a68b87628c5dc75c4f7d9 refs/tags/v1.21.0
# cadfe53949266d33476b15ca52c92f682600a29c refs/tags/v1.22.0
# ...
#
# .. which is why some additional processing is required to extract the
# latest version number and strip off the "v" prefix.
LATEST_RELEASED_SEMCONV_VERSION := $(shell git ls-remote --tags https://github.com/open-telemetry/semantic-conventions.git | cut -f 2 | sort --reverse | head -n 1 | tr '/' ' ' | cut -d ' ' -f 3 | $(SED) 's/v//g')
.PHONY: check-policies
check-policies:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/policies:/policies \
otel/weaver:${WEAVER_VERSION} registry check \
--registry=/source \
--policy=/policies/registry.rego \
--policy=/policies/attribute_name_collisions.rego \
--policy=/policies/yaml_schema.rego
--baseline-registry=https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v$(LATEST_RELEASED_SEMCONV_VERSION).zip[model] \
--policy=/policies

# Test rego policies
.PHONY: test-policies
test-policies:
docker run --rm -v $(PWD)/policies:/policies -v $(PWD)/policies_test:/policies_test \
openpolicyagent/opa:${OPA_POLICY_AGENT_VERSION} test \
--explain fails \
/policies \
/policies_test

# TODO: This is now duplicative with weaver policy checks. We can remove
# once github action requirements are updated.
.PHONY: compatibility-check
compatibility-check:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \
$(SEMCONVGEN_CONTAINER) -f /source compatibility --previous-version $(LATEST_RELEASED_SEMCONV_VERSION)
20 changes: 11 additions & 9 deletions policies/attribute_name_collisions.rego
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package after_resolution

import rego.v1

# 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) }
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) }
}


deny[attr_registry_collision(description, name)] {
deny contains attr_registry_collision(description, name) if {
some i
name := attribute_names[i].name
const_name := attribute_names[i].const_name
Expand All @@ -24,7 +26,7 @@ deny[attr_registry_collision(description, name)] {
description := sprintf("Attribute '%s' has the same constant name '%s' as '%s'.", [name, const_name, collisions])
}

deny[attr_registry_collision(description, name)] {
deny contains attr_registry_collision(description, name) if {
some i
name := attribute_names[i].name
prefix := attribute_names[i].namespace_prefix
Expand All @@ -39,7 +41,7 @@ deny[attr_registry_collision(description, name)] {
description := sprintf("Attribute '%s' is used as a namespace in '%s'.", [name, collisions])
}

attr_registry_collision(description, attr_name) = violation {
attr_registry_collision(description, attr_name) = violation if {
violation := {
"id": description,
"type": "semconv_attribute",
Expand All @@ -49,11 +51,11 @@ attr_registry_collision(description, attr_name) = violation {
}
}

to_namespace_prefix(name) = namespace {
to_namespace_prefix(name) = namespace if {
namespace := concat("", [name, "."])
}

to_const_name(name) = const_name {
to_const_name(name) = const_name if {
const_name := replace(name, ".", "_")
}

Expand Down
Loading
Loading