@@ -18,6 +18,7 @@ use crate::values::yaml_config::YAMLConfig;
1818use opamp_client:: operation:: capabilities:: Capabilities ;
1919use serde:: { Deserialize , Deserializer } ;
2020use std:: { collections:: HashMap , str:: FromStr } ;
21+ use tracing:: warn;
2122
2223/// AgentTypeDefinition represents the definition of an [AgentType]. It defines the variables and runtime for any supported
2324/// environment.
@@ -294,15 +295,16 @@ fn update_specs(
294295 values : HashMap < String , serde_yaml:: Value > ,
295296 agent_vars : & mut HashMap < String , VariableDefinitionTree > ,
296297) -> Result < ( ) , AgentTypeError > {
297- for ( ref k, v) in values. into_iter ( ) {
298- let spec = agent_vars
299- . get_mut ( k)
300- . ok_or_else ( || AgentTypeError :: UnexpectedValueKey ( k. clone ( ) ) ) ?;
298+ for ( ref key, value) in values. into_iter ( ) {
299+ let Some ( spec) = agent_vars. get_mut ( key) else {
300+ warn ! ( %key, "Unexpected variable in the configuration" ) ;
301+ continue ;
302+ } ;
301303
302304 match spec {
303- VariableDefinitionTree :: End ( e) => e. merge_with_yaml_value ( v ) ?,
305+ VariableDefinitionTree :: End ( e) => e. merge_with_yaml_value ( value ) ?,
304306 VariableDefinitionTree :: Mapping ( m) => {
305- let v: HashMap < String , serde_yaml:: Value > = serde_yaml:: from_value ( v ) ?;
307+ let v: HashMap < String , serde_yaml:: Value > = serde_yaml:: from_value ( value ) ?;
306308 update_specs ( v, m) ?
307309 }
308310 }
@@ -352,7 +354,8 @@ pub(crate) type Variables = HashMap<String, VariableDefinition>;
352354
353355#[ cfg( test) ]
354356pub mod tests {
355-
357+ use super :: * ;
358+ use crate :: agent_type:: runtime_config:: Deployment ;
356359 use crate :: {
357360 agent_type:: {
358361 environment:: Environment ,
@@ -362,9 +365,6 @@ pub mod tests {
362365 } ,
363366 sub_agent:: effective_agents_assembler:: build_agent_type,
364367 } ;
365-
366- use super :: * ;
367- use crate :: agent_type:: runtime_config:: Deployment ;
368368 use assert_matches:: assert_matches;
369369 use serde_yaml:: { Error , Number } ;
370370 use std:: collections:: HashMap as Map ;
@@ -556,7 +556,6 @@ deployment:
556556 #[ test]
557557 fn test_normalize_agent_spec ( ) {
558558 // create AgentSpec
559-
560559 let given_agent = AgentType :: build_for_testing ( AGENT_GIVEN_YAML , & Environment :: OnHost ) ;
561560
562561 let expected_map: Map < String , VariableDefinition > = Map :: from ( [ (
@@ -718,8 +717,8 @@ deployment:
718717 args : TemplateableValue {
719718 value : Some ( Args ( "--config config_path --plugin_dir integration_path --verbose true --logs trace" . to_string ( ) ) ) ,
720719 template :
721- "--config ${nr-var:config} --plugin_dir ${nr-var:integrations} --verbose ${nr-var:deployment.on_host.verbose} --logs ${nr-var:deployment.on_host.log_level}"
722- . to_string ( ) ,
720+ "--config ${nr-var:config} --plugin_dir ${nr-var:integrations} --verbose ${nr-var:deployment.on_host.verbose} --logs ${nr-var:deployment.on_host.log_level}"
721+ . to_string ( ) ,
723722 } ,
724723 env : Env :: default ( ) ,
725724 restart_policy : RestartPolicyConfig {
@@ -911,6 +910,7 @@ deployment:
911910"# ;
912911
913912 const GIVEN_NEWRELIC_INFRA_USER_CONFIG_YAML : & str = r#"
913+ unknown_variable: ignored
914914config3:
915915 log_level: trace
916916 forward: "true"
@@ -1018,7 +1018,8 @@ status_server_port: 8004
10181018 . as_ref( )
10191019 . unwrap( )
10201020 . clone( )
1021- )
1021+ ) ;
1022+ assert ! ( !filled_variables. contains_key( "unknown_variable" ) )
10221023 }
10231024
10241025 const AGENT_TYPE_WITH_VARIANTS : & str = r#"
@@ -1055,16 +1056,9 @@ restart_policy:
10551056 fn test_variables_with_variants ( ) {
10561057 let agent_type =
10571058 AgentType :: build_for_testing ( AGENT_TYPE_WITH_VARIANTS , & Environment :: OnHost ) ;
1058- let values: YAMLConfig =
1059- serde_yaml:: from_str ( VALUES_VALID_VARIANT ) . expect ( "Failed to parse user config" ) ;
10601059
10611060 // Valid variant
1062- let filled_variables = agent_type
1063- . variables
1064- . clone ( )
1065- . fill_with_values ( values)
1066- . unwrap ( )
1067- . flatten ( ) ;
1061+ let filled_variables = agent_type. fill_variables ( VALUES_VALID_VARIANT ) ;
10681062
10691063 let var = filled_variables. get ( "restart_policy.type" ) . unwrap ( ) ;
10701064 assert_eq ! (
@@ -1086,12 +1080,7 @@ restart_policy:
10861080 ) ;
10871081
10881082 // Default invalid variant is allowed
1089- let filled_variables_default = agent_type
1090- . variables
1091- . clone ( )
1092- . fill_with_values ( YAMLConfig :: default ( ) )
1093- . unwrap ( )
1094- . flatten ( ) ;
1083+ let filled_variables_default = agent_type. fill_variables ( "" ) ;
10951084 let var = filled_variables_default. get ( "restart_policy.type" ) . unwrap ( ) ;
10961085 assert_eq ! (
10971086 "exponential" . to_string( ) ,
0 commit comments