Skip to content

Commit eeca8f4

Browse files
Update agent-control/src/cli/on_host/host_monitoring_gen/infra_config_gen.rs
Co-authored-by: danielorihuela <danielorihuela@users.noreply.github.com>
1 parent 42c4fe7 commit eeca8f4

File tree

1 file changed

+29
-42
lines changed

1 file changed

+29
-42
lines changed

agent-control/src/cli/on_host/host_monitoring_gen/infra_config_gen.rs

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -131,48 +131,35 @@ impl InfraConfigGenerator {
131131

132132
let legacy_config_renamer = LegacyConfigRenamer::default();
133133

134-
for cfg in config.configs {
135-
debug!("Checking configurations for {}", cfg.agent_type_fqn);
136-
match config_migrator.migrate(&cfg) {
137-
Ok(_) => {
138-
for (_, mapping_type) in cfg.filesystem_mappings {
139-
match mapping_type {
140-
MappingType::Dir(dir_path) => {
141-
legacy_config_renamer
142-
.rename_path(dir_path.dir_path.as_path())
143-
.map_err(|err| {
144-
CliError::Command(format!(
145-
"error renaming path on migration: {err}"
146-
))
147-
})?;
148-
}
149-
MappingType::File(file_info) => {
150-
legacy_config_renamer
151-
.rename_path(file_info.file_path.as_path())
152-
.map_err(|err| {
153-
CliError::Command(format!(
154-
"error renaming file on migration: {err}"
155-
))
156-
})?;
157-
}
158-
}
159-
}
160-
debug!("Classic config files and paths renamed");
161-
}
162-
Err(MigratorError::AgentTypeNotFoundOnConfig) => {
163-
debug!(
164-
"No agents of agent_type {} found on config, skipping",
165-
cfg.agent_type_fqn.clone()
166-
);
167-
}
168-
Err(e) => {
169-
warn!(
170-
"Could not apply local config migration for {}: {}",
171-
cfg.agent_type_fqn, e
172-
);
173-
}
174-
}
175-
}
134+
for cfg in config.configs {
135+
let fqn = cfg.agent_type_fqn.clone();
136+
debug!("Checking configurations for {fqn}");
137+
let migrate_result = config_migrator.migrate(&cfg);
138+
if let Err(MigratorError::AgentTypeNotFoundOnConfig) = migrate_result {
139+
debug!("No agents of agent_type {fqn} found on config, skipping",);
140+
continue;
141+
};
142+
143+
if let Err(e) = migrate_result {
144+
warn!("Could not apply local config migration for {fqn}: {e}",);
145+
continue;
146+
};
147+
148+
for (_, mapping_type) in cfg.filesystem_mappings {
149+
let (mapping_key, mapping_path) = match mapping_type {
150+
MappingType::Dir(dir_path) => ("path", dir_path.dir_path),
151+
MappingType::File(file_info) => ("file", file_info.file_path),
152+
};
153+
legacy_config_renamer
154+
.rename_path(mapping_path.as_path())
155+
.map_err(|err| {
156+
CliError::Command(format!(
157+
"error renaming {mapping_key} on migration: {err}"
158+
))
159+
})?;
160+
}
161+
debug!("Classic config files and paths renamed");
162+
}
176163
info!("Local config files successfully created");
177164

178165
Ok(())

0 commit comments

Comments
 (0)