Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics exporter to Prometheus with OTLP #1438

Merged
merged 17 commits into from
Dec 18, 2024

Conversation

shinta-liem
Copy link
Collaborator

Added an exporter to Prometheus with opentelemetry

Copy link
Collaborator

@akoshelev akoshelev left a comment

Choose a reason for hiding this comment

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

this is looking very promising, thanks for working on it!

@@ -13,6 +13,11 @@ partitions = []
crossbeam-channel = "0.5"
# This crate uses raw entry API that is unstable in stdlib
hashbrown = "0.15"
# Open telemetry crates: opentelemetry-prometheus crate implementation is based on Opentelemetry API and SDK 0.23. (TBC)
opentelemetry = "0.24"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is great, but can you make a separate crate for it? ipa-metrics is intended to contain only core functionality and it is easier to maintain in the long term if it does not have extra dependencies

use crate::{counter, install_new_thread, producer::Producer, MetricChannelType};
struct MeteredScope<'scope, 'env: 'scope>(&'scope Scope<'scope, 'env>, Producer);

impl<'scope, 'env: 'scope> MeteredScope<'scope, 'env> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need this complexity, each thread has access to its own metric store throuh CurrentThreadMetricContext

// Err(err) => Err(Error::application(StatusCode::INTERNAL_SERVER_ERROR, err)),
// }

// TODO: Remove this dummy metrics and get metrics for scraper from ipa-metrics::PrometheusMetricsExporter (see ipa-metrics/exporter.rs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@akoshelev I'm still not clear how we can pull the metrics from the logging_handle. IpaHttpClient doesn't seem to have a reference to it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's right, it is not referenced from anywhere. helper.rs does have logging_handle that has a reference to this controller. So we need to plumb it through to deliver Controller to the handlers

@@ -120,6 +121,10 @@ impl PartitionedStore {
self.get_mut(CurrentThreadContext::get()).counter(key)
}

pub fn counters(&mut self) -> impl Iterator<Item = (&OwnedMetricName, CounterValue)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is &mut required here or &self can work too?


/// Takes details from the HTTP request and creates a `[TransportCommand]::CreateQuery` that is sent
/// to the [`HttpTransport`].
async fn handler(transport: Extension<MpcHttpTransport>) -> Result<Vec<u8>, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd encourage to write some tests here as it is often hard to figure out why HTTP server is not responding or responds with errors. There are some examples in this folder that exercise happy path and error path

.merge(query::query_router(transport.clone()))
.merge(query::h2h_router(transport.clone())),
)
.merge(query::metric_router(transport))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Does this handler belong inside the query module? You can perhaps park it alongside echo

let mut buff = Vec::new();
store.export(&mut buff);

let result = String::from_utf8(buff).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to validate the results somehow. Also consider removing the println.

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 87.33333% with 19 lines in your changes missing coverage. Please review.

Project coverage is 93.05%. Comparing base (e7a234a) to head (822c659).
Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
ipa-core/src/cli/metric_collector.rs 12.50% 7 Missing ⚠️
ipa-core/src/net/transport.rs 0.00% 4 Missing ⚠️
ipa-core/src/app.rs 40.00% 3 Missing ⚠️
ipa-metrics/src/partitioned.rs 62.50% 3 Missing ⚠️
ipa-core/src/bin/helper.rs 0.00% 1 Missing ⚠️
ipa-core/src/net/server/handlers/metrics.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1438      +/-   ##
==========================================
- Coverage   93.28%   93.05%   -0.23%     
==========================================
  Files         239      239              
  Lines       43532    43652     +120     
==========================================
+ Hits        40608    40621      +13     
- Misses       2924     3031     +107     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akoshelev akoshelev merged commit 62653e5 into private-attribution:main Dec 18, 2024
13 checks passed
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.

3 participants