-
Notifications
You must be signed in to change notification settings - Fork 813
Correct nh sample span structure and parsing #1082
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
Correct nh sample span structure and parsing #1082
Conversation
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
…le-span-structure Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
… be None Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
|
||
|
||
def _compose_spans(spans, spans_name): | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i'd prefer early return instead of exception handling
if spans_name not in spans:
return None
pos_spans_text = spans[spans_name] | ||
pos_spans = [] | ||
for start, end in pos_spans_text: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That _text is Hungarian notation :)
pos_spans_text = spans[spans_name] | |
pos_spans = [] | |
for start, end in pos_spans_text: | |
for start, end in spans[spans_name]: |
re_deltas = re.compile(r'(positive_deltas|negative_deltas):\[(-?\d+(?:,-?\d+)*)\]') | ||
|
||
items = dict(re.findall(pattern, text)) | ||
spans = dict(re_spans.findall(text)) | ||
matches = re_spans.findall(text) | ||
spans = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this here makes the code a little inconsistent, you do the text->data conversion here for spans, but in a helper function for the deltas. Let's move this into the helper function.
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -364,6 +336,31 @@ def _parse_nh_struct(text): | |||
pos_deltas=pos_deltas, | |||
neg_deltas=neg_deltas | |||
) | |||
|
|||
|
|||
def _compose_spans(span_matches, spans_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might want to add a comment what this does, because the list comprehension takes a minute to understand :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense! I've also added comments to the other less complicated function, while I was at it :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also 👍 though I will give you a moment if you want to add a comment, I agree it would be nice.
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
While working on the exposition part of the issue prometheus/OpenMetrics#279, I realized I made a mistake in the code relative to the NH spans and deltas parsing, in that I was not taking into account that span lists have no fixed length, span lists can be absent and that deltas can consequently also not be there. I thought I’d get this right before continuing on the rest of the work.