Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Merge #1999
Browse files Browse the repository at this point in the history
1999: Enable metric endpoint for taker r=bonomat a=bonomat

Fixes #1980 

This allows us to collect metrics for the taker as well.

In a discussion with Thomas we thought about having a feature flag for this but I opted against it because that would mean we need to release 2 versions: one with and one without this feature. 

What do you think? Shall I add a feature flag or maybe a new cli arg which allows to enable the metric endpoint?

Co-authored-by: Philipp Hoenisch <[email protected]>
  • Loading branch information
bors[bot] and bonomat authored May 10, 2022
2 parents ea2deae + 64ad82c commit 6dff712
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- network: an additional field `leverage` was added to `wire::MakerToTaker::TakeOffer`.
- network: an additional field `leverage_choices` was added to `Order` which is sent from maker to taker when he created a new offer.
The field `leverage` was deprecated.
- Additional API for the taker: `api/metrics` will return prometheus-based metrics about your positions and about general behavior of the application

### Changed

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions taker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ http-api-problem = { version = "0.51.0", features = ["rocket"] }
itertools = "0.10"
libp2p-core = { version = "0.32", default-features = false }
model = { path = "../model" }
prometheus = { version = "0.13", default-features = false }
rocket = { version = "0.5.0-rc.1", features = ["json", "uuid"] }
rocket-basicauth = { path = "../rocket-basicauth" }
rust-embed = "6.4"
Expand Down
1 change: 1 addition & 0 deletions taker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ async fn main() -> Result<()> {
routes::get_health_check,
routes::post_cfd_action,
routes::post_withdraw_request,
routes::get_metrics,
],
)
.register("/api", default_catchers())
Expand Down
13 changes: 13 additions & 0 deletions taker/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ pub async fn post_withdraw_request(
Ok(projection::to_mempool_url(txid, *network.inner()))
}

#[rocket::get("/metrics")]
pub async fn get_metrics<'r>(_auth: Authenticated) -> Result<String, HttpApiProblem> {
let metrics = prometheus::TextEncoder::new()
.encode_to_string(&prometheus::gather())
.map_err(|e| {
HttpApiProblem::new(StatusCode::INTERNAL_SERVER_ERROR)
.title("Failed to encode metrics")
.detail(e.to_string())
})?;

Ok(metrics)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 6dff712

Please sign in to comment.