Skip to content

Commit

Permalink
refactor: drop unused cadence metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Dec 2, 2024
1 parent c27c8ea commit 1f290b1
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 38 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ badge = { path = "./libs/badge" }
actix-web = "4"
actix-web-lab = "0.23"
anyhow = "1"
cadence = "1"
crates-index = { version = "3", default-features = false, features = ["git"] }
derive_more = { version = "1", features = ["display", "error", "from"] }
dotenvy = "0.15"
Expand Down
10 changes: 0 additions & 10 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::{
collections::HashSet,
panic::RefUnwindSafe,
sync::{Arc, LazyLock},
time::{Duration, Instant},
};

use actix_web::dev::Service;
use anyhow::{anyhow, Error};
use cadence::{MetricSink, NopMetricSink, StatsdClient};
use futures_util::{
future::try_join_all,
stream::{self, LocalBoxStream},
Expand Down Expand Up @@ -39,7 +37,6 @@ use self::fut::{analyze_dependencies, crawl_manifest};

#[derive(Debug, Clone)]
pub struct Engine {
metrics: Arc<StatsdClient>,
query_crate: Cache<QueryCrate, CrateName>,
get_popular_crates: Cache<GetPopularCrates, ()>,
get_popular_repos: Cache<GetPopularRepos, ()>,
Expand All @@ -49,8 +46,6 @@ pub struct Engine {

impl Engine {
pub fn new(client: reqwest::Client, index: ManagedIndex) -> Engine {
let metrics = Arc::new(StatsdClient::from_sink("engine", NopMetricSink));

let query_crate = Cache::new(QueryCrate::new(index), Duration::from_secs(10), 500);
let get_popular_crates = Cache::new(
GetPopularCrates::new(client.clone()),
Expand All @@ -70,18 +65,13 @@ impl Engine {
);

Engine {
metrics,
query_crate,
get_popular_crates,
get_popular_repos,
retrieve_file_at_path,
fetch_advisory_db,
}
}

pub fn set_metrics<M: MetricSink + Send + Sync + RefUnwindSafe + 'static>(&mut self, sink: M) {
self.metrics = Arc::new(StatsdClient::from_sink("engine", sink));
}
}

#[derive(Debug)]
Expand Down
19 changes: 2 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#![deny(rust_2018_idioms)]
#![warn(missing_debug_implementations)]

use std::{
env,
net::{Ipv4Addr, UdpSocket},
time::Duration,
};
use std::{env, net::Ipv4Addr, time::Duration};

use actix_web::{
middleware::Logger,
web::{self, ThinData},
};
use actix_web_lab::middleware::NormalizePath;
use cadence::{QueuingMetricSink, UdpMetricSink};
use reqwest::redirect::Policy as RedirectPolicy;

mod engine;
Expand All @@ -26,14 +21,6 @@ use self::{engine::Engine, utils::index::ManagedIndex};

const DEPS_RS_UA: &str = "deps.rs";

fn init_metrics() -> QueuingMetricSink {
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.set_nonblocking(true).unwrap();
let host = ("127.0.0.1", 8125);
let sink = UdpMetricSink::from(host, socket).unwrap();
QueuingMetricSink::from(sink)
}

fn init_tracing_subscriber() {
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
Expand All @@ -57,7 +44,6 @@ fn init_tracing_subscriber() {
async fn main() {
dotenvy::dotenv().ok();
init_tracing_subscriber();
let metrics = init_metrics();

let client = reqwest::Client::builder()
.user_agent(DEPS_RS_UA)
Expand All @@ -81,8 +67,7 @@ async fn main() {
});
}

let mut engine = Engine::new(client.clone(), index);
engine.set_metrics(metrics);
let engine = Engine::new(client.clone(), index);

let server = actix_web::HttpServer::new(move || {
actix_web::App::new()
Expand Down

0 comments on commit 1f290b1

Please sign in to comment.