Skip to content

Conversation

@ljbade
Copy link

@ljbade ljbade commented Mar 25, 2022

This PR is set to merge on the rebased master, but I will update that once #7 is merged.

The OpenMetrics specification has a few changes from the previous Prometheus exposition format.

This PR adds a flag to allow enabling the OpenMetrics format. Which changes the following:

  • # EOF is added to the end
  • the untyped metric type is now called unknown
  • for counter metrics the value name must now end in _total (which was the recommended practice with Prometheus prior).
  • for counter metrics the name in the # TYPE header must not contain _total
  • timestamps are now floating point numbers with units of seconds instead of integers with units of milliseconds

I have added a bunch of tests to check the changes.

@ljbade ljbade requested a review from jbangelo March 25, 2022 04:02
@coveralls
Copy link

coveralls commented Mar 25, 2022

Pull Request Test Coverage Report for Build 2067817853

  • 39 of 39 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 96.384%

Totals Coverage Status
Change from base Build 2063676183: 0.08%
Covered Lines: 773
Relevant Lines: 802

💛 - Coveralls

@ljbade ljbade force-pushed the ljbade/om branch 3 times, most recently from a50a1a0 to 523e1f8 Compare March 25, 2022 12:12
@ljbade ljbade force-pushed the ljbade/rebase-upstream branch from 6837162 to dd539fd Compare March 28, 2022 22:42
@ljbade ljbade force-pushed the ljbade/om branch 3 times, most recently from 6236e1f to cca5b7d Compare March 29, 2022 03:23
Copy link

@silverjam silverjam left a comment

Choose a reason for hiding this comment

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

I think we should consider proposing this PR to the maintainers to gauge their interest pushing it upstream and see if they have any suggestions how to best structure the changes. Since OpenMetrics is supported by other tools (like ClickHouse) this seems like a feature that would be useful to other users.

If the maintainers are not interested in pulling in the changes we should consider how we are going to maintain this long term. If we structure these changes so that they lives alongside the existing code it might be easier to bring in future changes or bug fixes without a lot manual code wrangling.

public:
using Serializer::Serialize;
std::string Serialize(const std::vector<MetricFamily>& metrics,
bool open_metrics) const;

Choose a reason for hiding this comment

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

Would it make sense to create an OpenMetrics specific serializer?

Copy link
Author

Choose a reason for hiding this comment

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

I will see if that would work.

for (auto& metric : family.metric) {
SerializeGauge(out, family, metric);
out << "# TYPE " << sorted_family.name << " gauge\n";
if (!sorted_family.help.empty()) {

Choose a reason for hiding this comment

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

Is this something we always want to do regardless of the value of open_metrics?

Copy link
Author

Choose a reason for hiding this comment

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

the order of type and help doesn't really matter, but in OpenMetrics I needed to ensure _total didn't end up in the help name for counters

SerializeCounter(out, family, metric);
void SerializeFamily(std::ostream& out, const MetricFamily& family,
const bool open_metrics) {
auto ends_with = [](const std::string& value,

Choose a reason for hiding this comment

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

This feels different enough that it could be a new function instead of mutating the existing function. Do we still need to be able to write the old format?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think so as recent Prometheus versions handle OpenMetrics. Maybe you are right it might be easier to just upgrade to the new format.

@ljbade ljbade force-pushed the ljbade/rebase-upstream branch 2 times, most recently from b389800 to 3fc5e1a Compare March 30, 2022 01:01
Base automatically changed from ljbade/rebase-upstream to master March 30, 2022 02:01
@ljbade
Copy link
Author

ljbade commented Mar 30, 2022

I wonder if its just easier to adopt the OpenMetrics format and remove the various conditions. Recent Prometheus versions understand the new format, so upstream concern might be breaking things for users of older Prometheus version but then it might be easier to stick to an old prometheus-cpp release.

@ljbade ljbade force-pushed the ljbade/om branch 2 times, most recently from bd99152 to 57d7d6b Compare March 30, 2022 09:03
@silverjam silverjam requested a review from notoriaga March 31, 2022 00:45
@ljbade ljbade merged commit b59a571 into master Apr 1, 2022
@ljbade ljbade deleted the ljbade/om branch April 1, 2022 00:51
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.

5 participants