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 logging module #298

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ tokio = { version = "^1.24.2", features = ["rt-multi-thread"], optional = true }
tokio-stream = { version = "0.1.11", features = ["net"], optional = true }
libloading = { version = "0.7.4", optional = true }
glob = { version = "0.3.0", optional = true }
log = "0.4.18"
env_logger = "0.10.0"

[dependencies.indradb-lib]
path = "../lib"
Expand Down
13 changes: 13 additions & 0 deletions proto/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
use tokio::sync::mpsc;
use tokio_stream::wrappers::{ReceiverStream, TcpListenerStream};
use tokio_stream::{Stream, StreamExt};
use tonic::transport::{Error as TonicTransportError, Server as TonicServer};

Check failure on line 14 in proto/src/server.rs

View workflow job for this annotation

GitHub Actions / stable on ubuntu-latest

Diff in /home/runner/work/indradb/indradb/proto/src/server.rs
use tonic::{Request, Response, Status, Streaming};

use log::{info};

const CHANNEL_CAPACITY: usize = 100;

fn send(tx: &mpsc::Sender<Result<crate::QueryOutputValue, Status>>, result: Result<crate::QueryOutputValue, Status>) {
Expand Down Expand Up @@ -194,16 +196,19 @@
#[tonic::async_trait]
impl<D: indradb::Datastore + Send + Sync + 'static> crate::indra_db_server::IndraDb for Server<D> {
async fn ping(&self, _: Request<()>) -> Result<Response<()>, Status> {
info!("Call ping");
Ok(Response::new(()))
}

async fn sync(&self, _: Request<()>) -> Result<Response<()>, Status> {
info!("Call sync");
let db = self.db.clone();
map_jh_indra_result(tokio::task::spawn_blocking(move || db.sync()).await)?;
Ok(Response::new(()))
}

async fn create_vertex(&self, request: Request<crate::Vertex>) -> Result<Response<crate::CreateResponse>, Status> {
info!("Call create_vertex");
let db = self.db.clone();
let vertex = map_conversion_result(request.into_inner().try_into())?;
let res = map_jh_indra_result(tokio::task::spawn_blocking(move || db.create_vertex(&vertex)).await)?;
Expand All @@ -214,13 +219,15 @@
&self,
request: Request<crate::Identifier>,
) -> Result<Response<crate::Uuid>, Status> {
info!("Call create_vertex_from_type");
let db = self.db.clone();
let t = map_conversion_result(request.into_inner().try_into())?;
let res = map_jh_indra_result(tokio::task::spawn_blocking(move || db.create_vertex_from_type(t)).await)?;
Ok(Response::new(res.into()))
}

async fn create_edge(&self, request: Request<crate::Edge>) -> Result<Response<crate::CreateResponse>, Status> {
info!("Call create_edge");
let db = self.db.clone();
let edge = map_conversion_result(request.into_inner().try_into())?;
let res = map_jh_indra_result(tokio::task::spawn_blocking(move || db.create_edge(&edge)).await)?;
Expand All @@ -229,6 +236,7 @@

type GetStream = Pin<Box<dyn Stream<Item = Result<crate::QueryOutputValue, Status>> + Send + Sync + 'static>>;
async fn get(&self, request: Request<crate::Query>) -> Result<Response<Self::GetStream>, Status> {
info!("Call get");
let db = self.db.clone();
let q: indradb::Query = map_conversion_result(request.into_inner().try_into())?;
let (tx, rx) = mpsc::channel(CHANNEL_CAPACITY);
Expand All @@ -245,20 +253,23 @@
}

async fn delete(&self, request: Request<crate::Query>) -> Result<Response<()>, Status> {
info!("Call delete");
let db = self.db.clone();
let q: indradb::Query = map_conversion_result(request.into_inner().try_into())?;
map_jh_indra_result(tokio::task::spawn_blocking(move || db.delete(q)).await)?;
Ok(Response::new(()))
}

async fn set_properties(&self, request: Request<crate::SetPropertiesRequest>) -> Result<Response<()>, Status> {
info!("Call set_properties");
let db = self.db.clone();
let (q, name, value) = map_conversion_result(request.into_inner().try_into())?;
map_jh_indra_result(tokio::task::spawn_blocking(move || db.set_properties(q, name, &value)).await)?;
Ok(Response::new(()))
}

async fn bulk_insert(&self, request: Request<Streaming<crate::BulkInsertItem>>) -> Result<Response<()>, Status> {
info!("Call bulk_insert");
let db = self.db.clone();

let items = {
Expand All @@ -277,6 +288,7 @@
}

async fn index_property(&self, request: Request<crate::IndexPropertyRequest>) -> Result<Response<()>, Status> {
info!("Call index_property");
let db = self.db.clone();

let name: indradb::Identifier = map_conversion_result(request.into_inner().try_into())?;
Expand All @@ -288,6 +300,7 @@
&self,
request: Request<crate::ExecutePluginRequest>,
) -> Result<Response<crate::ExecutePluginResponse>, Status> {
info!("Call execute_plugin");
let request = request.into_inner();
let arg = if let Some(arg) = request.arg {
map_conversion_result(arg.try_into())?
Expand Down
3 changes: 3 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ clap = "2.34.0"
tonic = "0.8.3"
tokio = { version = "1.24.2", features = ["macros", "rt-multi-thread"] }

log = "0.4.0"
env_logger = "0.9.0"

[dev-dependencies]
serde_json = "1.0.91"

Expand Down
7 changes: 6 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@

use crate::cli::CliDatastoreArgs;

use indradb_proto as proto;

Check failure on line 12 in server/src/main.rs

View workflow job for this annotation

GitHub Actions / stable on ubuntu-latest

Diff in /home/runner/work/indradb/indradb/server/src/main.rs
use tokio::net::TcpListener;

use log::{info};
use env_logger::{Builder,Env};

async fn run_server<D>(
datastore: indradb::Database<D>,
listener: TcpListener,
plugin_path: &Option<String>,
) -> Result<(), Box<dyn Error>>
where
D: indradb::Datastore + Send + Sync + 'static,

Check failure on line 24 in server/src/main.rs

View workflow job for this annotation

GitHub Actions / stable on ubuntu-latest

Diff in /home/runner/work/indradb/indradb/server/src/main.rs
{
Builder::from_env(Env::default().default_filter_or("info")).init();

let binding = listener.local_addr()?;
println!("grpc://{binding}");
info!("grpc://{binding}");

if let Some(plugin_path) = plugin_path {
unsafe {
Expand Down