Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Exporter/Prometheus: Convert None label values to empty string.#486

Merged
songy23 merged 2 commits intocensus-instrumentation:masterfrom
songy23:prometheus-none-label
Feb 6, 2019
Merged

Exporter/Prometheus: Convert None label values to empty string.#486
songy23 merged 2 commits intocensus-instrumentation:masterfrom
songy23:prometheus-none-label

Conversation

@songy23
Copy link
Copy Markdown
Contributor

@songy23 songy23 commented Feb 5, 2019

Fixes #480.

/cc @PikBot

Copy link
Copy Markdown
Member

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Great catch and thank you @songy23! I believe we had a similar bug in OpenCensus Go that was fixed late last year. LGTM but with a minor suggestion for a comment for our future selves.

metric_name = desc['name']
metric_description = desc['documentation']
label_keys = desc['labels']
tag_values = list(map(cast_none_to_empty_str, tag_values))
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.

Let's add a comment above this code to say

# Prometheus requires that all tag values be strings hence
# the need to cast none to the empty string before exporting.
# See https://github.com/census-instrumentation/opencensus-python/issues/480
tag_values = list(map(cast_none_to_empty_str, tag_values)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG, done. Also fixed a bug in histogram buckets.

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, but I think it's a bit more readable and idiomatic to do:

tag_values = [tv for tv in tag_values if tv else ""]

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.

And why wrap the comment at <79 chars?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks for the suggestion.

And why wrap the comment at <79 chars?

Test session "lint" checks line length and will fail on lines with >80 chars, including comments.

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.

I mean why not wrap at the last word boundary before 79, the line is wrapped early. Not a big deal in any case.

cum_count += agg_data.counts_per_bucket[ii]
points[str(bound)] = cum_count
# Prometheus requires buckets to be sorted, and +Inf present.
# In OpenCensus we don't have +Inf in the bucket bonds so need to
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

# Prometheus requires buckets to be sorted, and +Inf present.
# In OpenCensus we don't have +Inf in the bucket bonds so need to
# append it here.
points["+Inf"] = agg_data.count_data
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.

What's this bug fix in here? A test demonstrating the problem would be useful. I thought this code runs through the Prometheus Python client first before being exported? I think it would be good for us to file and diagnose that bug separately than sneak in a bug fix here without figuring out its extent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@songy23 songy23 force-pushed the prometheus-none-label branch from c4e41c6 to 003da06 Compare February 6, 2019 00:19
Copy link
Copy Markdown
Member

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

LGTM, please squash the commits and we are good to go. Please file a separate bug for the +Inf inclusion into exported buckets.

@songy23 songy23 force-pushed the prometheus-none-label branch from 003da06 to cdc4cae Compare February 6, 2019 00:31
@songy23 songy23 force-pushed the prometheus-none-label branch from cdc4cae to cc61de8 Compare February 6, 2019 00:59
metric_name = desc['name']
metric_description = desc['documentation']
label_keys = desc['labels']
tag_values = list(map(cast_none_to_empty_str, tag_values))
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, but I think it's a bit more readable and idiomatic to do:

tag_values = [tv for tv in tag_values if tv else ""]

metric_name = desc['name']
metric_description = desc['documentation']
label_keys = desc['labels']
tag_values = list(map(cast_none_to_empty_str, tag_values))
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.

And why wrap the comment at <79 chars?

@songy23
Copy link
Copy Markdown
Contributor Author

songy23 commented Feb 6, 2019

Thanks for reviewing!

@songy23 songy23 merged commit beb70f7 into census-instrumentation:master Feb 6, 2019
@songy23 songy23 deleted the prometheus-none-label branch February 6, 2019 02:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants