Skip to content

Prometheus metrics integration#646

Merged
murerfel merged 13 commits intomasterfrom
feature/fm-prometheus-metrics
Feb 15, 2022
Merged

Prometheus metrics integration#646
murerfel merged 13 commits intomasterfrom
feature/fm-prometheus-metrics

Conversation

@murerfel
Copy link
Contributor

@murerfel murerfel commented Feb 7, 2022

Integrate the prometheus service client as described in #611

  • Use the warp http server to serve the metrics as a http resource (/metrics) on a configurable port
    • NOTE: does NOT use https/TLS, but plain http
  • Add an o-call interface to update metrics from inside the enclave
  • Provides some default metrics (handled by the prometheus library itself)
  • In addition, added the following metrics:
    • Free balance of the enclave account
    • Sidechain block height
    • TOP pool size

Closes #611

Copy link
Contributor Author

@murerfel murerfel left a comment

Choose a reason for hiding this comment

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

Comments to explain the changes

Comment on lines +18 to +34
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(all(feature = "std", feature = "sgx"))]
compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time");

#[cfg(all(not(feature = "std"), feature = "sgx"))]
extern crate sgx_tstd as std;

use codec::{Decode, Encode};

#[derive(Encode, Decode)]
pub enum EnclaveMetric {
SetSidechainBlockHeight(u64),
TopPoolSizeSet(u64),
TopPoolSizeIncrement,
TopPoolSizeDecrement,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a small crate for the data model to hold metrics information that can be passed from the enclave -> untrusted service.

Comment on lines +100 to +126
pub static GLOBAL_RPC_AUTHOR_COMPONENT: ComponentContainer<EnclaveRpcAuthor> =
ComponentContainer::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initializing this component was done in the sidechain crate until now - but since we have to pass in the o-call API now too, I decided to move it here into the enclave-runtime with the rest of all the global components.

@murerfel murerfel marked this pull request as ready for review February 8, 2022 07:23
@murerfel murerfel requested review from clangenb and haerdib February 8, 2022 07:23
@murerfel murerfel self-assigned this Feb 8, 2022
@murerfel murerfel force-pushed the feature/fm-prometheus-metrics branch from dea9b22 to 6ecccd0 Compare February 9, 2022 06:32
Felix Müller added 2 commits February 14, 2022 09:06
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Looks very cool. I only have one question.

api.signer = signer_orig;
Ok(())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, main.rs is constantly shrinking.

Comment on lines +51 to +54
let metrics_route = warp::path!("metrics").and_then(move || {
let handler_clone = metrics_handler.clone();
async move { handler_clone.handle_metrics().await }
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I have problems understanding this code. Why do we need the nested move?

Copy link
Contributor Author

@murerfel murerfel Feb 14, 2022

Choose a reason for hiding this comment

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

This took me 3 hours to figure out - and I still cannot say I understand it fully myself 🙈

First we create a lambda, into which we move the handler, that is the easy part to understand. But then every request needs its own instance of a request handler, and this is the only way I was able to make that work (it implements Fn and not only FnOnce, which would be the case if you didn't have the clone() like on line 52.
The second async move is required to move the handler clone into the async block, without the move it cannot be guaranteed that the handler clone lives long enough for the future to complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, interesting. Well, to me it seems like you did understand the problematic here. 😄

Copy link
Contributor

@haerdib haerdib left a comment

Choose a reason for hiding this comment

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

Looks good, some small comments :)

@murerfel murerfel requested review from clangenb and haerdib February 15, 2022 06:27
Copy link
Contributor

@haerdib haerdib left a comment

Choose a reason for hiding this comment

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

LGTM :)

Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

provide prometheus stats

3 participants