Skip to content

Commit

Permalink
Merge pull request #867 from portier/feat/prometheus
Browse files Browse the repository at this point in the history
Drop prometheus crate dep, reimplement metrics
  • Loading branch information
stephank committed Apr 11, 2024
2 parents 2588d63 + 3a53cc7 commit 30223fe
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 126 deletions.
41 changes: 13 additions & 28 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ features = ["builder"]
version = "0.4.11"
features = ["std", "release_max_level_info"]

[dependencies.prometheus]
version = "0.13.0"
default-features = false

[dependencies.rand_core]
optional = true
version = "0.6.4"
Expand Down
2 changes: 1 addition & 1 deletion src/agents/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::metrics::Histogram;
use crate::utils::agent::{Agent, Context, Handler, Message};
use headers::{CacheControl, HeaderMapExt};
use http::StatusCode;
use prometheus::Histogram;
use reqwest::{Client, Method, Request};
use std::time::Duration;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/agents/store/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::agents::key_manager::rotating::{KeySet, RotatingKeys};
use crate::config::LimitInput;
use crate::crypto::SigningAlgorithm;
use crate::metrics::Histogram;
use crate::utils::agent::{Addr, Message, Sender};
use crate::utils::BoxError;
use crate::web::{Session, SessionData};
use prometheus::Histogram;
use std::collections::HashSet;
use url::Url;

Expand Down
9 changes: 3 additions & 6 deletions src/handlers/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::web::{data_response, empty_response, Context, HandlerResult, Response
use headers::{ContentType, Header};
use http::StatusCode;
use hyper_staticfile::{AcceptEncoding, ResponseBuilder};
use prometheus::{Encoder, TextEncoder};
use std::env;

/// Handler for the root path, redirects to the Portier homepage.
Expand Down Expand Up @@ -33,13 +32,11 @@ pub async fn version(_ctx: &mut Context) -> HandlerResult {

/// Metrics route. (Prometheus-compatible)
pub async fn metrics(_ctx: &mut Context) -> HandlerResult {
let mut buffer = vec![];
let metric_families = prometheus::gather();
let encoder = TextEncoder::new();
encoder.encode(&metric_families, &mut buffer).unwrap();
let mut buffer = String::new();
crate::metrics::write_metrics(&mut buffer).unwrap();

let mut res = data_response(buffer);
res.header(ContentType::name(), encoder.format_type());
res.header(ContentType::name(), "text/plain; version=0.0.4");
Ok(res)
}

Expand Down

0 comments on commit 30223fe

Please sign in to comment.