From 03e1543cd4c4cef13dafc1e16ab4b96ae8eb614e Mon Sep 17 00:00:00 2001 From: James Moessis Date: Wed, 12 Jan 2022 18:11:41 +1100 Subject: [PATCH] appease linter --- .../semconv/model/semantic_convention.py | 17 +++++++---- .../semconv/templating/markdown/__init__.py | 15 ++++++++-- .../tests/semconv/model/test_correct_parse.py | 30 ++++++++++++------- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py index 87e46d4a..aa01a12a 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py @@ -65,6 +65,7 @@ class InstrumentKind(Enum): def __str__(self): return self.name + def parse_semantic_convention_type(type_value): # Gracefully transition to the new types if type_value is None: @@ -268,17 +269,23 @@ def __init__(self, group): if group.get("metrics"): try: self.metrics: Tuple[MetricSemanticConvention.Metric] = tuple( - map(lambda m: MetricSemanticConvention.Metric(m), group.get("metrics")) + map( + MetricSemanticConvention.Metric, + group.get("metrics"), + ) ) - except ValueError: + except ValueError as e: raise ValidationError.from_yaml_pos( - self._position, "id, instrument, units, and brief must all be defined for concrete metrics" - ) + self._position, + "id, instrument, units, and brief must all be defined for concrete metrics", + ) from e for metric in self.metrics: if not metric.id.startswith(self.semconv_id): raise ValidationError.from_yaml_pos( self._position, - "id of metric `{}` must be prefixed with its parent's id `{}`".format(metric.id, self.semconv_id) + "id of metric `{}` must be prefixed with its parent's id `{}`".format( + metric.id, self.semconv_id + ), ) diff --git a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py index e32411bb..5a5db8c0 100644 --- a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py +++ b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py @@ -42,6 +42,7 @@ class RenderContext: def __init__(self): self.is_full = False self.is_remove_constraint = False + self.is_metric_table = False self.group_key = "" self.enums = [] self.notes = [] @@ -175,7 +176,10 @@ def to_markdown_attr( ) ) - def to_markdown_metric_table(self, semconv: MetricSemanticConvention, output: io.StringIO): + @staticmethod + def to_markdown_metric_table( + semconv: MetricSemanticConvention, output: io.StringIO + ): """ This method renders metrics as markdown table entry """ @@ -185,7 +189,9 @@ def to_markdown_metric_table(self, semconv: MetricSemanticConvention, output: io ) for metric in semconv.metrics: output.write( - "| `{}` | {} | `{}` | {} |\n".format(metric.id, metric.instrument, metric.units, metric.brief) + "| `{}` | {} | `{}` | {} |\n".format( + metric.id, metric.instrument, metric.units, metric.brief + ) ) def to_markdown_anyof(self, anyof: AnyOf, output: io.StringIO): @@ -433,7 +439,10 @@ def _render_group(self, semconv, parameters, output): if isinstance(semconv, EventSemanticConvention): output.write("The event name MUST be `{}`.\n\n".format(semconv.name)) - if isinstance(semconv, MetricSemanticConvention) and self.render_ctx.is_metric_table: + if ( + isinstance(semconv, MetricSemanticConvention) + and self.render_ctx.is_metric_table + ): self.to_markdown_metric_table(semconv, output) attr_to_print = [] 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 6301c879..08c81c9f 100644 --- a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py +++ b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py @@ -20,9 +20,9 @@ from opentelemetry.semconv.model.semantic_attribute import StabilityLevel from opentelemetry.semconv.model.semantic_convention import ( EventSemanticConvention, + MetricSemanticConvention, SemanticConventionSet, SpanSemanticConvention, - MetricSemanticConvention, ) @@ -202,14 +202,21 @@ def test_metrics_http(self): semconv.parse(self.load_file("yaml/general.yaml")) semconv.parse(self.load_file("yaml/http.yaml")) - metric_semconvs = cast(List[MetricSemanticConvention], list(semconv.models.values())[:3]) + metric_semconvs = cast( + List[MetricSemanticConvention], list(semconv.models.values())[:3] + ) expected = { "id": "metric.http", "prefix": "http", "extends": "", "n_constraints": 0, - "attributes": ["http.method", "http.host", "http.scheme", "http.status_code"] + "attributes": [ + "http.method", + "http.host", + "http.scheme", + "http.status_code", + ], } self.semantic_convention_check(metric_semconvs[0], expected) @@ -219,11 +226,13 @@ def test_metrics_http(self): "extends": "metric.http", "n_constraints": 1, "attributes": ["net.peer.name", "net.peer.port", "net.peer.ip"], - "metrics": [{ + "metrics": [ + { "id": "metric.http.client.duration", "instrument": "Histogram", - "units": "ms" - }] + "units": "ms", + } + ], } self.semantic_convention_check(metric_semconvs[1], expected) self.metric_check(metric_semconvs[1].metrics, expected.get("metrics")) @@ -238,19 +247,18 @@ def test_metrics_http(self): { "id": "metric.http.server.duration", "instrument": "Histogram", - "units": "ms" + "units": "ms", }, { "id": "metric.http.server.active_requests", "instrument": "AsynchronousUpDownCounter", - "units": "{requests}" - } - ] + "units": "{requests}", + }, + ], } self.semantic_convention_check(metric_semconvs[2], expected) self.metric_check(metric_semconvs[2].metrics, expected.get("metrics")) - def test_resource(self): semconv = SemanticConventionSet(debug=False) semconv.parse(self.load_file("yaml/cloud.yaml"))