Skip to content

Commit

Permalink
appease linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmoessis committed Jan 12, 2022
1 parent ed5072c commit 03e1543
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down
30 changes: 19 additions & 11 deletions semantic-conventions/src/tests/semconv/model/test_correct_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from opentelemetry.semconv.model.semantic_attribute import StabilityLevel
from opentelemetry.semconv.model.semantic_convention import (
EventSemanticConvention,
MetricSemanticConvention,
SemanticConventionSet,
SpanSemanticConvention,
MetricSemanticConvention,
)


Expand Down Expand Up @@ -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)

Expand All @@ -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"))
Expand All @@ -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"))
Expand Down

0 comments on commit 03e1543

Please sign in to comment.