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

add telemetry library #409

Merged
merged 6 commits into from
Feb 12, 2025
Merged
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
27 changes: 19 additions & 8 deletions backend/Cargo.lock

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

9 changes: 8 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[workspace]
members = ["argo-workflows-openapi", "graph-proxy", "sessionspaces"]
members = [
"argo-workflows-openapi",
"graph-proxy",
"sessionspaces",
"telemetry",
]
resolver = "2"

[workspace.dependencies]
anyhow = { version = "1.0.95" }
built = { version = "0.7.5" }
clap = { version = "4.5.26", features = ["derive", "env"] }
chrono = { version = "0.4.39" }
derive_more = { version = "1.0.0", features = [
Expand All @@ -20,6 +26,7 @@ reqwest = { version = "0.12.9", default-features = false, features = [
] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = { version = "1.0.137" }
thiserror = { version = "2.0.11" }
tracing = { version = "0.1.41" }
tokio = { version = "1.43.0", features = [
"macros",
Expand Down
19 changes: 12 additions & 7 deletions backend/Dockerfile.graph-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ COPY argo-workflows-openapi/build.rs argo-workflows-openapi/build.rs
COPY argo-workflows-openapi/src/lib.rs argo-workflows-openapi/src/lib.rs
COPY sessionspaces/Cargo.toml sessionspaces/Cargo.toml
COPY graph-proxy/Cargo.toml graph-proxy/
COPY telemetry/build.rs telemetry/Cargo.toml telemetry/
COPY Cargo.toml Cargo.lock ./

RUN mkdir sessionspaces/src \
&& echo "fn main() {}" > sessionspaces/src/main.rs

RUN mkdir graph-proxy/src \
&& echo "fn main() {}" > graph-proxy/src/main.rs \
&& touch --date @0 graph-proxy/src/main.rs \
&& cargo build --release --package graph-proxy
&& echo "fn main() {}" > graph-proxy/src/main.rs \
&& mkdir sessionspaces/src \
&& echo "fn main() {}" > sessionspaces/src/main.rs \
&& mkdir telemetry/src \
&& echo "fn prebuild() {}" > telemetry/src/lib.rs

RUN cargo build --release --package telemetry

RUN touch --date @0 graph-proxy/src/main.rs \
&& cargo build --release --package graph-proxy

COPY . .

RUN touch graph-proxy/src/main.rs \
&& cargo auditable build --release --manifest-path graph-proxy/Cargo.toml
&& cargo auditable build --release --package graph-proxy

FROM gcr.io/distroless/cc-debian12@sha256:b7550f0b15838de14c564337eef2b804ba593ae55d81ca855421bd52f19bb480 AS deploy

Expand Down
17 changes: 12 additions & 5 deletions backend/Dockerfile.sessionspaces
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ RUN cargo install cargo-auditable
COPY argo-workflows-openapi/Cargo.toml argo-workflows-openapi/Cargo.toml
COPY graph-proxy/Cargo.toml graph-proxy/
COPY sessionspaces/Cargo.toml sessionspaces/
COPY telemetry/build.rs telemetry/build.rs
COPY telemetry/Cargo.toml telemetry/Cargo.toml
COPY Cargo.toml Cargo.lock ./

RUN mkdir argo-workflows-openapi/src \
&& touch argo-workflows-openapi/src/lib.rs \
&& mkdir graph-proxy/src \
&& echo "fn main() {}" > graph-proxy/src/main.rs
&& echo "fn main() {}" > graph-proxy/src/main.rs \
&& mkdir sessionspaces/src \
&& echo "fn main() {}" > sessionspaces/src/main.rs \
&& mkdir telemetry/src \
&& echo "fn prebuild() {}" > telemetry/src/lib.rs

RUN mkdir sessionspaces/src && echo "fn main() {}" > sessionspaces/src/main.rs \
&& touch --date @0 sessionspaces/src/main.rs \
&& cargo build --release --package sessionspaces
RUN cargo build --release --package telemetry

RUN touch --date @0 sessionspaces/src/main.rs \
&& cargo build --release --package sessionspaces

COPY . .

RUN touch sessionspaces/src/main.rs \
&& cargo auditable build --release --manifest-path sessionspaces/Cargo.toml
&& cargo auditable build --release --package sessionspaces

FROM gcr.io/distroless/cc-debian12@sha256:b7550f0b15838de14c564337eef2b804ba593ae55d81ca855421bd52f19bb480 AS deploy

Expand Down
2 changes: 1 addition & 1 deletion backend/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]

[bans.workspace-dependencies]
duplicates = "deny"
include-path-dependencies = true
include-path-dependencies = false
unused = "deny"
12 changes: 2 additions & 10 deletions backend/graph-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,16 @@ derive_more = { workspace = true }
dotenvy = { workspace = true }
lazy_static = { version = "1.5.0" }
mime_guess = "2.0.5"
opentelemetry = { version = "0.27.1" }
opentelemetry-otlp = { version = "0.27.0", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry_sdk = { version = "0.27.1", features = ["rt-tokio"] }
regex = "1.11.1"
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { version = "2.0.11" }
thiserror = { workspace = true }
telemetry = { path = "../telemetry" }
tokio = { workspace = true }
tower-http = { version = "0.6.2", features = ["cors"] }
tracing = { workspace = true }
tracing-opentelemetry = { version = "0.28.0" }
tracing-subscriber = { workspace = true }
url = { workspace = true }

[dev-dependencies]
mockito = "1.6.1"

[build-dependencies]
built = { version = "0.7.5" }
30 changes: 11 additions & 19 deletions backend/graph-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

/// GraphQL resolvers
mod graphql;
/// OpenTelemetry setup and configuration
mod telemetry;

use async_graphql::{http::GraphiQLSource, SDLExportOptions};
use axum::{response::Html, routing::get, Router};
Expand All @@ -20,7 +18,7 @@ use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
};
use telemetry::setup_telemetry;
use telemetry::{setup_telemetry, TelemetryConfig};
use tokio::net::TcpListener;
use tower_http::cors::{AllowOrigin, CorsLayer};
use tracing::{info, instrument, Level};
Expand Down Expand Up @@ -51,15 +49,9 @@ struct ServeArgs {
/// The endpoint at which the GraphQL API should be served
#[arg(long, env = "PREFIX_PATH", default_value = "/")]
prefix_path: String,
/// The endpoint to send OTLP metrics to
#[arg(short, long, env = "METRICS_ENDPOINT")]
metrics_endpoint: Option<Url>,
/// The endpoint to send OTLP traces to
#[arg(short, long, env = "TRACING_ENDPOINT")]
tracing_endpoint: Option<Url>,
/// The minimum telemetry level
#[arg(short, long, env="TELEMETRY_LEVEL", default_value_t=Level::INFO)]
telemetry_level: Level,
/// Args to setup telemetry
#[command(flatten)]
telemetry_config: TelemetryConfig,
/// Regexes of Cross Origin Resource Sharing (CORS) Origins to allow
#[arg(long, env="CORS_ALLOW", value_delimiter=' ', num_args=1..)]
cors_allow: Option<Vec<Regex>>,
Expand All @@ -84,12 +76,7 @@ async fn main() {

match args {
Cli::Serve(args) => {
let _otlp_guard = setup_telemetry(
args.metrics_endpoint.clone(),
args.tracing_endpoint.clone(),
args.telemetry_level,
)
.unwrap();
let _otlp_guard = setup_telemetry(args.telemetry_config.clone()).unwrap();
info!(?args, "Starting GraphQL Server");
let schema = root_schema_builder()
.data(ArgoServerUrl(args.argo_server_url))
Expand All @@ -98,7 +85,12 @@ async fn main() {
serve(router, args.host, args.port).await.unwrap();
}
Cli::Schema(args) => {
setup_telemetry(None, None, Level::INFO).unwrap();
setup_telemetry(TelemetryConfig {
metrics_endpoint: None,
tracing_endpoint: None,
telemetry_level: Level::INFO,
})
.unwrap();
info!(?args, "Generating GraphQL schema");
let schema = root_schema_builder().finish();
let schema_string = schema.sdl_with_options(SDLExportOptions::new().federation());
Expand Down
2 changes: 1 addition & 1 deletion backend/sessionspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ sqlx = { version = "0.8.3", features = [
"time",
] }
strum = { version = "0.26.3", features = ["derive"] }
telemetry = { path = "../telemetry" }
time = { version = "0.3.37" }
tokio = { workspace = true }
tower = { version = "0.5.2", features = ["limit", "util"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }

[dev-dependencies]
Expand Down
11 changes: 5 additions & 6 deletions backend/sessionspaces/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ldap3::LdapConnAsync;
use resources::{create_configmap, create_namespace, delete_namespace};
use sqlx::mysql::MySqlPoolOptions;
use std::{collections::BTreeSet, time::Duration};
use telemetry::{setup_telemetry, TelemetryConfig};
use tokio::time::interval;
use tracing::{info, warn};
use url::Url;
Expand All @@ -35,19 +36,17 @@ struct Cli {
/// The maximum allowable k8s API requests per second
#[clap(long, env, default_value = "10")]
request_rate: Option<u64>,
/// The [`tracing::Level`] to log at
#[arg(long, env="LOG_LEVEL", default_value_t=tracing::Level::INFO)]
log_level: tracing::Level,
/// Args to setup telemetry
#[command(flatten)]
telemetry_config: TelemetryConfig,
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
dotenvy::dotenv().ok();
let args = Cli::parse();

tracing_subscriber::fmt()
.with_max_level(args.log_level)
.init();
let _otlp_guard = setup_telemetry(args.telemetry_config).unwrap();

let ispyb_pool = MySqlPoolOptions::new()
.connect(args.database_url.as_str())
Expand Down
23 changes: 23 additions & 0 deletions backend/telemetry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "telemetry"
build = "build.rs"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
description = "A telemetry library for collecting and exporting metrics and traces."

[dependencies]
clap = { workspace = true }
opentelemetry = { version = "0.27.1" }
opentelemetry-otlp = { version = "0.27.0", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry_sdk = { version = "0.27.1", features = ["rt-tokio"] }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing-opentelemetry = { version = "0.28.0" }
tracing-subscriber = { version = "0.3.19" }
url = { workspace = true }

[build-dependencies]
built = { version = "0.7.5" }

File renamed without changes.
Loading