Skip to content

Commit bd7c2a9

Browse files
committed
feat: filter log types using include/exclude patterns
Allow users to filter log types reported by log plugins using include and exclude patterns in the plugin configuration.
1 parent 4b22255 commit bd7c2a9

File tree

16 files changed

+609
-19
lines changed

16 files changed

+609
-19
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configuration/contrib/log-plugins/journald

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ list_log_types() {
3737
exit 1
3838
fi
3939
status=0
40-
{ systemctl list-units --type=service --no-legend --no-pager --plain || status=$?; } | awk '!/^systemd/ { sub(/\.service$/, "", $1); print $1 }' || status=$?
40+
{ systemctl list-units --type=service --no-legend --no-pager --plain || status=$?; } | awk '{ sub(/\.service$/, "", $1); print $1 }' || status=$?
4141
if [ "$status" -ne 0 ]; then
4242
echo "Pipeline failed with $status" >&2
4343
exit "$status"

crates/core/tedge_agent/src/agent.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use tedge_health_ext::HealthMonitorBuilder;
6262
use tedge_log_manager::LogManagerBuilder;
6363
use tedge_log_manager::LogManagerConfig;
6464
use tedge_log_manager::LogManagerOptions;
65+
use tedge_log_manager::PluginConfig;
6566
use tedge_mqtt_ext::MqttActorBuilder;
6667
use tedge_mqtt_ext::MqttConfig;
6768
use tedge_mqtt_ext::TopicFilter;
@@ -383,8 +384,12 @@ impl Agent {
383384
mqtt_device_topic_id: device_topic_id.clone(),
384385
plugin_dirs: self.config.log_plugin_dirs,
385386
})?;
387+
388+
let plugin_config =
389+
PluginConfig::from_file(&log_manager_config.plugin_config_path).await;
386390
let mut log_actor = LogManagerBuilder::try_new(
387391
log_manager_config,
392+
plugin_config,
388393
&mut fs_watch_actor_builder,
389394
&mut uploader_actor_builder,
390395
)

crates/extensions/tedge_log_manager/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ repository = { workspace = true }
1313
anyhow = { workspace = true }
1414
async-trait = { workspace = true }
1515
camino = { workspace = true }
16+
regex = { workspace = true }
17+
serde = { workspace = true }
1618
serde_json = { workspace = true }
1719
tedge_actors = { workspace = true }
1820
tedge_api = { workspace = true }
@@ -30,6 +32,7 @@ tracing = { workspace = true }
3032
[dev-dependencies]
3133
tedge_actors = { workspace = true, features = ["test-helpers"] }
3234
tedge_test_utils = { workspace = true }
35+
tempfile = { workspace = true }
3336
time = { workspace = true, features = ["macros"] }
3437

3538
[lints]

crates/extensions/tedge_log_manager/src/actor.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::error::LogManagementError;
22
use super::LogManagerConfig;
33
use super::DEFAULT_PLUGIN_CONFIG_FILE_NAME;
4+
use crate::config::PluginConfig;
45
use crate::plugin_manager::ExternalPlugins;
56
use async_trait::async_trait;
67
use std::collections::HashMap;
@@ -59,6 +60,7 @@ pub struct LogManagerActor {
5960
messages: SimpleMessageBox<LogInput, LogOutput>,
6061
upload_sender: DynSender<LogUploadRequest>,
6162
external_plugins: ExternalPlugins,
63+
plugin_config: PluginConfig,
6264
}
6365

6466
#[async_trait]
@@ -93,6 +95,7 @@ impl Actor for LogManagerActor {
9395
impl LogManagerActor {
9496
pub fn new(
9597
config: LogManagerConfig,
98+
plugin_config: PluginConfig,
9699
messages: SimpleMessageBox<LogInput, LogOutput>,
97100
upload_sender: DynSender<LogUploadRequest>,
98101
external_plugins: ExternalPlugins,
@@ -103,6 +106,7 @@ impl LogManagerActor {
103106
messages,
104107
upload_sender,
105108
external_plugins,
109+
plugin_config,
106110
}
107111
}
108112

@@ -280,6 +284,9 @@ impl LogManagerActor {
280284
async fn reload_supported_log_types(&mut self) -> Result<(), RuntimeError> {
281285
info!(target: "log plugins", "Reloading supported log types");
282286

287+
// Reload plugin configuration for up-to-date filtering rules
288+
self.plugin_config = PluginConfig::from_file(&self.config.plugin_config_path).await;
289+
283290
// Note: The log manager now only handles external plugins.
284291
// The file-based plugin configuration is handled by the standalone plugin.
285292
self.external_plugins.load().await?;
@@ -305,7 +312,21 @@ impl LogManagerActor {
305312
target: "log plugins",
306313
"Plugin {} supports log types: {:?}", plugin_type, log_types
307314
);
308-
for log_type in log_types {
315+
316+
// Apply filtering from plugin config
317+
let filtered_log_types =
318+
self.plugin_config.filter_log_types(&plugin_type, log_types);
319+
320+
if !filtered_log_types.is_empty() {
321+
info!(
322+
target: "log plugins",
323+
"Log types from {} plugin after filtering: {:?}",
324+
plugin_type,
325+
filtered_log_types
326+
);
327+
}
328+
329+
for log_type in filtered_log_types {
309330
if plugin_type == "file" {
310331
// For the file plugin, add log types without suffix (default behavior)
311332
types.push(log_type);

0 commit comments

Comments
 (0)