Skip to content

Commit e7dabac

Browse files
authored
feat: allow for no agents in config (#180)
* feat: allow for no agents in config Signed-off-by: David Sánchez <[email protected]> * test: check default agent config Signed-off-by: David Sánchez <[email protected]> --------- Signed-off-by: David Sánchez <[email protected]>
1 parent 29bc1cf commit e7dabac

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

build/package/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# headers:
44
# api-key: API_KEY_HERE
55

6-
agents:
6+
# agents:
77
# nr_infra_agent:
88
# agent_type: "newrelic/com.newrelic.infrastructure_agent:0.0.1"
99
# nr_otel_collector:

src/agent/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,23 @@ deployment:
559559
};
560560
assert_eq!("license_key: abc123\nstaging: true\n", f.content);
561561
}
562+
563+
#[test]
564+
fn empty_load_agent_cfgs_test() {
565+
let local_agent_type_repository = LocalRepository::new();
566+
let file_reader_mock = MockFileReaderMock::new();
567+
let agent_config = SuperAgentConfig {
568+
agents: Default::default(),
569+
opamp: None,
570+
};
571+
572+
let effective_agent_repository = load_agent_cfgs(
573+
&local_agent_type_repository,
574+
&file_reader_mock,
575+
&agent_config,
576+
)
577+
.unwrap();
578+
579+
assert_eq!(local_agent_type_repository, effective_agent_repository);
580+
}
562581
}

src/agent/supervisor_group.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,21 @@ pub mod tests {
297297
Ok(SupervisorGroup(group))
298298
}
299299

300+
#[test]
301+
fn run_stop_without_opamp_nor_agents() {
302+
let supervisor_group: SupervisorGroup<MockOpAMPClientMock, Stopped> =
303+
SupervisorGroup(HashMap::new());
304+
let running_supervisor_group = supervisor_group.run();
305+
assert!(
306+
running_supervisor_group.is_ok(),
307+
"unable to run supervisor_group without opamp"
308+
);
309+
assert!(
310+
running_supervisor_group.unwrap().stop().is_ok(),
311+
"unable to stop supervisor_group without opamp"
312+
);
313+
}
314+
300315
#[test]
301316
fn run_stop_without_opamp() {
302317
let (tx, _) = std::sync::mpsc::channel();

src/config/agent_configs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl Display for AgentID {
2222
#[serde(deny_unknown_fields)]
2323
pub struct SuperAgentConfig {
2424
/// agents is a map of agent types to their specific configuration (if any).
25+
#[serde(default)]
2526
pub agents: HashMap<AgentID, AgentSupervisorConfig>,
2627

2728
/// opamp contains the OpAMP client configuration

src/config/agent_type_registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait AgentRepository {
2323
fn store_with_key(&mut self, key: String, agent: Agent) -> Result<(), AgentRepositoryError>;
2424
}
2525

26-
#[derive(Debug, Default, Clone)]
26+
#[derive(Debug, Default, Clone, PartialEq)]
2727
pub struct LocalRepository(HashMap<String, Agent>);
2828

2929
impl AgentRepository for LocalRepository {

0 commit comments

Comments
 (0)