From 6e01a75a34e758e4c3e41e98ce73580430910bac Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Fri, 29 Mar 2024 15:39:06 -0700 Subject: [PATCH] remove unused Units, Scope, and MetricGroup conventions --- semantic-conventions/CHANGELOG.md | 3 ++ semantic-conventions/semconv.schema.json | 12 ----- .../semconv/model/semantic_convention.py | 28 +--------- .../semconv/templating/markdown/__init__.py | 4 -- .../tests/data/jinja/metrics/expected.java | 23 --------- .../expected_trim_whitespace_enabled.java | 31 +++++------ .../tests/data/jinja/metrics/units_template | 11 ---- .../units_template_trim_whitespace_enabled | 13 ----- .../data/markdown/metrics_unit/expected.md | 10 ---- .../tests/data/markdown/metrics_unit/input.md | 4 -- .../src/tests/data/markdown/scope/expected.md | 7 --- .../src/tests/data/markdown/scope/input.md | 4 -- .../src/tests/data/markdown/scope/scope.yaml | 14 ----- .../src/tests/data/yaml/metrics.yaml | 2 +- .../src/tests/data/yaml/metrics/units.yaml | 14 ----- .../metrics/units_bad_with_attributes.yaml | 12 ----- .../src/tests/data/yaml/scope.yaml | 14 ----- .../tests/semconv/model/test_correct_parse.py | 18 ------- .../model/test_semantic_convention_units.py | 51 ------------------- .../src/tests/semconv/templating/test_code.py | 23 ++------- .../tests/semconv/templating/test_markdown.py | 6 --- semantic-conventions/syntax.md | 2 - 22 files changed, 22 insertions(+), 284 deletions(-) delete mode 100644 semantic-conventions/src/tests/data/jinja/metrics/expected.java delete mode 100644 semantic-conventions/src/tests/data/jinja/metrics/units_template delete mode 100644 semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled delete mode 100644 semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md delete mode 100644 semantic-conventions/src/tests/data/markdown/metrics_unit/input.md delete mode 100644 semantic-conventions/src/tests/data/markdown/scope/expected.md delete mode 100644 semantic-conventions/src/tests/data/markdown/scope/input.md delete mode 100644 semantic-conventions/src/tests/data/markdown/scope/scope.yaml delete mode 100644 semantic-conventions/src/tests/data/yaml/metrics/units.yaml delete mode 100644 semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml delete mode 100644 semantic-conventions/src/tests/data/yaml/scope.yaml delete mode 100644 semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py diff --git a/semantic-conventions/CHANGELOG.md b/semantic-conventions/CHANGELOG.md index 1c48e69a..b1e85fb5 100644 --- a/semantic-conventions/CHANGELOG.md +++ b/semantic-conventions/CHANGELOG.md @@ -4,6 +4,9 @@ Please update the changelog as part of any significant pull request. ## Unreleased +- BREAKING: Remove unused semantic convention types: `UnitSemanticConvention`, `MetricGroupSemanticConvention`, `ScopeSemanticConvention` + ([#TODO](https://github.com/open-telemetry/build-tools/pull/TODO)) + ## 0.24.0 - BREAKING: Add `stability` (required) and `deprecated` (optional) properties to `EnumMember` diff --git a/semantic-conventions/semconv.schema.json b/semantic-conventions/semconv.schema.json index 0e3a5050..9d862bd2 100644 --- a/semantic-conventions/semconv.schema.json +++ b/semantic-conventions/semconv.schema.json @@ -54,9 +54,7 @@ "span", "resource", "metric", - "metric_group", "event", - "scope", "attribute_group" ], "description": "The (signal) type of the semantic convention" @@ -169,16 +167,6 @@ {"required": ["name"]} ] }, - "MetricGroupSemanticConvention": { - "allOf": [{ "$ref": "#/definitions/SemanticConventionBase" }], - "required": ["type"], - "properties": { - "type": { - "type": "string", - "const": "metric_group" - } - } - }, "MetricSemanticConvention": { "allOf": [{ "$ref": "#/definitions/SemanticConventionBase" }], "required": [ diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py index 537e335a..3a317be7 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py @@ -198,10 +198,6 @@ class ResourceSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "resource" -class ScopeSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "scope" - - class AttributeGroupConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "attribute_group" @@ -239,26 +235,7 @@ def __init__(self, group, validation_ctx): ) -class UnitSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "units" - - allowed_keys = ( # We completely override base semantic keys here. - "id", - "type", - "brief", - "members", - ) - - def __init__(self, group, validation_ctx): - super().__init__(group, validation_ctx) - self.members = UnitMember.parse(group.get("members"), validation_ctx) - - -class MetricGroupSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "metric_group" - - -class MetricSemanticConvention(MetricGroupSemanticConvention): +class MetricSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "metric" allowed_keys: Tuple[str, ...] = BaseSemanticConvention.allowed_keys + ( @@ -600,10 +577,7 @@ def attribute_templates(self): SpanSemanticConvention, ResourceSemanticConvention, EventSemanticConvention, - MetricGroupSemanticConvention, MetricSemanticConvention, - UnitSemanticConvention, - ScopeSemanticConvention, AttributeGroupConvention, ) } diff --git a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py index 360aa29d..c0511821 100644 --- a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py +++ b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py @@ -34,7 +34,6 @@ EventSemanticConvention, MetricSemanticConvention, SemanticConventionSet, - UnitSemanticConvention, ) from opentelemetry.semconv.model.utils import ID_RE from opentelemetry.semconv.templating.markdown.options import MarkdownOptions @@ -531,9 +530,6 @@ def _render_group(self, semconv, parameters, output): self.to_markdown_constraint(cnst, output) self.to_markdown_enum(output) - if isinstance(semconv, UnitSemanticConvention): - self.to_markdown_unit_table(semconv.members, output) - output.write("") def _render_stability( diff --git a/semantic-conventions/src/tests/data/jinja/metrics/expected.java b/semantic-conventions/src/tests/data/jinja/metrics/expected.java deleted file mode 100644 index 46ec3069..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/expected.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { - - /** - * Use this unit for Metric Instruments recording values - * representing fraction of a total. - **/ - public static final String PERCENT = "%"; - - /** - * Use this unit for Metric Instruments recording values - * representing time. - **/ - public static final String NANOSECOND = "NS"; - - /** - * Use this unit for Metric Instruments recording values - * representing connections. - **/ - public static final String CONNECTIONS = "{connections}"; - -} \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java b/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java index 4b4186ba..1bd77d9d 100644 --- a/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java +++ b/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java @@ -1,22 +1,19 @@ package io.opentelemetry.instrumentation.api.metric; -class Units { - - /** - * Use this unit for Metric Instruments recording values - * representing fraction of a total. - **/ - public static final String PERCENT = "%"; - +class AllMetrics { /** - * Use this unit for Metric Instruments recording values - * representing time. - **/ - public static final String NANOSECOND = "NS"; + * first metric description + * Unit: {one} + * Instrument: counter + * Experimental: False + */ + public static final String FIRST_METRIC = "first.metric"; /** - * Use this unit for Metric Instruments recording values - * representing connections. - **/ - public static final String CONNECTIONS = "{connections}"; -} + * second metric description + * Unit: s + * Instrument: histogram + * Experimental: True + */ + public static final String SECOND_GROUP_METRIC = "second_group.metric"; +} \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/jinja/metrics/units_template b/semantic-conventions/src/tests/data/jinja/metrics/units_template deleted file mode 100644 index 47831ffa..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/units_template +++ /dev/null @@ -1,11 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { -{% for member in semconvs['units'].members.values() %}{% set constant_name = member.id.upper() %} - /** - * Use this unit for Metric Instruments recording values - * representing {{member.brief}}. - **/ - public static final String {{constant_name}} = "{{member.value}}"; -{% endfor %} -} diff --git a/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled b/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled deleted file mode 100644 index c38ea68e..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled +++ /dev/null @@ -1,13 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { -{% for member in semconvs['units'].members.values() %}{% set constant_name = member.id.upper() %} - - /** - * Use this unit for Metric Instruments recording values - * representing {{member.brief}}. - **/ - public static final String {{constant_name}} = "{{member.value}}"; -{% endfor %} -} - diff --git a/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md b/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md deleted file mode 100644 index 3d1ab3af..00000000 --- a/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md +++ /dev/null @@ -1,10 +0,0 @@ -# Units - - - -| Name | Kind of Quantity | Unit String | -| ------------| ---------------- | ----------- | -| percent | fraction of a total | `%` | -| nanosecond | time | `NS` | -| connections | connections | `{connections}` | - diff --git a/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md b/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md deleted file mode 100644 index 75c93676..00000000 --- a/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md +++ /dev/null @@ -1,4 +0,0 @@ -# Units - - - diff --git a/semantic-conventions/src/tests/data/markdown/scope/expected.md b/semantic-conventions/src/tests/data/markdown/scope/expected.md deleted file mode 100644 index 29209024..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/expected.md +++ /dev/null @@ -1,7 +0,0 @@ -# Instrumentation Scope Semantic Conventions - - -| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability | -|---|---|---|---|---|---| -| `short_name` | string | The single-word name for the instrumentation scope. | `mylibrary` | `Recommended` | Experimental | - diff --git a/semantic-conventions/src/tests/data/markdown/scope/input.md b/semantic-conventions/src/tests/data/markdown/scope/input.md deleted file mode 100644 index 94120116..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/input.md +++ /dev/null @@ -1,4 +0,0 @@ -# Instrumentation Scope Semantic Conventions - - - diff --git a/semantic-conventions/src/tests/data/markdown/scope/scope.yaml b/semantic-conventions/src/tests/data/markdown/scope/scope.yaml deleted file mode 100644 index ab0c8ce0..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/scope.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: scope - prefix: "" - type: scope - brief: > - Instrumentation Scope attributes - attributes: - - id: short_name - stability: experimental - type: string - requirement_level: recommended - brief: > - The single-word name for the instrumentation scope. - examples: ['mylibrary'] \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/yaml/metrics.yaml b/semantic-conventions/src/tests/data/yaml/metrics.yaml index 9ff2e70f..9ef78257 100644 --- a/semantic-conventions/src/tests/data/yaml/metrics.yaml +++ b/semantic-conventions/src/tests/data/yaml/metrics.yaml @@ -1,7 +1,7 @@ groups: - id: metric.foo prefix: bar - type: metric_group + type: attribute_group stability: experimental brief: "This document defines foo." note: > diff --git a/semantic-conventions/src/tests/data/yaml/metrics/units.yaml b/semantic-conventions/src/tests/data/yaml/metrics/units.yaml deleted file mode 100644 index cd5d189e..00000000 --- a/semantic-conventions/src/tests/data/yaml/metrics/units.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: units - type: units - brief: Specification of commonly used units. - members: - - id: percent - brief: fraction of a total - value: "%" - - id: nanosecond - brief: time - value: NS - - id: connections - brief: connections - value: "{connections}" diff --git a/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml b/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml deleted file mode 100644 index 1a5b3b46..00000000 --- a/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml +++ /dev/null @@ -1,12 +0,0 @@ -groups: - - id: units - type: units - brief: Specification of commonly used units. - members: - - id: percent - brief: fraction of a total - value: "%" - attributes: - - id: foo - brief: bar - type: int diff --git a/semantic-conventions/src/tests/data/yaml/scope.yaml b/semantic-conventions/src/tests/data/yaml/scope.yaml deleted file mode 100644 index a9bc8c36..00000000 --- a/semantic-conventions/src/tests/data/yaml/scope.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: scope-id - prefix: "" - type: scope - brief: > - Instrumentation Scope attributes - attributes: - - id: short_name - stability: experimental - type: string - requirement_level: recommended - brief: > - The single-word name for the instrumentation scope. - examples: ['mylibrary'] \ No newline at end of file diff --git a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py index 51ef2112..3cc6d473 100644 --- a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py +++ b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py @@ -790,24 +790,6 @@ def semantic_convention_check(self, s, expected): self.assertEqual(expected["n_constraints"], len(s.constraints)) self.assertEqual(expected["attributes"], [a.fqn for a in s.attributes]) - def test_scope_attribute(self): - semconv = SemanticConventionSet(debug=False) - semconv.parse(self.load_file("yaml/scope.yaml")) - self.assertEqual(len(semconv.models), 1) - - expected = { - "id": "scope-id", - "prefix": "", - "type": "scope", - "extends": "", - "brief": "Instrumentation Scope attributes", - "n_constraints": 0, - "attributes": [ - "short_name", - ], - } - self.semantic_convention_check(list(semconv.models.values())[0], expected) - _TEST_DIR = os.path.dirname(__file__) def load_file(self, filename): diff --git a/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py b/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py deleted file mode 100644 index c2cdc880..00000000 --- a/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py +++ /dev/null @@ -1,51 +0,0 @@ -import os - -import pytest - -from opentelemetry.semconv.model.exceptions import ValidationError -from opentelemetry.semconv.model.semantic_convention import ( - UnitSemanticConvention, - parse_semantic_convention_groups, -) -from opentelemetry.semconv.model.utils import ValidationContext - - -def test_build_units(open_test_file): - with open_test_file(os.path.join("yaml", "metrics", "units.yaml")) as yaml_file: - conventions = parse_semantic_convention_groups( - yaml_file, ValidationContext(open_test_file, True) - ) - - assert len(conventions) == 1 - convention = conventions[0] - - assert isinstance(convention, UnitSemanticConvention) - assert convention.id == "units" - assert convention.brief == "Specification of commonly used units." - - assert len(convention.members) == 3 - assert sorted(convention.members) == sorted( - ["percent", "nanosecond", "connections"] - ) - - assert convention.members["percent"].id == "percent" - assert convention.members["percent"].brief == "fraction of a total" - assert convention.members["percent"].value == "%" - - assert convention.members["nanosecond"].id == "nanosecond" - assert convention.members["nanosecond"].brief == "time" - assert convention.members["nanosecond"].value == "NS" - - assert convention.members["connections"].id == "connections" - assert convention.members["connections"].brief == "connections" - assert convention.members["connections"].value == "{connections}" - - -def test_build_units_bad(open_test_file): - with pytest.raises(ValidationError) as excinfo, open_test_file( - os.path.join("yaml", "metrics", "units_bad_with_attributes.yaml") - ) as yaml_file: - parse_semantic_convention_groups( - yaml_file, ValidationContext(open_test_file, True) - ) - assert "attributes" in str(excinfo.value) diff --git a/semantic-conventions/src/tests/semconv/templating/test_code.py b/semantic-conventions/src/tests/semconv/templating/test_code.py index 034d2b95..f0e28525 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_code.py +++ b/semantic-conventions/src/tests/semconv/templating/test_code.py @@ -5,24 +5,6 @@ from opentelemetry.semconv.templating.code import CodeRenderer -def test_codegen_units(test_file_path, read_test_file): - semconv = SemanticConventionSet(debug=False) - semconv.parse(test_file_path("yaml", "metrics", "units.yaml")) - semconv.finish() - - template_path = test_file_path("jinja", "metrics", "units_template") - renderer = CodeRenderer({}, trim_whitespace=False) - - filename = os.path.join(tempfile.mkdtemp(), "Attributes.java") - renderer.render(semconv, template_path, filename, None) - with open(filename, "r", encoding="utf-8") as f: - result = f.read() - - expected = read_test_file("jinja", "metrics", "expected.java") - - assert result == expected - - def test_codegen_metrics_all(test_file_path, read_test_file): semconv = SemanticConventionSet(debug=False) semconv.parse(test_file_path("yaml", "metrics", "metrics.yaml")) @@ -44,11 +26,11 @@ def test_codegen_metrics_all(test_file_path, read_test_file): def test_strip_blocks_enabled(test_file_path, read_test_file): """Tests that the Jinja whitespace control params are fed to the Jinja environment""" semconv = SemanticConventionSet(debug=False) - semconv.parse(test_file_path("yaml", "metrics", "units.yaml")) + semconv.parse(test_file_path("yaml", "metrics", "metrics.yaml")) semconv.finish() template_path = test_file_path( - "jinja", "metrics", "units_template_trim_whitespace_enabled" + "jinja", "metrics", "metrics_template_trim_whitespace_enabled" ) renderer = CodeRenderer({}, trim_whitespace=True) @@ -61,6 +43,7 @@ def test_strip_blocks_enabled(test_file_path, read_test_file): "jinja", "metrics", "expected_trim_whitespace_enabled.java" ) + print(result) assert result == expected diff --git a/semantic-conventions/src/tests/semconv/templating/test_markdown.py b/semantic-conventions/src/tests/semconv/templating/test_markdown.py index 5c84c440..895d6c0a 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_markdown.py +++ b/semantic-conventions/src/tests/semconv/templating/test_markdown.py @@ -126,9 +126,6 @@ def test_wrong_duplicate(self): self.assertIn("Parameter", msg) self.assertIn("already defined", msg) - def test_units(self): - self.check("markdown/metrics_unit/", extra_yaml_dirs=["yaml/metrics/"]) - def test_event(self): self.check("markdown/event/") @@ -154,9 +151,6 @@ def test_omit_requirement_level(self): def testSamplingRelevant(self): self.check("markdown/sampling_relevant/") - def test_scope(self): - self.check("markdown/scope/") - def test_attribute_group(self): self.check("markdown/attribute_group/") diff --git a/semantic-conventions/syntax.md b/semantic-conventions/syntax.md index 84a7544a..86c05a82 100644 --- a/semantic-conventions/syntax.md +++ b/semantic-conventions/syntax.md @@ -51,8 +51,6 @@ convtype ::= "span" # Default if not specified | "resource" # see spanspecificfields | "event" # see eventspecificfields | "metric" # see metricfields - | "metric_group" - | "scope" | "attribute_group" # no specific fields defined brief ::= string