diff --git a/.gitignore b/.gitignore index ccb96162d8..b67374fde3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ crates/*/Cargo.lock .idea *.iml .vscode + +# Docs +/docs/node_modules/ +/docs/.cache/ diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5b1cf5a2..39eb0f4ebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm --> + +# [v0.1.0-preview.1] (unreleased) - 2022-mm-dd +## ❗ BREAKING ❗ +## 🚀 Features +## 🐛 Fixes +- **Log and error message formatting** ([PR #721](https://github.com/apollographql/router/pull/721)) + + Logs and error messages in Rust begin with lower case and do not have trailing punctuation. The codebase is now consistent with this scheme. +## 🛠 Maintenance +## 📚 Documentation + # [v0.1.0-preview.0] - 2022-03-22 ## 🎉 **The Apollo Router has graduated to its Preview phase!** 🎉 @@ -29,6 +40,7 @@ For more information on what's expected at this stage, please see our [release s ## 🐛 Fixes - **Header propagation by `name` only fixed** ([PR #709](https://github.com/apollographql/router/pull/709)) + Previously `rename` and `default` values were required (even though they were correctly not flagged as required in the json schema). The following will now work: ```yaml diff --git a/apollo-router-core/src/error.rs b/apollo-router-core/src/error.rs index 3ff1b2556c..8b223c3789 100644 --- a/apollo-router-core/src/error.rs +++ b/apollo-router-core/src/error.rs @@ -17,37 +17,37 @@ use typed_builder::TypedBuilder; #[serde(tag = "type")] #[ignore_extra_doc_attributes] pub enum FetchError { - /// Query references unknown service '{service}'. + /// query references unknown service '{service}' ValidationUnknownServiceError { /// The service that was unknown. service: String, }, - /// Invalid type for variable: '{name}' + /// invalid type for variable: '{name}' ValidationInvalidTypeVariable { /// Name of the variable. name: String, }, - /// Query could not be planned: {reason} + /// query could not be planned: {reason} ValidationPlanningError { /// The failure reason. reason: String, }, - /// Response was malformed: {reason} + /// response was malformed: {reason} MalformedResponse { /// The reason the serialization failed. reason: String, }, - /// Service '{service}' returned no response. + /// service '{service}' returned no response. SubrequestNoResponse { /// The service that returned no response. service: String, }, - /// Service '{service}' response was malformed: {reason} + /// service '{service}' response was malformed: {reason} SubrequestMalformedResponse { /// The service that responded with the malformed response. service: String, @@ -56,7 +56,7 @@ pub enum FetchError { reason: String, }, - /// Service '{service}' returned a PATCH response which was not expected. + /// service '{service}' returned a PATCH response which was not expected SubrequestUnexpectedPatchResponse { /// The service that returned the PATCH response. service: String, @@ -64,7 +64,7 @@ pub enum FetchError { /// HTTP fetch failed from '{service}': {reason} /// - /// Note that this relates to a transport error and not a GraphQL error. + /// note that this relates to a transport error and not a GraphQL error SubrequestHttpError { /// The service failed. service: String, @@ -73,16 +73,16 @@ pub enum FetchError { reason: String, }, - /// Subquery requires field '{field}' but it was not found in the current response. + /// subquery requires field '{field}' but it was not found in the current response ExecutionFieldNotFound { /// The field that is not found. field: String, }, - /// Invalid content: {reason} + /// invalid content: {reason} ExecutionInvalidContent { reason: String }, - /// Could not find path: {reason} + /// could not find path: {reason} ExecutionPathNotFound { reason: String }, } diff --git a/apollo-router-core/src/query_cache.rs b/apollo-router-core/src/query_cache.rs index b59bded755..40cc36688a 100644 --- a/apollo-router-core/src/query_cache.rs +++ b/apollo-router-core/src/query_cache.rs @@ -23,7 +23,7 @@ impl CacheResolver>> for QueryCacheResolver { // Silently ignore cancelled tasks (never happen for blocking tasks). Err(err) if err.is_cancelled() => None, Err(err) => { - failfast_debug!("Parsing query task failed: {}", err); + failfast_debug!("parsing query task failed: {}", err); None } }; @@ -47,7 +47,7 @@ impl QueryCache { match self.cm.get(key).await { Ok(v) => v, Err(err) => { - failfast_debug!("Parsing query task failed: {}", err); + failfast_debug!("parsing query task failed: {}", err); None } } diff --git a/apollo-router-core/src/query_planner/mod.rs b/apollo-router-core/src/query_planner/mod.rs index 565861182c..c9facf5744 100644 --- a/apollo-router-core/src/query_planner/mod.rs +++ b/apollo-router-core/src/query_planner/mod.rs @@ -110,7 +110,7 @@ impl PlanNode { parent_value: &'a Value, ) -> future::BoxFuture<(Value, Vec)> { Box::pin(async move { - tracing::trace!("Executing plan:\n{:#?}", self); + tracing::trace!("executing plan:\n{:#?}", self); let mut value; let mut errors; @@ -440,7 +440,7 @@ pub(crate) mod fetch { // because we need to take ownership of the inner value if let Value::Object(mut map) = data { if let Some(entities) = map.remove("_entities") { - tracing::trace!("Received entities: {:?}", &entities); + tracing::trace!("received entities: {:?}", &entities); if let Value::Array(array) = entities { let mut value = Value::default(); diff --git a/apollo-router-core/src/query_planner/router_bridge_query_planner.rs b/apollo-router-core/src/query_planner/router_bridge_query_planner.rs index 765347342d..85da32cbf5 100644 --- a/apollo-router-core/src/query_planner/router_bridge_query_planner.rs +++ b/apollo-router-core/src/query_planner/router_bridge_query_planner.rs @@ -47,11 +47,11 @@ impl QueryPlanner for RouterBridgeQueryPlanner { match planner_result { PlannerResult::QueryPlan { node: Some(node) } => Ok(Arc::new(QueryPlan { root: node })), PlannerResult::QueryPlan { node: None } => { - failfast_debug!("Empty query plan"); + failfast_debug!("empty query plan"); Err(QueryPlannerError::EmptyPlan) } PlannerResult::Other => { - failfast_debug!("Unhandled planner result"); + failfast_debug!("unhandled planner result"); Err(QueryPlannerError::UnhandledPlannerResult) } } diff --git a/apollo-router-core/src/services/reqwest_subgraph_service.rs b/apollo-router-core/src/services/reqwest_subgraph_service.rs index 1b58b4dc1b..bb29c706f0 100644 --- a/apollo-router-core/src/services/reqwest_subgraph_service.rs +++ b/apollo-router-core/src/services/reqwest_subgraph_service.rs @@ -128,9 +128,9 @@ impl reqwest_middleware::Middleware for LoggingMiddleware { extensions: &mut task_local_extensions::Extensions, next: reqwest_middleware::Next<'_>, ) -> reqwest_middleware::Result { - tracing::trace!("Request to service {}: {:?}", self.service, req); + tracing::trace!("request to service {}: {:?}", self.service, req); let res = next.run(req, extensions).await; - tracing::trace!("Response from service {}: {:?}", self.service, res); + tracing::trace!("response from service {}: {:?}", self.service, res); res } } diff --git a/apollo-router-core/src/spec/query.rs b/apollo-router-core/src/spec/query.rs index 7308b65da0..48a669fe50 100644 --- a/apollo-router-core/src/spec/query.rs +++ b/apollo-router-core/src/spec/query.rs @@ -57,7 +57,7 @@ impl Query { failfast_debug!("can't find operation for {:?}", operation_name); } } else { - failfast_debug!("Invalid type for data in response."); + failfast_debug!("invalid type for data in response."); } } @@ -73,7 +73,7 @@ impl Query { .collect::>(); if !errors.is_empty() { - failfast_debug!("Parsing error(s): {}", errors.join(", ")); + failfast_debug!("parsing error(s): {}", errors.join(", ")); return None; } @@ -377,7 +377,7 @@ impl Query { } } else { // the fragment should have been already checked with the schema - failfast_debug!("Missing fragment named: {}", name); + failfast_debug!("missing fragment named: {}", name); } } } @@ -458,7 +458,7 @@ impl Query { self.apply_selection_set(&fragment.selection_set, input, output, schema)?; } else { // the fragment should have been already checked with the schema - failfast_debug!("Missing fragment named: {}", name); + failfast_debug!("missing fragment named: {}", name); } } } diff --git a/apollo-router/src/apollo_telemetry.rs b/apollo-router/src/apollo_telemetry.rs index 203cde4c54..72fa7a9668 100644 --- a/apollo-router/src/apollo_telemetry.rs +++ b/apollo-router/src/apollo_telemetry.rs @@ -450,7 +450,7 @@ fn stats_report_key(op_name: &opentelemetry::Value, query: &str) -> String { // If we can't parse the query, we definitely can't normalize it, so // just return the appropriate error. if ast.errors().len() > 0 { - tracing::warn!("Could not parse query: {}", query); + tracing::warn!("could not parse query: {}", query); return GRAPHQL_PARSE_FAILURE.to_string(); } let doc = ast.document(); @@ -487,7 +487,7 @@ fn stats_report_key(op_name: &opentelemetry::Value, query: &str) -> String { let mut required_definitions: Vec<_> = doc.definitions().into_iter().filter(filter).collect(); tracing::debug!("required definitions: {:?}", required_definitions); if required_definitions.len() != 1 { - tracing::warn!("Could not find required definition: {}", query); + tracing::warn!("could not find required definition: {}", query); return GRAPHQL_UNKNOWN_OPERATION_NAME.to_string(); } tracing::debug!( diff --git a/apollo-router/src/configuration/mod.rs b/apollo-router/src/configuration/mod.rs index c9f617c03c..20df6cda47 100644 --- a/apollo-router/src/configuration/mod.rs +++ b/apollo-router/src/configuration/mod.rs @@ -21,31 +21,31 @@ use typed_builder::TypedBuilder; /// Configuration error. #[derive(Debug, Error, Display)] pub enum ConfigurationError { - /// Could not read secret from file: {0} + /// could not read secret from file: {0} CannotReadSecretFromFile(std::io::Error), - /// Could not read secret from environment variable: {0} + /// could not read secret from environment variable: {0} CannotReadSecretFromEnv(std::env::VarError), - /// Missing environment variable: {0} + /// missing environment variable: {0} MissingEnvironmentVariable(String), - /// Invalid environment variable: {0} + /// invalid environment variable: {0} InvalidEnvironmentVariable(String), - /// Could not setup OTLP tracing: {0} + /// could not setup OTLP tracing: {0} OtlpTracing(opentelemetry::trace::TraceError), - /// The configuration could not be loaded because it requires the feature {0:?} + /// the configuration could not be loaded because it requires the feature {0:?} MissingFeature(&'static str), - /// Unknown plugin {0} + /// unknown plugin {0} PluginUnknown(String), - /// Plugin {plugin} could not be configured: {error} + /// plugin {plugin} could not be configured: {error} PluginConfiguration { plugin: String, error: String }, - /// Plugin {plugin} could not be started: {error} + /// plugin {plugin} could not be started: {error} PluginStartup { plugin: String, error: String }, - /// Plugin {plugin} could not be stopped: {error} + /// plugin {plugin} could not be stopped: {error} PluginShutdown { plugin: String, error: String }, - /// Unknown layer {0} + /// unknown layer {0} LayerUnknown(String), - /// Layer {layer} could not be configured: {error} + /// layer {layer} could not be configured: {error} LayerConfiguration { layer: String, error: String }, - /// The configuration contained errors. + /// the configuration contained errors InvalidConfiguration, } diff --git a/apollo-router/src/http_server_factory.rs b/apollo-router/src/http_server_factory.rs index 2d8717488c..818ba9aff6 100644 --- a/apollo-router/src/http_server_factory.rs +++ b/apollo-router/src/http_server_factory.rs @@ -124,7 +124,7 @@ impl HttpServerHandle { let handle = factory .create(router, Arc::clone(&configuration), listener) .await?; - tracing::debug!("Restarted on {}", handle.listen_address()); + tracing::debug!("restarted on {}", handle.listen_address()); Ok(handle) } diff --git a/apollo-router/src/lib.rs b/apollo-router/src/lib.rs index f1cf613ce5..6467ba08a9 100644 --- a/apollo-router/src/lib.rs +++ b/apollo-router/src/lib.rs @@ -28,6 +28,7 @@ pub use executable::{main, rt_main}; use futures::channel::{mpsc, oneshot}; use futures::prelude::*; use futures::FutureExt; +use std::fmt::{Display, Formatter}; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::task::{Context, Poll}; @@ -42,43 +43,43 @@ type SchemaStream = Pin + Send>>; /// Error types for FederatedServer. #[derive(Error, Debug, DisplayDoc)] pub enum FederatedServerError { - /// Failed to start server. + /// failed to start server StartupError, - /// Failed to stop HTTP Server. + /// failed to stop HTTP Server HttpServerLifecycleError, - /// Configuration was not supplied. + /// configuration was not supplied NoConfiguration, - /// Schema was not supplied. + /// schema was not supplied NoSchema, - /// Could not deserialize configuration: {0} + /// could not deserialize configuration: {0} DeserializeConfigError(serde_yaml::Error), - /// Could not read configuration: {0} + /// could not read configuration: {0} ReadConfigError(std::io::Error), - /// Could not read schema: {0} + /// could not read schema: {0} ReadSchemaError(graphql::SchemaError), - /// Could not create the HTTP pipeline: {0} + /// could not create the HTTP pipeline: {0} ServiceCreationError(tower::BoxError), - /// Could not create the HTTP server: {0} + /// could not create the HTTP server: {0} ServerCreationError(std::io::Error), - /// Could not configure spaceport: {0} + /// could not configure spaceport: {0} ServerSpaceportError(tokio::sync::mpsc::error::SendError), - /// No reload handle available + /// no reload handle available NoReloadTracingHandleError, - /// Could not set global subscriber: {0} + /// could not set global subscriber: {0} SetGlobalSubscriberError(SetGlobalDefaultError), - /// Could not reload tracing layer: {0} + /// could not reload tracing layer: {0} ReloadTracingLayerError(ReloadError), } @@ -483,6 +484,17 @@ pub enum State { Errored, } +impl Display for State { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + State::Startup => write!(f, "startup"), + State::Running { .. } => write!(f, "running"), + State::Stopped => write!(f, "stopped"), + State::Errored => write!(f, "errored"), + } + } +} + /// A handle that allows the client to await for various server events. pub struct FederatedServerHandle { result: Pin> + Send>>, @@ -549,16 +561,16 @@ impl FederatedServerHandle { .for_each(|state| { match state { State::Startup => { - tracing::info!(r#"Starting Apollo Router"#) + tracing::info!("starting Apollo Router") } State::Running { address, .. } => { - tracing::info!("Listening on {} 🚀", address) + tracing::info!("listening on {} 🚀", address) } State::Stopped => { - tracing::info!("Stopped") + tracing::info!("stopped") } State::Errored => { - tracing::info!("Stopped with error") + tracing::info!("stopped with error") } } future::ready(()) diff --git a/apollo-router/src/plugins/override_url.rs b/apollo-router/src/plugins/override_url.rs index ed211ca630..ab71f61eea 100644 --- a/apollo-router/src/plugins/override_url.rs +++ b/apollo-router/src/plugins/override_url.rs @@ -14,7 +14,6 @@ impl Plugin for OverrideSubgraphUrl { type Config = HashMap; fn new(configuration: Self::Config) -> Result { - tracing::debug!("OverrideSubgraphUrl {:#?}!", configuration); Ok(OverrideSubgraphUrl { urls: configuration, }) diff --git a/apollo-router/src/plugins/rhai.rs b/apollo-router/src/plugins/rhai.rs index a4e8049ea9..00314ad147 100644 --- a/apollo-router/src/plugins/rhai.rs +++ b/apollo-router/src/plugins/rhai.rs @@ -140,7 +140,6 @@ impl Plugin for Rhai { type Config = Conf; fn new(configuration: Self::Config) -> Result { - tracing::debug!("RHAI {:#?}!", configuration.filename); let engine = Arc::new(Rhai::new_rhai_engine()); let ast = engine.compile_file(configuration.filename)?; Ok(Self { ast, engine }) @@ -157,7 +156,7 @@ impl Plugin for Rhai { .any(|fn_def| fn_def.name == FUNCTION_NAME_REQUEST) { let this = self.clone(); - tracing::debug!("RHAI plugin: router_service_request function found"); + tracing::debug!("router_service_request function found"); service = service .map_request(move |mut request: RouterRequest| { @@ -187,7 +186,7 @@ impl Plugin for Rhai { .iter_fn_def() .any(|fn_def| fn_def.name == FUNCTION_NAME_REQUEST) { - tracing::debug!("RHAI plugin: {} function found", FUNCTION_NAME_REQUEST); + tracing::debug!("{} function found", FUNCTION_NAME_REQUEST); let this = self.clone(); service = service @@ -208,7 +207,7 @@ impl Plugin for Rhai { .iter_fn_def() .any(|fn_def| fn_def.name == FUNCTION_NAME_RESPONSE) { - tracing::debug!("RHAI plugin: {} function found", FUNCTION_NAME_RESPONSE); + tracing::debug!("{} function found", FUNCTION_NAME_RESPONSE); let this = self.clone(); service = service .map_response(move |mut response: QueryPlannerResponse| { @@ -247,7 +246,7 @@ impl Plugin for Rhai { .iter_fn_def() .any(|fn_def| fn_def.name == FUNCTION_NAME_REQUEST) { - tracing::debug!("RHAI plugin: {} function found", FUNCTION_NAME_REQUEST); + tracing::debug!("{} function found", FUNCTION_NAME_REQUEST); let this = self.clone(); service = service @@ -279,7 +278,7 @@ impl Plugin for Rhai { .iter_fn_def() .any(|fn_def| fn_def.name == FUNCTION_NAME_REQUEST) { - tracing::debug!("RHAI plugin: {} function found", FUNCTION_NAME_REQUEST); + tracing::debug!("{} function found", FUNCTION_NAME_REQUEST); let this = self.clone(); service = service diff --git a/apollo-router/src/plugins/telemetry.rs b/apollo-router/src/plugins/telemetry.rs index 9a82b95403..d5b6c261e0 100644 --- a/apollo-router/src/plugins/telemetry.rs +++ b/apollo-router/src/plugins/telemetry.rs @@ -227,11 +227,9 @@ impl Plugin for Telemetry { } fn new(mut configuration: Self::Config) -> Result { - tracing::debug!("Reporting configuration {:?}!", configuration); - // Graph can only be set via env variables. configuration.graph = studio_graph(); - + tracing::debug!("Apollo graph configuration: {:?}", configuration.graph); // Studio Agent Spaceport listener let (tx, mut rx) = tokio::sync::mpsc::channel::(1); @@ -301,11 +299,6 @@ impl Plugin for Telemetry { impl Telemetry { fn try_build_layer(&self) -> Result { - tracing::debug!( - "spaceport: {:?}, graph: {:?}", - self.config.spaceport, - self.config.graph - ); let spaceport_config = &self.config.spaceport; let graph_config = &self.config.graph; @@ -330,7 +323,7 @@ impl Telemetry { let apollo_exporter = Self::apollo_exporter_pipeline(spaceport_config, graph_config).install_batch()?; let agent = tracing_opentelemetry::layer().with_tracer(apollo_exporter); - tracing::debug!("Adding agent telemetry"); + tracing::debug!("adding agent telemetry"); Ok(Box::new(agent)) } else { // If we don't have any reporting to do, just put in place our BaseLayer diff --git a/apollo-router/src/router_factory.rs b/apollo-router/src/router_factory.rs index 8d316a45f5..5671afd673 100644 --- a/apollo-router/src/router_factory.rs +++ b/apollo-router/src/router_factory.rs @@ -90,29 +90,36 @@ impl RouterServiceFactory for YamlRouterServiceFactory { ) -> PluggableRouterServiceBuilder { let plugin_registry = apollo_router_core::plugins(); match plugin_registry.get(name.as_str()) { - Some(factory) => match factory.create_instance(configuration) { - Ok(mut plugin) => { - tracing::debug!("Starting plugin: {}", name); - match plugin.startup().await { - Ok(_v) => { - tracing::debug!("Started plugin: {}", name); - builder = builder.with_dyn_plugin(plugin); - } - Err(err) => { - (*errors).push(ConfigurationError::PluginStartup { - plugin: name, - error: err.to_string(), - }); + Some(factory) => { + tracing::debug!( + "creating plugin: '{}' with configuration:\n{:#}", + name, + configuration + ); + match factory.create_instance(configuration) { + Ok(mut plugin) => { + tracing::debug!("starting plugin: {}", name); + match plugin.startup().await { + Ok(_v) => { + tracing::debug!("started plugin: {}", name); + builder = builder.with_dyn_plugin(plugin); + } + Err(err) => { + (*errors).push(ConfigurationError::PluginStartup { + plugin: name, + error: err.to_string(), + }); + } } } + Err(err) => { + (*errors).push(ConfigurationError::PluginConfiguration { + plugin: name, + error: err.to_string(), + }); + } } - Err(err) => { - (*errors).push(ConfigurationError::PluginConfiguration { - plugin: name, - error: err.to_string(), - }); - } - }, + } None => { (*errors).push(ConfigurationError::PluginUnknown(name)); } @@ -129,15 +136,15 @@ impl RouterServiceFactory for YamlRouterServiceFactory { if !errors.is_empty() { // Shutdown all the plugins we started for plugin in builder.plugins().iter_mut().rev() { - tracing::debug!("Stopping plugin: {}", plugin.name()); + tracing::debug!("stopping plugin: {}", plugin.name()); if let Err(err) = plugin.shutdown().await { // If we can't shutdown a plugin, we terminate the router since we can't // assume that it is safe to continue. - tracing::error!("Could not stop plugin: {}, error: {}", plugin.name(), err); - tracing::error!("Terminating router..."); + tracing::error!("could not stop plugin: {}, error: {}", plugin.name(), err); + tracing::error!("terminating router..."); std::process::exit(1); } else { - tracing::debug!("Stopped plugin: {}", plugin.name()); + tracing::debug!("stopped plugin: {}", plugin.name()); } } for error in errors { @@ -218,17 +225,15 @@ mod test { type Config = Conf; async fn startup(&mut self) -> Result<(), BoxError> { - tracing::info!("starting: {}", stringify!(AlwaysStartsAndStopsPlugin)); Ok(()) } async fn shutdown(&mut self) -> Result<(), BoxError> { - tracing::info!("shutting down: {}", stringify!(AlwaysStartsAndStopsPlugin)); Ok(()) } fn new(configuration: Self::Config) -> Result { - tracing::info!("Hello {}!", configuration.name); + tracing::debug!("{}", configuration.name); Ok(AlwaysStartsAndStopsPlugin {}) } } @@ -249,17 +254,15 @@ mod test { type Config = Conf; async fn startup(&mut self) -> Result<(), BoxError> { - tracing::info!("starting: {}", stringify!(AlwaysFailsToStartPlugin)); Err(Box::new(PluginError {})) } async fn shutdown(&mut self) -> Result<(), BoxError> { - tracing::info!("shutting down: {}", stringify!(AlwaysFailsToStartPlugin)); Ok(()) } fn new(configuration: Self::Config) -> Result { - tracing::info!("Hello {}!", configuration.name); + tracing::debug!("{}", configuration.name); Ok(AlwaysFailsToStartPlugin {}) } } @@ -280,17 +283,15 @@ mod test { type Config = Conf; async fn startup(&mut self) -> Result<(), BoxError> { - tracing::info!("starting: {}", stringify!(AlwaysFailsToStopPlugin)); Ok(()) } async fn shutdown(&mut self) -> Result<(), BoxError> { - tracing::info!("shutting down: {}", stringify!(AlwaysFailsToStopPlugin)); Err(Box::new(PluginError {})) } fn new(configuration: Self::Config) -> Result { - tracing::info!("Hello {}!", configuration.name); + tracing::debug!("{}", configuration.name); Ok(AlwaysFailsToStopPlugin {}) } } @@ -311,20 +312,15 @@ mod test { type Config = Conf; async fn startup(&mut self) -> Result<(), BoxError> { - tracing::info!("starting: {}", stringify!(AlwaysFailsToStartAndStopPlugin)); Err(Box::new(PluginError {})) } async fn shutdown(&mut self) -> Result<(), BoxError> { - tracing::info!( - "shutting down: {}", - stringify!(AlwaysFailsToStartAndStopPlugin) - ); Err(Box::new(PluginError {})) } fn new(configuration: Self::Config) -> Result { - tracing::info!("Hello {}!", configuration.name); + tracing::debug!("{}", configuration.name); Ok(AlwaysFailsToStartAndStopPlugin {}) } } diff --git a/apollo-router/src/state_machine.rs b/apollo-router/src/state_machine.rs index c8989eeb8e..f8aa6b70ef 100644 --- a/apollo-router/src/state_machine.rs +++ b/apollo-router/src/state_machine.rs @@ -9,6 +9,7 @@ use apollo_router_core::prelude::*; use apollo_router_core::Schema; use futures::channel::mpsc; use futures::prelude::*; +use std::fmt::{Display, Formatter}; use std::sync::Arc; use Event::{NoMoreConfiguration, NoMoreSchema, Shutdown}; @@ -32,6 +33,17 @@ enum PrivateState { Errored(FederatedServerError), } +impl Display for PrivateState { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + PrivateState::Startup { .. } => write!(f, "startup"), + PrivateState::Running { .. } => write!(f, "running"), + PrivateState::Stopped => write!(f, "stopped"), + PrivateState::Errored { .. } => write!(f, "errored"), + } + } +} + /// A state machine that responds to events to control the lifecycle of the server. /// The server is in startup state until both configuration and schema are supplied. /// If config and schema are not supplied then the machine ends with an error. @@ -87,7 +99,7 @@ where mut self, mut messages: impl Stream + Unpin, ) -> Result<(), FederatedServerError> { - tracing::debug!("Starting"); + tracing::debug!("starting"); let mut state = Startup { configuration: None, schema: None, @@ -133,7 +145,7 @@ where // Running: Handle shutdown. (Running { server_handle, .. }, Shutdown) => { - tracing::debug!("Shutting down"); + tracing::debug!("shutting down"); match server_handle.shutdown().await { Ok(_) => Stopped, Err(err) => Errored(err), @@ -150,7 +162,7 @@ where }, UpdateSchema(new_schema), ) => { - tracing::info!("Reloading schema"); + tracing::info!("reloading schema"); self.reload_server( configuration, schema, @@ -173,7 +185,7 @@ where }, UpdateConfiguration(new_configuration), ) => { - tracing::info!("Reloading configuration"); + tracing::info!("reloading configuration"); self.reload_server( configuration, schema, @@ -188,7 +200,7 @@ where // Anything else we don't care about (state, message) => { - tracing::debug!("Ignoring message transition {:?}", message); + tracing::debug!("ignoring message transition {:?}", message); state } }; @@ -198,7 +210,7 @@ where >::notify_state_listener(&mut state_listener, new_public_state) .await; } - tracing::debug!("Transitioned to state {:?}", &new_state); + tracing::debug!("transitioned to state {}", &new_state); state = new_state; // If we've errored then exit even if there are potentially more messages @@ -206,13 +218,13 @@ where break; } } - tracing::debug!("Stopped"); + tracing::debug!("stopped"); match state { Stopped => Ok(()), Errored(err) => Err(err), _ => { - panic!("Must finish on stopped or errored state.") + panic!("must finish on stopped or errored state") } } } @@ -238,7 +250,7 @@ where schema: Some(schema), } = state { - tracing::debug!("Starting http"); + tracing::debug!("starting http"); let configuration = Arc::new(configuration); let schema = Arc::new(schema); let router = self diff --git a/apollo-spaceport/src/server.rs b/apollo-spaceport/src/server.rs index 4b299e1262..0b82155102 100644 --- a/apollo-spaceport/src/server.rs +++ b/apollo-spaceport/src/server.rs @@ -112,7 +112,7 @@ impl ReportSpaceport { } }, _ = interval.tick() => { - tracing::debug!("spaceport ticked"); + tracing::trace!("spaceport ticked"); task_total.store(0, Ordering::SeqCst); process_all_graphs(&client, task_graph_usage.clone()).await; } @@ -290,8 +290,8 @@ impl ReportSpaceport { async fn process_all_graphs(client: &Client, task_graph_usage: GraphUsageMap) { for result in extract_graph_usage(client, task_graph_usage).await { match result { - Ok(v) => tracing::debug!("Report submission succeeded: {:?}", v), - Err(e) => tracing::error!("Report submission failed: {}", e), + Ok(v) => tracing::debug!("report submission succeeded: {:?}", v), + Err(e) => tracing::error!("report submission failed: {}", e), } } } diff --git a/apollo-spaceport/src/spaceport.rs b/apollo-spaceport/src/spaceport.rs index 26baf3e673..03b956c8d1 100644 --- a/apollo-spaceport/src/spaceport.rs +++ b/apollo-spaceport/src/spaceport.rs @@ -31,7 +31,7 @@ async fn main() -> Result<(), Box> { .with_env_filter(filter) .json() .init(); - tracing::info!("Spaceport starting..."); + tracing::info!("spaceport starting"); let spaceport = ReportSpaceport::new(args.address); spaceport.serve().await?; diff --git a/examples/context/src/context_data.rs b/examples/context/src/context_data.rs index 46ae0f4c10..c76d23785c 100644 --- a/examples/context/src/context_data.rs +++ b/examples/context/src/context_data.rs @@ -51,7 +51,7 @@ impl Plugin for ContextData { // This can only happen if the value could not be serialized. // In this case we will never fail because we are storing a string which we // know can be stored as Json. - tracing::info!("Failed to set context data {}", e); + tracing::info!("failed to set context data {}", e); } req }) @@ -59,7 +59,7 @@ impl Plugin for ContextData { .map_response(|resp| { // Pick up a value from the context on the response. if let Ok(Some(data)) = resp.context.get::<_, u64>("response_count") { - tracing::info!("Subrequest count {}", data); + tracing::info!("subrequest count {}", data); } resp }) @@ -75,7 +75,7 @@ impl Plugin for ContextData { .map_request(|req: SubgraphRequest| { // Pick up a value from the context that was populated earlier. if let Ok(Some(data)) = req.context.get::<_, String>("incoming_data") { - tracing::info!("Hello {}", data); // Hello world! + tracing::info!("hello {}", data); // Hello world! } req }) diff --git a/examples/forbid-anonymous-operations/src/forbid_anonymous_operations.rs b/examples/forbid-anonymous-operations/src/forbid_anonymous_operations.rs index f219442f5c..6baefbca83 100644 --- a/examples/forbid-anonymous-operations/src/forbid_anonymous_operations.rs +++ b/examples/forbid-anonymous-operations/src/forbid_anonymous_operations.rs @@ -61,7 +61,7 @@ impl Plugin for ForbidAnonymousOperations { Ok(ControlFlow::Break(res)) } else { // we're good to go! - tracing::info!("Operation is allowed!"); + tracing::info!("operation is allowed!"); Ok(ControlFlow::Continue(req)) } }) diff --git a/examples/jwt-auth/src/jwt.rs b/examples/jwt-auth/src/jwt.rs index 95fbca8d76..1fc8932259 100644 --- a/examples/jwt-auth/src/jwt.rs +++ b/examples/jwt-auth/src/jwt.rs @@ -202,12 +202,10 @@ impl Plugin for JwtAuth { type Config = Conf; async fn startup(&mut self) -> Result<(), BoxError> { - tracing::debug!("starting: {}: {}", stringify!(JwtAuth), self.name()); Ok(()) } async fn shutdown(&mut self) -> Result<(), BoxError> { - tracing::debug!("shutting down: {}: {}", stringify!(JwtAuth), self.name()); Ok(()) } @@ -375,7 +373,6 @@ impl Plugin for JwtAuth { } fn new(configuration: Self::Config) -> Result { - tracing::debug!("JwtAuth configuration {:?}!", configuration); JwtAuth::new(configuration) } } diff --git a/fuzz/src/lib.rs b/fuzz/src/lib.rs index 01820c3fff..8a2e8a0ddd 100644 --- a/fuzz/src/lib.rs +++ b/fuzz/src/lib.rs @@ -19,7 +19,7 @@ pub fn generate_valid_operation(input: &[u8]) -> Result { .map(|err| err.message()) .collect::>() .join("\n"); - debug!("Parser errors ========== \n{:?}", errors); + debug!("parser errors ========== \n{:?}", errors); debug!("========================"); panic!("cannot parse the supergraph"); }