Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
feat: log headers to see if X-Forward-For or X-Real-IP present
Browse files Browse the repository at this point in the history
  • Loading branch information
taco-paco committed Oct 22, 2024
1 parent 9865bcd commit effcef2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use prometheus::{Encoder, GaugeVec, IntCounter, IntCounterVec, Opts, Registry, T
use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::Method;
use rocket::{Data, Request, State};
use tracing::debug;
use tracing::instrument;

use crate::errors::CoreError;
Expand All @@ -29,8 +30,17 @@ impl Fairing for Metrics {
}
}

#[instrument(skip(self, req, _data))]
async fn on_request(&self, req: &mut Request<'_>, _data: &mut Data<'_>) {
self.requests_total.inc();
if let Some(val) = req.client_ip() {
let ip = val.to_string();
let ip = ip.as_str();
debug!("Plugin launched by: {}", ip);
debug!("Headers: {:?}", req.headers());

self.num_distinct_users.with_label_values(&[ip]).inc();
}

match req.method() {
Method::Options => {}
Expand All @@ -41,14 +51,6 @@ impl Fairing for Metrics {

impl Metrics {
fn update_metrics(&self, req: &mut Request<'_>) {
if let Some(val) = req.client_ip() {
let ip = val.to_string();
let ip = ip.as_str();
info!("Plugin launched by: {}", ip);

self.num_distinct_users.with_label_values(&[ip]).inc();
}

match req.uri().path().as_str() {
"/compile" | "/compile-async" => self.num_of_compilations.inc(),
"/on-plugin-launched" => self.num_plugin_launches.inc(),
Expand Down

0 comments on commit effcef2

Please sign in to comment.