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

Log headers in debug environment to see if X-Forward-For or X-Real-IP present #236

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading