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

Finish instrumenting grpc service with OpenTelemetry #43

Merged
merged 1 commit into from
Oct 1, 2024
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
103 changes: 0 additions & 103 deletions fhevm-engine/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 fhevm-engine/coprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ actix-web = "4.9.0"
opentelemetry = "0.25"
opentelemetry-otlp = "0.25"
opentelemetry_sdk = { version = "0.25", features = ["rt-tokio"] }
tonic-tracing-opentelemetry = "0.21"

[dev-dependencies]
testcontainers = "0.21"
Expand Down
11 changes: 10 additions & 1 deletion fhevm-engine/coprocessor/src/db_queries.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use std::collections::{BTreeSet, HashMap};
use std::str::FromStr;

use crate::server::GrpcTracer;
use crate::types::{CoprocessorError, TfheTenantKeys};
use fhevm_engine_common::utils::{safe_deserialize_versioned, safe_deserialize_versioned_sks};
use opentelemetry::trace::Span;
use opentelemetry::KeyValue;
use sqlx::{query, Postgres};

/// Returns tenant id upon valid authorization request
pub async fn check_if_api_key_is_valid<T>(
req: &tonic::Request<T>,
pool: &sqlx::Pool<Postgres>,
ctx: &GrpcTracer,
) -> Result<i32, CoprocessorError> {
let mut outer_span = ctx.child_span("check_api_key_validity");
match req.metadata().get("authorization") {
Some(auth) => {
let auth_header = String::from_utf8(auth.as_bytes().to_owned())
Expand All @@ -28,19 +33,23 @@ pub async fn check_if_api_key_is_valid<T>(
Err(_) => return Err(CoprocessorError::Unauthorized),
};

let span = ctx.child_span("db_query_api_key");
let tenant = query!(
"SELECT tenant_id FROM tenants WHERE tenant_api_key = $1",
api_key
)
.fetch_all(pool)
.await
.map_err(Into::<CoprocessorError>::into)?;
drop(span);

if tenant.is_empty() {
return Err(CoprocessorError::Unauthorized);
}

return Ok(tenant[0].tenant_id);
let tenant_id = tenant[0].tenant_id;
outer_span.set_attribute(KeyValue::new("tenant_id", tenant_id as i64));
return Ok(tenant_id);
}
None => {
return Err(CoprocessorError::Unauthorized);
Expand Down
Loading