From 9e4c36235111afd79f9e1b17d7e4800164572588 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Tue, 11 Apr 2023 09:39:54 +1000 Subject: [PATCH] Initial public API cleanup (#1119) --- shotover/src/error.rs | 44 ------------------------------- shotover/src/lib.rs | 6 ++--- shotover/src/message_value.rs | 2 +- shotover/src/observability/mod.rs | 2 +- shotover/src/runner.rs | 10 +++---- shotover/src/transforms/mod.rs | 2 +- 6 files changed, 11 insertions(+), 55 deletions(-) diff --git a/shotover/src/error.rs b/shotover/src/error.rs index 32be1b8ed..c3c64b8fc 100644 --- a/shotover/src/error.rs +++ b/shotover/src/error.rs @@ -1,47 +1,3 @@ use crate::message::Messages; -use std::{error, fmt}; -use thiserror::Error; - -#[derive(Error, Clone, Debug)] -pub enum RequestError { - #[error("Invalid header (expected {expected:?}, got {found:?})")] - InvalidHeader { expected: String, found: String }, - #[error("Malform Request: {0}")] - MalformedRequest(String), - - #[error("Could not process script: {0}")] - ScriptProcessingError(String), - - #[error("Could not process chain: {0}")] - ChainProcessingError(String), -} - -#[derive(Error, Debug)] -pub struct ConfigError { - pub message: String, - pub source: Option>, -} - -impl ConfigError { - pub fn new(message: &str) -> Self { - ConfigError { - message: String::from(message), - source: None, - } - } - - pub fn from(error: Box) -> Self { - ConfigError { - message: error.to_string(), - source: Some(error), - } - } -} - -impl fmt::Display for ConfigError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "An error occured: {:}", self.message) - } -} pub type ChainResponse = anyhow::Result; diff --git a/shotover/src/lib.rs b/shotover/src/lib.rs index 2b568f039..994bdf7d6 100644 --- a/shotover/src/lib.rs +++ b/shotover/src/lib.rs @@ -22,7 +22,7 @@ #![deny(clippy::print_stderr)] pub mod codec; -pub mod config; +mod config; pub mod error; pub mod frame; pub mod message; @@ -30,8 +30,8 @@ pub mod message_value; mod observability; pub mod runner; mod server; -pub mod sources; +mod sources; pub mod tcp; pub mod tls; -pub mod tracing_panic_handler; +mod tracing_panic_handler; pub mod transforms; diff --git a/shotover/src/message_value.rs b/shotover/src/message_value.rs index 458378756..1086e240d 100644 --- a/shotover/src/message_value.rs +++ b/shotover/src/message_value.rs @@ -309,7 +309,7 @@ pub(crate) fn serialize_with_length_prefix( .copy_from_slice(&(bytes_len as CInt).to_be_bytes()); } -pub fn serialize_len(cursor: &mut Cursor<&mut Vec>, len: usize) { +pub(crate) fn serialize_len(cursor: &mut Cursor<&mut Vec>, len: usize) { let len = len as CInt; cursor.write_all(&len.to_be_bytes()).unwrap(); } diff --git a/shotover/src/observability/mod.rs b/shotover/src/observability/mod.rs index f128d457b..744333c1d 100644 --- a/shotover/src/observability/mod.rs +++ b/shotover/src/observability/mod.rs @@ -12,7 +12,7 @@ use std::{net::SocketAddr, sync::Arc}; use tracing::{error, trace}; /// Exports metrics over HTTP. -pub struct LogFilterHttpExporter { +pub(crate) struct LogFilterHttpExporter { recorder_handle: PrometheusHandle, address: SocketAddr, tracing_handle: ReloadHandle, diff --git a/shotover/src/runner.rs b/shotover/src/runner.rs index 04cd1cb16..84b07fdea 100644 --- a/shotover/src/runner.rs +++ b/shotover/src/runner.rs @@ -27,7 +27,7 @@ use tracing_subscriber::{EnvFilter, Registry}; #[derive(Parser, Clone)] #[clap(version = crate_version!(), author = "Instaclustr")] -pub struct ConfigOpts { +struct ConfigOpts { #[clap(short, long, default_value = "config/topology.yaml")] pub topology_file: String, @@ -48,7 +48,7 @@ pub struct ConfigOpts { } #[derive(clap::ValueEnum, Clone, Copy)] -pub enum LogFormat { +enum LogFormat { Human, Json, } @@ -190,7 +190,7 @@ impl Shotover { } } -pub struct TracingState { +struct TracingState { /// Once this is dropped tracing logs are ignored _guard: WorkerGuard, handle: ReloadHandle, @@ -276,7 +276,7 @@ type Formatter = Layered, NonBlocking>, Regis // * https://github.com/tokio-rs/tracing/pull/1035 // * https://github.com/linkerd/linkerd2-proxy/blob/6c484f6dcdeebda18b68c800b4494263bf98fcdc/linkerd/app/core/src/trace.rs#L19-L36 #[derive(Clone)] -pub enum ReloadHandle { +pub(crate) enum ReloadHandle { Json(Handle>), Human(Handle>), } @@ -290,7 +290,7 @@ impl ReloadHandle { } } -pub async fn run( +async fn run( topology: Topology, config: Config, trigger_shutdown_rx: watch::Receiver, diff --git a/shotover/src/transforms/mod.rs b/shotover/src/transforms/mod.rs index b61159972..1f4bc1542 100644 --- a/shotover/src/transforms/mod.rs +++ b/shotover/src/transforms/mod.rs @@ -487,4 +487,4 @@ pub trait Transform: Send { fn set_pushed_messages_tx(&mut self, _pushed_messages_tx: mpsc::UnboundedSender) {} } -pub type ResponseFuture = Pin> + Send + Sync>>; +type ResponseFuture = Pin> + Send + Sync>>;