Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy metrics prometheus server #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
131 changes: 115 additions & 16 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ dotenv = "0.15.0"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
futures-util = "0.3.30"
hyper = { version = "1.2.0", features = ["full"] }
hyper-util = { version = "0.1.3", features = ["full"] }
prometheus = "0.13.3"
bytes = "1.5.0"
http-body-util = "0.1.0"
2 changes: 2 additions & 0 deletions proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{env, path::PathBuf};
#[derive(Debug, Clone)]
pub struct Config {
pub proxy_addr: String,
pub prometheus_addr: String,
pub ssl_crt_path: PathBuf,
pub ssl_key_path: PathBuf,
pub node_port: u16,
Expand All @@ -13,6 +14,7 @@ impl Config {
pub fn new() -> Self {
Self {
proxy_addr: env::var("PROXY_ADDR").expect("PROXY_ADDR must be set"),
prometheus_addr: env::var("PROMETHEUS_ADDR").expect("PROMETHEUS_ADDR must be set"),
ssl_crt_path: env::var("SSL_CRT_PATH")
.map(|e| e.into())
.expect("SSL_CRT_PATH must be set"),
Expand Down
10 changes: 9 additions & 1 deletion proxy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use dotenv::dotenv;
use metrics::Metrics;
use prometheus::Registry;
use regex::Regex;
use std::{collections::HashMap, error::Error, fmt::Display, sync::Arc};
use tokio::sync::RwLock;
Expand All @@ -8,7 +10,9 @@ use crate::config::Config;

mod auth;
mod config;
mod metrics;
mod proxy;
mod utils;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -18,27 +22,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let state = Arc::new(RwLock::new(State::try_new()?));

let auth = auth::start(state.clone());
let metrics = metrics::start(state.clone());
let proxy_server = proxy::start(state.clone());

tokio::join!(auth, proxy_server);
tokio::join!(auth, metrics, proxy_server);

Ok(())
}

#[derive(Debug, Clone)]
pub struct State {
config: Config,
metrics: Metrics,
host_regex: Regex,
consumers: HashMap<String, Consumer>,
}
impl State {
pub fn try_new() -> Result<Self, Box<dyn Error>> {
let config = Config::new();
let metrics = Metrics::try_new(Registry::default())?;
let host_regex = Regex::new(r"(dmtr_[\w\d-]+)\.([\w]+)-([\w\d]+).+")?;
let consumers = HashMap::new();

Ok(Self {
config,
metrics,
host_regex,
consumers,
})
Expand Down
Loading
Loading