nlopes / actix-web-prom

Actix-web middleware to expose Prometheus metrics
MIT License
89 stars 56 forks source link

Metrcis not working as expected locally #78

Closed lauti7 closed 9 months ago

lauti7 commented 9 months ago

Hi! I've been testing the crate on my local machine but it's not working as expected.

After making some requests to my Actix server, the metrics seem to be reset or started over (or not updating at all), It's bizarre what's happening. For example, the HTTP request counter is never updated or after being incremented, it decrements and no sense to me. The /metrics endpoint doesn't keep itself consistent. Is this behavior expected or maybe I'm doing something wrong?

We're not doing anything weird on our side:

// middleware::metrics
pub fn metrics() -> PrometheusMetrics {
    PrometheusMetricsBuilder::new("quests")
        .endpoint("/metrics")
        .build()
        .unwrap()
}

// Actix routing
pub fn get_app_router(
    config: &Data<Config>,
    db: &Data<Database>,
    redis: &Data<RedisMessagesQueue>,
) -> App<
    impl ServiceFactory<
        actix_web::dev::ServiceRequest,
        Config = (),
        Response = actix_web::dev::ServiceResponse<impl MessageBody>,
        Error = actix_web::Error,
        InitError = (),
    >,
> {
    let cors = actix_cors::Cors::permissive();
    App::new()
        .app_data(query_extractor_config())
        .app_data(json_extractor_config())
        .app_data(path_extractor_config())
        .app_data(config.clone())
        .app_data(db.clone())
        .app_data(redis.clone())
        .wrap(cors)
        .wrap(TracingLogger::default())
        .wrap(middlewares::metrics())
        .wrap(middlewares::metrics_token(&config.wkc_metrics_bearer_token))
        .configure(routes::services)
}