Skip to content

Commit

Permalink
fix(hermes): fix metrics content-type
Browse files Browse the repository at this point in the history
Openmetrics specification expects its own content-type instead of plain
text. I didn't set it before as Prometheus still accepts text format but
apparently there are some scrapers (like datadog) that decide
dynamically what format to use for parsing based on the content type and
our format follows Openmetrics specification. Prometheus should be able
to parse it but weirdly it didn't work in our situation. An example of
inconsistency is how counters are represented. In Openmetrics
specification the metric name is appended by `_total` whereas normal
prometheus just uses the metric name.
  • Loading branch information
ali-bahjati committed Oct 20, 2023
1 parent 99eaab8 commit 6215460
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hermes/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hermes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hermes"
version = "0.4.1"
version = "0.4.2"
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
edition = "2021"

Expand Down
9 changes: 8 additions & 1 deletion hermes/src/metrics_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use {
anyhow::Result,
axum::{
extract::State,
http::header,
response::IntoResponse,
routing::get,
Router,
Expand Down Expand Up @@ -55,5 +56,11 @@ pub async fn metrics(State(state): State<Arc<AppState>>) -> impl IntoResponse {
// to write to the buffer.
encode(&mut buffer, &registry).unwrap();

buffer
(
[(
header::CONTENT_TYPE,
"application/openmetrics-text; version=1.0.0; charset=utf-8",
)],
buffer,
)
}

0 comments on commit 6215460

Please sign in to comment.