Skip to content

Commit

Permalink
Improve logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Mar 25, 2024
1 parent b97cde8 commit 55fad66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sessions/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use chrono::{DateTime, Utc};
use models::{bl_session, proposal};
use sea_orm::{ColumnTrait, Condition, DatabaseConnection, EntityTrait, QueryFilter};
use serde::Serialize;
use tracing::instrument;
use tracing::{info, instrument};

/// The GraphQL schema exposed by the service
pub type RootSchema = Schema<Query, EmptyMutation, EmptySubscription>;
Expand Down Expand Up @@ -98,6 +98,7 @@ impl Query {
OpaSessionParameters { proposal, visit },
)?)
.await?;
info!("Retrieving session");
Ok(bl_session::Entity::find()
.find_also_related(proposal::Entity)
.filter(
Expand Down
10 changes: 7 additions & 3 deletions sessions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::{
time::Duration,
};
use tokio::net::TcpListener;
use tracing::instrument;
use tracing::{info, instrument};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use url::Url;

Expand Down Expand Up @@ -108,8 +108,12 @@ async fn main() {
/// Creates a connection pool to access the database
#[instrument(skip(database_url))]
async fn setup_database(database_url: Url) -> Result<DatabaseConnection, TransactionError<DbErr>> {
let connection_options = ConnectOptions::new(database_url.to_string());
info!("Connecting to database at {database_url}");
let connection_options = ConnectOptions::new(database_url.to_string())
.sqlx_logging_level(tracing::log::LevelFilter::Debug)
.to_owned();
let connection = Database::connect(connection_options).await?;
info!("Database connection established: {connection:?}");
Ok(connection)
}

Expand All @@ -134,7 +138,7 @@ fn setup_router(schema: RootSchema) -> Router {
async fn serve(router: Router, port: u16) -> Result<(), std::io::Error> {
let socket_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port));
let listener = TcpListener::bind(socket_addr).await?;
println!("GraphiQL IDE: {}", socket_addr);
println!("Serving API & GraphQL UI at {}", socket_addr);
axum::serve(listener, router.into_make_service()).await?;
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion sessions/src/opa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_extra::headers::{authorization::Bearer, Authorization};
use serde::{Deserialize, Serialize};
use tracing::instrument;
use tracing::{info, instrument};
use url::Url;

/// Parametrers required by OPA to make the policy decision
Expand Down Expand Up @@ -44,6 +44,7 @@ pub struct OpaClient {
impl OpaClient {
/// Creates a new [`OpaClient`] bound to the provided endpoint [`Url`]
pub fn new(endpoint: Url) -> Self {
info!("Setting up OPA client at {endpoint}");
Self {
client: reqwest::Client::new(),
endpoint,
Expand Down

0 comments on commit 55fad66

Please sign in to comment.