Skip to content

feat(remap transform): make --watch-config watch external VRL files in remap transforms #23010

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/9819_watch_remap_external_vrl.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Files specified in the `file` and `files` fields of `remap` transforms are now watched when `--watch-config` is enabled. Changes to these files automatically trigger a configuration reload, so there's no need to restart Vector.

authors: nekorro
11 changes: 11 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ pub async fn load_configs(
let mut watched_component_paths = Vec::new();

if let Some(watcher_conf) = watcher_conf {
for (name, transform) in config.transforms() {
let files = transform.inner.files_to_watch();
let component_config =
ComponentConfig::new(files.into_iter().cloned().collect(), name.clone());
watched_component_paths.push(component_config);
}

for (name, sink) in config.sinks() {
let files = sink.inner.files_to_watch();
let component_config =
Expand All @@ -544,6 +551,10 @@ pub async fn load_configs(
message = "Starting watcher.",
paths = ?watched_paths
);
info!(
message = "Components to watch.",
paths = ?watched_component_paths
);

// Start listening for config changes.
config::watcher::spawn_thread(
Expand Down
10 changes: 8 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::{
collections::{HashMap, HashSet},
fmt::{self, Display, Formatter},
fs,
hash::Hash,
net::SocketAddr,
path::PathBuf,
Expand Down Expand Up @@ -83,9 +84,14 @@ pub struct ComponentConfig {
}

impl ComponentConfig {
pub const fn new(config_paths: Vec<PathBuf>, component_key: ComponentKey) -> Self {
pub fn new(config_paths: Vec<PathBuf>, component_key: ComponentKey) -> Self {
let canonicalized_paths = config_paths
.into_iter()
.filter_map(|p| fs::canonicalize(p).ok())
.collect();

Self {
config_paths,
config_paths: canonicalized_paths,
component_key,
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/config/transform.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;

use async_trait::async_trait;
use dyn_clone::DynClone;
Expand Down Expand Up @@ -253,6 +254,11 @@ pub trait TransformConfig: DynClone + NamedComponent + core::fmt::Debug + Send +
fn nestable(&self, _parents: &HashSet<&'static str>) -> bool {
true
}

/// Gets the files to watch to trigger reload
fn files_to_watch(&self) -> Vec<&PathBuf> {
Vec::new()
}
}

dyn_clone::clone_trait_object!(TransformConfig);
Expand Down
7 changes: 7 additions & 0 deletions src/transforms/remap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ impl TransformConfig for RemapConfig {
fn enable_concurrency(&self) -> bool {
true
}

fn files_to_watch(&self) -> Vec<&PathBuf> {
self.file
.iter()
.chain(self.files.iter().flatten())
.collect()
}
}

#[derive(Debug, Clone)]
Expand Down