Skip to content

Commit

Permalink
fix(dev): make doc generation platform agnostic (#22223)
Browse files Browse the repository at this point in the history
* fix(dev): make doc generation platform agnostic

* gate macro use

* attempt to fix on windows

* some good refactoring

* another attempt for windows

* more tweaks for windows

* new workaround, revert unix.rs changes
  • Loading branch information
pront authored Jan 17, 2025
1 parent 70d3e63 commit 7acd86f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ vrl.workspace = true
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
snafu.workspace = true
cfg-if.workspace = true

# Internal libs
dnsmsg-parser = { path = "lib/dnsmsg-parser", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

//! The main library to support building Vector.
#[cfg(all(unix, feature = "sinks-socket"))]
#[macro_use]
extern crate cfg_if;
#[macro_use]
extern crate derivative;
#[macro_use]
Expand Down
49 changes: 34 additions & 15 deletions src/sinks/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use vector_lib::codecs::{
};
use vector_lib::configurable::configurable_component;

#[cfg(unix)]
#[cfg(not(windows))]
use crate::sinks::util::unix::UnixSinkConfig;
use crate::{
codecs::{Encoder, EncodingConfig, EncodingConfigWithFraming, SinkType},
Expand Down Expand Up @@ -41,15 +41,12 @@ pub enum Mode {
Udp(UdpMode),

/// Send over a Unix domain socket (UDS), in stream mode.
#[cfg(unix)]
#[serde(alias = "unix")]
UnixStream(UnixMode),

/// Send over a Unix domain socket (UDS), in datagram mode.
/// Unavailable on macOS, due to send(2)'s apparent non-blocking behavior,
/// resulting in ENOBUFS errors which we currently don't handle.
#[cfg(unix)]
#[cfg_attr(target_os = "macos", serde(skip))]
UnixDatagram(UnixMode),
}

Expand All @@ -76,7 +73,6 @@ pub struct UdpMode {
}

/// Unix Domain Socket configuration.
#[cfg(unix)]
#[configurable_component]
#[derive(Clone, Debug)]
pub struct UnixMode {
Expand All @@ -87,6 +83,19 @@ pub struct UnixMode {
encoding: EncodingConfigWithFraming,
}

// Workaround for https://github.com/vectordotdev/vector/issues/22198.
#[cfg(windows)]
/// A Unix Domain Socket sink.
#[configurable_component]
#[derive(Clone, Debug)]
pub struct UnixSinkConfig {
/// The Unix socket path.
///
/// This should be an absolute path.
#[configurable(metadata(docs::examples = "/path/to/socket"))]
pub path: std::path::PathBuf,
}

impl GenerateConfig for SocketSinkConfig {
fn generate_config() -> toml::Value {
toml::from_str(
Expand Down Expand Up @@ -151,16 +160,28 @@ impl SinkConfig for SocketSinkConfig {
super::util::service::net::UnixMode::Stream,
)
}
#[allow(unused)]
#[cfg(unix)]
Mode::UnixDatagram(UnixMode { config, encoding }) => {
let transformer = encoding.transformer();
let (framer, serializer) = encoding.build(SinkType::StreamBased)?;
let encoder = Encoder::<Framer>::new(framer, serializer);
config.build(
transformer,
encoder,
super::util::service::net::UnixMode::Datagram,
)
cfg_if! {
if #[cfg(not(target_os = "macos"))] {
let transformer = encoding.transformer();
let (framer, serializer) = encoding.build(SinkType::StreamBased)?;
let encoder = Encoder::<Framer>::new(framer, serializer);
config.build(
transformer,
encoder,
super::util::service::net::UnixMode::Datagram,
)
}
else {
Err("UnixDatagram is not available on macOS platforms.".into())
}
}
}
#[cfg(not(unix))]
Mode::UnixStream(_) | Mode::UnixDatagram(_) => {
Err("Unix modes are supported only on Unix platforms.".into())
}
}
}
Expand All @@ -169,9 +190,7 @@ impl SinkConfig for SocketSinkConfig {
let encoder_input_type = match &self.mode {
Mode::Tcp(TcpMode { encoding, .. }) => encoding.config().1.input_type(),
Mode::Udp(UdpMode { encoding, .. }) => encoding.config().input_type(),
#[cfg(unix)]
Mode::UnixStream(UnixMode { encoding, .. }) => encoding.config().1.input_type(),
#[cfg(unix)]
Mode::UnixDatagram(UnixMode { encoding, .. }) => encoding.config().1.input_type(),
};
Input::new(encoder_input_type)
Expand Down

0 comments on commit 7acd86f

Please sign in to comment.