Skip to content

Commit

Permalink
Remove constraints (open-telemetry#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova authored May 7, 2024
1 parent 63502e6 commit 14261dd
Show file tree
Hide file tree
Showing 55 changed files with 39 additions and 848 deletions.
13 changes: 6 additions & 7 deletions semantic-conventions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ for which we want to generate the table.
After `{semantic_convention_id}`, optional parameters enclosed in parentheses can be added to customize the output:

- `tag={tag}`: prints only the attributes that have `{tag}` as a tag;
- `full`: prints attributes and constraints inherited from the parent semantic conventions or from included ones;
- `full`: prints attributes inherited from the parent semantic conventions or from included ones;
- `ref`: prints attributes that are referenced from another semantic convention;
- `remove_constraint`: does not print additional constraints of the semantic convention.

By default markdown tables are rendered with stability badges (like ![Stable](https://img.shields.io/badge/-stable-lightgreen) or ![Experimental](https://img.shields.io/badge/-experimental-blue)) which can be disabled with `--md-disable-stable-badge`, `--md-disable-experimental-badge`, `--md-disable-deprecated-badge`.
When badges are disabled, the stability column contains plain text representation of stability or deprecation status.
Expand All @@ -74,18 +73,18 @@ When badges are disabled, the stability column contains plain text representatio

These examples assume that a semantic convention with the id `http.server` extends another semantic convention with the id `http`.

`<!-- semconv http.server -->` will print only the attributes and constraints of the `http.server` semantic
`<!-- semconv http.server -->` will print only the attributes of the `http.server` semantic
convention.

`<!-- semconv http.server(full) -->` will print the attributes and constraints of the `http` semantic
convention and also the attributes and constraints of the `http.server` semantic convention.
`<!-- semconv http.server(full) -->` will print the attributes of the `http` semantic
convention and also the attributes of the `http.server` semantic convention.

`<!-- semconv http.server() -->` is equivalent to `<!-- semconv http.server -->`.

`<!-- semconv http.server(tag=network) -->` will print the constraints and attributes of the `http.server` semantic
`<!-- semconv http.server(tag=network) -->` will print the attributes of the `http.server` semantic
convention that have the tag `network`.

`<!-- semconv http.server(tag=network, full) -->` will print the constraints and attributes of both `http` and `http.server`
`<!-- semconv http.server(tag=network, full) -->` will print the attributes of both `http` and `http.server`
semantic conventions that have the tag `network`.

`<!-- semconv metric.http.server.active_requests(metric_table) -->` will print a table describing a single metric
Expand Down
46 changes: 0 additions & 46 deletions semantic-conventions/semconv.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,6 @@
},
"description": "list of attributes that belong to the semconv"
},
"constraints": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"additionalProperties": false,
"required": [
"any_of"
],
"properties": {
"any_of": {
"type": "array",
"description": " accepts a list of sequences. Each sequence contains a list of attribute ids that are required. any_of enforces that all attributes of at least one of the sequences are set.",
"items": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
}
}
}
},
{
"type": "object",
"additionalProperties": false,
"required": [
"include"
],
"properties": {
"include": {
"type": "string",
"description": "accepts a semantic conventions id. It includes as part of this semantic convention all constraints and required attributes that are not already defined in the current semantic convention."
}
}
}
]
}
},
"display_name": {
"type": "string",
"description": "the display name / title of the attribute group."
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from ruamel.yaml import YAML

from opentelemetry.semconv.model.constraints import AnyOf, Include, parse_constraints
from opentelemetry.semconv.model.exceptions import ValidationError
from opentelemetry.semconv.model.semantic_attribute import (
AttributeType,
Expand Down Expand Up @@ -109,7 +108,6 @@ class BaseSemanticConvention(ValidatableYamlNode):
"stability",
"extends",
"attributes",
"constraints",
"deprecated",
"display_name",
)
Expand Down Expand Up @@ -163,9 +161,6 @@ def __init__(self, group, validation_ctx):
)
self.extends = group.get("extends", "").strip()
self.events = group.get("events", ())
self.constraints = parse_constraints(
group.get("constraints", ()), validation_ctx
)
self.attrs_by_name = SemanticAttribute.parse(
self.prefix, group.get("attributes"), validation_ctx
)
Expand All @@ -179,15 +174,6 @@ def contains_attribute(self, attr: "SemanticAttribute"):
return True
return False

def has_attribute_constraint(self, attr):
return any(
attribute.equivalent_to(attr)
for constraint in self.constraints
if isinstance(constraint, AnyOf)
for attr_list in constraint.choice_list_attributes
for attribute in attr_list
)

def validate_values(self):
super().validate_values()
if self.prefix:
Expand Down Expand Up @@ -347,17 +333,13 @@ def finish(self):
if index > 0:
self.debug = False
for semconv in self.models.values():
# Ref first, extends and includes after!
fixpoint_ref = self.resolve_ref(semconv)
fixpoint_inc = self.resolve_include(semconv)
fixpoint = fixpoint and fixpoint_ref and fixpoint_inc
fixpoint = fixpoint and fixpoint_ref
index += 1
self.debug = tmp_debug
# After we resolve any local dependency, we can resolve parent/child relationship
self._populate_extends()
# From string containing attribute ids to SemanticAttribute objects
self._populate_anyof_attributes()
# From strings containing Semantic Conventions for Events ids to SemanticConvention objects
self._populate_events()

def _populate_extends(self):
Expand Down Expand Up @@ -397,15 +379,9 @@ def _populate_extends_single(self, semconv, unprocessed):
parent_extended = self.models.get(extended.extends)
self._populate_extends_single(parent_extended, unprocessed)

# inherit prefix and constraints
# inherit prefix
if not semconv.prefix:
semconv.prefix = extended.prefix
# Constraints
for constraint in extended.constraints:
if constraint not in semconv.constraints and isinstance(
constraint, AnyOf
):
semconv.constraints += (constraint.inherit_anyof(),)
# Attributes
parent_attributes = {}
for ext_attr in extended.attributes_and_templates:
Expand All @@ -417,27 +393,6 @@ def _populate_extends_single(self, semconv, unprocessed):
# delete from remaining semantic conventions to process
del unprocessed[semconv.semconv_id]

def _populate_anyof_attributes(self):
any_of: AnyOf
for semconv in self.models.values():
for any_of in semconv.constraints:
if not isinstance(any_of, AnyOf):
continue
for index, attr_ids in enumerate(any_of.choice_list_ids):
constraint_attrs = []
for attr_id in attr_ids:
ref_attr = self._lookup_attribute(attr_id)
if ref_attr is None:
self.validation_ctx.raise_or_warn(
any_of._yaml_src_position[index],
f"Any_of attribute '{attr_id}' of semantic "
"convention {semconv.semconv_id} does not exist!",
attr_id,
)
constraint_attrs.append(ref_attr)
if constraint_attrs:
any_of.add_attributes(constraint_attrs)

def _populate_events(self):
for semconv in self.models.values():
events: typing.List[EventSemanticConvention] = []
Expand Down Expand Up @@ -505,48 +460,6 @@ def _merge_attribute(self, child, parent):
child.attr_id = parent.attr_id
return child

def resolve_include(self, semconv):
fixpoint_inc = True
for constraint in semconv.constraints:
if isinstance(constraint, Include):
include_semconv = self.models.get(constraint.semconv_id)
# include required attributes and constraints
if include_semconv is None:
self.validation_ctx.raise_or_warn(
semconv._position,
f"Semantic Convention {semconv.semconv_id} includes "
"{constraint.semconv_id} but the latter cannot be found!",
semconv.semconv_id,
)
# We resolve the parent/child relationship of the included semantic convention, if any
self._populate_extends_single(
include_semconv, {include_semconv.semconv_id: include_semconv}
)
attr: SemanticAttribute
for attr in include_semconv.attributes_and_templates:
if semconv.contains_attribute(attr):
if self.debug:
print(
f"[Includes] {semconv.semconv_id} already contains attribute {attr}"
)
continue
# There are changes
fixpoint_inc = False
semconv.attrs_by_name[attr.fqn] = attr.import_attribute()
for inc_constraint in include_semconv.constraints:
if (
isinstance(inc_constraint, Include)
or inc_constraint in semconv.constraints
):
# We do not include "include" constraint or the constraint was already imported
continue
# We know the type of the constraint
inc_constraint: AnyOf
# There are changes
fixpoint_inc = False
semconv.constraints += (inc_constraint.inherit_anyof(),)
return fixpoint_inc

def _lookup_attribute(self, attr_id: str) -> Union[SemanticAttribute, None]:
return next(
(
Expand Down
Loading

0 comments on commit 14261dd

Please sign in to comment.