8000 Correct nh sample span structure and parsing by vesari · Pull Request #1082 · prometheus/client_python · GitHub
[go: up one dir, main page]

Skip to content

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

Merged

Conversation

vesari
Copy link
Contributor
@vesari vesari commented Jan 8, 2025

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.

vesari added 5 commits January 6, 2025 17:57
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:
Copy link
Member

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

Comment on lines 349 to 351
pos_spans_text = spans[spans_name]
pos_spans = []
for start, end in pos_spans_text:
Copy link
Member

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 :)

Suggested change
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 = {}
Copy link
Member

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>
Copy link
Member
@krajorama krajorama left a 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):
Copy link
Member

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 :)

Copy link
Contributor Author

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

Copy link
Member
@csmarchbanks csmarchbanks left a 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>
@csmarchbanks csmarchbanks merged commit ecf344b into prometheus:master Jan 17, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0