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

Initial public API cleanup #1119

Merged
merged 3 commits into from Apr 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 0 additions & 44 deletions 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<Box<dyn error::Error + 'static>>,
}

impl ConfigError {
pub fn new(message: &str) -> Self {
ConfigError {
message: String::from(message),
source: None,
}
}

pub fn from(error: Box<dyn error::Error + 'static>) -> 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<Messages>;
6 changes: 3 additions & 3 deletions shotover/src/lib.rs
Expand Up @@ -22,16 +22,16 @@
#![deny(clippy::print_stderr)]

pub mod codec;
pub mod config;
mod config;
pub mod error;
pub mod frame;
pub mod message;
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;
2 changes: 1 addition & 1 deletion shotover/src/message_value.rs
Expand Up @@ -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<u8>>, len: usize) {
pub(crate) fn serialize_len(cursor: &mut Cursor<&mut Vec<u8>>, len: usize) {
let len = len as CInt;
cursor.write_all(&len.to_be_bytes()).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/observability/mod.rs
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions shotover/src/runner.rs
Expand Up @@ -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,

Expand All @@ -48,7 +48,7 @@ pub struct ConfigOpts {
}

#[derive(clap::ValueEnum, Clone, Copy)]
pub enum LogFormat {
enum LogFormat {
Human,
Json,
}
Expand Down Expand Up @@ -190,7 +190,7 @@ impl Shotover {
}
}

pub struct TracingState {
struct TracingState {
/// Once this is dropped tracing logs are ignored
_guard: WorkerGuard,
handle: ReloadHandle,
Expand Down Expand Up @@ -276,7 +276,7 @@ type Formatter<A, B> = Layered<Layer<Registry, A, Format<B>, 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<EnvFilter, Formatter<JsonFields, Json>>),
Human(Handle<EnvFilter, Formatter<DefaultFields, Full>>),
}
Expand All @@ -290,7 +290,7 @@ impl ReloadHandle {
}
}

pub async fn run(
async fn run(
topology: Topology,
config: Config,
trigger_shutdown_rx: watch::Receiver<bool>,
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/mod.rs
Expand Up @@ -487,4 +487,4 @@ pub trait Transform: Send {
fn set_pushed_messages_tx(&mut self, _pushed_messages_tx: mpsc::UnboundedSender<Messages>) {}
}

pub type ResponseFuture = Pin<Box<dyn Future<Output = Result<util::Response>> + Send + Sync>>;
type ResponseFuture = Pin<Box<dyn Future<Output = Result<util::Response>> + Send + Sync>>;