Use host-prefixed log directories under containers. (#21568)
vkalintiris committed
Jan 15, 2026 at 18:44 UTC
1fac5653d541f1880c805e3ebb0720fbbd2b0e50
1 file changed
+29
src/crates/netdata-log-viewer/journal-viewer-plugin/src/plugin_config.rs
+29
@@ -130,6 +130,13 @@ impl PluginConfig {
130
config.cache.directory =
131
resolve_relative_path(&config.cache.directory, netdata_env.cache_dir.as_deref());
132
133
+ // Add host-prefixed journal paths for containerized environments
134
+ if let Some(ref host_prefix) = netdata_env.host_prefix {
135
+ if !host_prefix.is_empty() {
136
+ expand_paths_with_host_prefix(&mut config.journal.paths, host_prefix);
137
+ }
138
+ }
139
+
140
// Validate configuration (also performs deduplication)
141
Self::validate(&mut config)?;
142
@@ -207,3 +214,25 @@ fn resolve_relative_path(path: &str, base_dir: Option<&Path>) -> String {
214
path.to_string_lossy().to_string()
215
}
216
}
217
+
218
+/// Standard journal paths that should be expanded with host prefix in containerized environments
219
+const STANDARD_JOURNAL_PATHS: &[&str] = &["/var/log/journal", "/run/log/journal"];
220
+
221
+/// Expand journal paths with host prefix for containerized environments
222
+///
223
+/// When running in a container with the host filesystem mounted (e.g., at /host),
224
+/// this adds prefixed versions of standard journal paths so we can read both
225
+/// container-local and host journals.
226
+fn expand_paths_with_host_prefix(paths: &mut Vec<String>, host_prefix: &str) {
227
+ let mut prefixed_paths = Vec::new();
228
+
229
+ for base_path in STANDARD_JOURNAL_PATHS {
230
+ let prefixed = format!("{}/{}", host_prefix, base_path);
231
+ // Only add if not already in the list
232
+ if !paths.contains(&prefixed) {
233
+ prefixed_paths.push(prefixed);
234
+ }
235
+ }
236
+
237
+ paths.extend(prefixed_paths);
238
+}