Skip to content

Correct nh sample span structure and parsing - #1082

Merged
csmarchbanks merged 8 commits into
prometheus:masterfrom
vesari:correct-nh-sample-span-structure
Jan 17, 2025
Merged

Correct nh sample span structure and parsing#1082
csmarchbanks merged 8 commits into
prometheus:masterfrom
vesari:correct-nh-sample-span-structure

Conversation

@vesari

Copy link
Copy Markdown
Contributor

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.

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
Copy Markdown
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
Copy Markdown
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= []
forstart, endinpos_spans_text:
forstart, endinspans[spans_name]:

Comment threadprometheus_client/openmetrics/parser.py
items = dict(re.findall(pattern, text))
spans = dict(re_spans.findall(text))
matches = re_spans.findall(text)
spans = {}

Copy link
Copy Markdown
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>

@krajoramakrajorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

)


def _compose_spans(span_matches, spans_name):

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

@csmarchbankscsmarchbanks left a comment

Copy link
Copy Markdown
Member

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:masterJan 17, 2025
Sign up for freeto 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

@vesari@csmarchbanks@krajorama