Skip to content

Commit 33e57a3

Browse files
feat: extend AgentType vars with runtime configuration [NR-428549] (#1438)
* chore: remove unneeded clone * refactor: add support for runtime info in variables * chore: restrict variants to string type * feat: add support for variants in config * chore: update docs * chore: address old TODO * improve docs * fix unused imports --------- Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
1 parent 604eae6 commit 33e57a3

32 files changed

+1344
-940
lines changed

agent-control/src/agent_control/run.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::error::AgentError;
77
use super::http_server::config::ServerConfig;
88
use crate::agent_control::http_server::runner::Runner;
99
use crate::agent_type::embedded_registry::EmbeddedRegistry;
10+
use crate::agent_type::variable::constraints::VariableConstraints;
1011
use crate::event::broadcaster::unbounded::UnboundedBroadcast;
1112

1213
use crate::event::{AgentControlEvent, ApplicationEvent, SubAgentEvent, channel::EventConsumer};
@@ -71,6 +72,7 @@ pub struct AgentControlRunConfig {
7172
pub base_paths: BasePaths,
7273
pub proxy: ProxyConfig,
7374
pub k8s_config: K8sConfig,
75+
pub agent_type_var_constraints: VariableConstraints,
7476
}
7577

7678
/// Structure with all the data required to run the agent control.
@@ -93,6 +95,7 @@ pub struct AgentControlRunner {
9395
runtime: Arc<Runtime>,
9496

9597
http_server_runner: Option<Runner>,
98+
agent_type_var_constraints: VariableConstraints,
9699
}
97100

98101
impl AgentControlRunner {
@@ -172,6 +175,7 @@ impl AgentControlRunner {
172175
sub_agent_publisher,
173176
base_paths: config.base_paths,
174177
signature_validator,
178+
agent_type_var_constraints: config.agent_type_var_constraints,
175179
})
176180
}
177181

agent-control/src/agent_control/run/k8s.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::agent_control::resource_cleaner::k8s_garbage_collector::K8sGarbageCol
1414
use crate::agent_control::run::AgentControlRunner;
1515
use crate::agent_control::version_updater::k8s::K8sACUpdater;
1616
use crate::agent_type::render::renderer::TemplateRenderer;
17-
use crate::agent_type::variable::definition::VariableDefinition;
17+
use crate::agent_type::variable::Variable;
1818
#[cfg_attr(test, mockall_double::double)]
1919
use crate::k8s::client::SyncK8sClient;
2020
use crate::opamp::effective_config::loader::DefaultEffectiveConfigLoaderBuilder;
@@ -121,13 +121,11 @@ impl AgentControlRunner {
121121
let agent_control_variables = HashMap::from([
122122
(
123123
NAMESPACE_VARIABLE_NAME.to_string(),
124-
VariableDefinition::new_final_string_variable(self.k8s_config.namespace.clone()),
124+
Variable::new_final_string_variable(self.k8s_config.namespace.clone()),
125125
),
126126
(
127127
NAMESPACE_AGENTS_VARIABLE_NAME.to_string(),
128-
VariableDefinition::new_final_string_variable(
129-
self.k8s_config.namespace_agents.clone(),
130-
),
128+
Variable::new_final_string_variable(self.k8s_config.namespace_agents.clone()),
131129
),
132130
]);
133131

@@ -137,6 +135,7 @@ impl AgentControlRunner {
137135
let agents_assembler = Arc::new(LocalEffectiveAgentsAssembler::new(
138136
self.agent_type_registry.clone(),
139137
template_renderer,
138+
self.agent_type_var_constraints,
140139
));
141140

142141
let supervisor_builder =

agent-control/src/agent_control/run/on_host.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::agent_control::run::AgentControlRunner;
1212
use crate::agent_control::version_updater::updater::NoOpUpdater;
1313
use crate::agent_type::render::persister::config_persister_file::ConfigurationPersisterFile;
1414
use crate::agent_type::render::renderer::TemplateRenderer;
15-
use crate::agent_type::variable::definition::VariableDefinition;
15+
use crate::agent_type::variable::Variable;
1616
use crate::health::noop::NoOpHealthChecker;
1717
use crate::http::client::HttpClient;
1818
use crate::http::config::{HttpConfig, ProxyConfig};
@@ -90,7 +90,7 @@ impl AgentControlRunner {
9090

9191
let agent_control_variables = HashMap::from([(
9292
HOST_ID_VARIABLE_NAME.to_string(),
93-
VariableDefinition::new_final_string_variable(identifiers.host_id.clone()),
93+
Variable::new_final_string_variable(identifiers.host_id.clone()),
9494
)]);
9595

9696
let instance_id_storer = Storer::new(
@@ -142,6 +142,7 @@ impl AgentControlRunner {
142142
let agents_assembler = Arc::new(LocalEffectiveAgentsAssembler::new(
143143
self.agent_type_registry.clone(),
144144
template_renderer,
145+
self.agent_type_var_constraints,
145146
));
146147

147148
let supervisor_builder =

agent-control/src/agent_type/agent_attributes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use super::variable::{definition::VariableDefinition, namespace::Namespace};
3+
use super::variable::{Variable, namespace::Namespace};
44

55
/// contains any attribute from the sub-agent that is used to build or modify variables used to template the AgentType.
66
#[derive(Debug, PartialEq, Clone, Default)]
@@ -13,10 +13,10 @@ impl AgentAttributes {
1313
const VARIABLE_SUB_AGENT_ID: &'static str = "agent_id";
1414

1515
/// returns the variables from the sub-agent attributes source 'nr-sub'.
16-
pub fn sub_agent_variables(&self) -> HashMap<String, VariableDefinition> {
16+
pub fn sub_agent_variables(&self) -> HashMap<String, Variable> {
1717
HashMap::from([(
1818
Namespace::SubAgent.namespaced_name(Self::VARIABLE_SUB_AGENT_ID),
19-
VariableDefinition::new_final_string_variable(self.agent_id.clone()),
19+
Variable::new_final_string_variable(self.agent_id.clone()),
2020
)])
2121
}
2222
}

0 commit comments

Comments
 (0)