change bucket and metrics

This commit is contained in:
MatthieuCoder 2023-01-21 14:25:05 +04:00
parent 28bb57889e
commit 2647bd0356
2 changed files with 11 additions and 10 deletions

View file

@ -51,21 +51,21 @@ lazy_static! {
.with_description("Amount of requests sent to the ratelimiter") .with_description("Amount of requests sent to the ratelimiter")
.init() .init()
}; };
static ref UPSTREAM_TIMES: Histogram<f64> = { static ref UPSTREAM_TIMES: Histogram<u64> = {
global::meter(&METER_NAME) global::meter(&METER_NAME)
.f64_histogram("rest.upstream_http_request_duration_seconds") .u64_histogram("rest.upstream_http_request_duration_miliseconds")
.with_description("Time took to request discord") .with_description("Time took to request discord")
.init() .init()
}; };
static ref TICKET_TIMES: Histogram<f64> = { static ref TICKET_TIMES: Histogram<u64> = {
global::meter(&METER_NAME) global::meter(&METER_NAME)
.f64_histogram("rest.ticket_http_request_duration_seconds") .u64_histogram("rest.ticket_http_request_duration_miliseconds")
.with_description("Time took to get a ticket from the ratelimiter") .with_description("Time took to get a ticket from the ratelimiter")
.init() .init()
}; };
static ref HEADERS_SUBMIT_TIMES: Histogram<f64> = { static ref HEADERS_SUBMIT_TIMES: Histogram<u64> = {
global::meter(&METER_NAME) global::meter(&METER_NAME)
.f64_histogram("rest.header_submit_http_request_duration_seconds") .u64_histogram("rest.header_submit_http_request_duration_miliseconds")
.with_description("Time took to get a ticket from the ratelimiter") .with_description("Time took to get a ticket from the ratelimiter")
.init() .init()
}; };
@ -242,7 +242,7 @@ pub async fn handle_request(
.then(|v| async { .then(|v| async {
TICKET_TIMES.record( TICKET_TIMES.record(
&cx, &cx,
ticket_start.elapsed()?.as_secs_f64(), ticket_start.elapsed()?.as_millis() as u64,
&[KeyValue::new("bucket", name)], &[KeyValue::new("bucket", name)],
); );
v v
@ -300,7 +300,7 @@ pub async fn handle_request(
.then(|v| async { .then(|v| async {
UPSTREAM_TIMES.record( UPSTREAM_TIMES.record(
&cx, &cx,
upstream_start.elapsed()?.as_secs_f64(), upstream_start.elapsed()?.as_millis() as u64,
&[KeyValue::new("bucket", name)], &[KeyValue::new("bucket", name)],
); );
v.context("") v.context("")
@ -327,6 +327,7 @@ pub async fn handle_request(
.map(|f| (f.0, f.1.expect("errors should be filtered"))) .map(|f| (f.0, f.1.expect("errors should be filtered")))
.collect(); .collect();
let headers_start = SystemTime::now();
HEADERS_SUBMIT_CALLS.add(&cx, 1, &[KeyValue::new("bucket", name)]); HEADERS_SUBMIT_CALLS.add(&cx, 1, &[KeyValue::new("bucket", name)]);
let _submit_headers = ratelimiter let _submit_headers = ratelimiter
.submit_headers(bucket.clone(), headers) .submit_headers(bucket.clone(), headers)
@ -334,7 +335,7 @@ pub async fn handle_request(
.then(|v| async { .then(|v| async {
HEADERS_SUBMIT_TIMES.record( HEADERS_SUBMIT_TIMES.record(
&cx, &cx,
upstream_start.elapsed()?.as_secs_f64(), headers_start.elapsed()?.as_millis() as u64,
&[KeyValue::new("bucket", name)], &[KeyValue::new("bucket", name)],
); );
v v

View file

@ -59,7 +59,7 @@ where
{ {
let meter = opentelemetry_otlp::new_pipeline() let meter = opentelemetry_otlp::new_pipeline()
.metrics( .metrics(
selectors::simple::histogram([1.0, 2.0, 5.0, 10.0, 20.0, 50.0]), selectors::simple::histogram([0.1, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0]),
stateless_temporality_selector(), stateless_temporality_selector(),
opentelemetry::runtime::Tokio, opentelemetry::runtime::Tokio,
) )