Skip to content

Commit

Permalink
prometheus.cc: Lift counter write to a function
Browse files Browse the repository at this point in the history
This patch abstracts the non-aggregated counter write logic into a
separate function for later use.
  • Loading branch information
Vlad Lazar committed Jun 22, 2022
1 parent abb4a3c commit 1ed2aac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/prometheus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,24 @@ metric_family_range get_range(const metrics_families_per_shard& mf, const sstrin

}

void write_counter(std::stringstream& s, const config& ctx, const sstring& name, const mi::metric_value& value, std::map<sstring, sstring> labels) {
add_name(s, name, labels, ctx);
std::string value_str;
try {
value_str = to_str(value);
} catch (const std::range_error& e) {
seastar_logger.debug("prometheus: write_text_representation: {}: {}", s.str(), e.what());
value_str = "NaN";
} catch (...) {
auto ex = std::current_exception();
// print this error as it's ignored later on by `connection::start_response`
seastar_logger.error("prometheus: write_text_representation: {}: {}", s.str(), ex);
std::rethrow_exception(std::move(ex));
}
s << value_str;
s << "\n";
}

void write_histogram(std::stringstream& s, const config& ctx, const sstring& name, const seastar::metrics::histogram& h, std::map<sstring, sstring> labels) {
add_name(s, name + "_sum", labels, ctx);
s << h.sample_sum;
Expand Down

0 comments on commit 1ed2aac

Please sign in to comment.