Skip to content

Commit 3e2fe63

Browse files
feat(OpAMP): adding new attributes
Signed-off-by: Paolo Gallina <[email protected]>
1 parent 19c3502 commit 3e2fe63

File tree

9 files changed

+119
-57
lines changed

9 files changed

+119
-57
lines changed

agent-control/src/agent_control/defaults.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub const OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY: &str = "cd.chart.version";
2121
pub const OPAMP_SERVICE_NAME: &str = "service.name";
2222
pub const OPAMP_SERVICE_VERSION: &str = "service.version";
2323
pub const OPAMP_SERVICE_NAMESPACE: &str = "service.namespace";
24+
// we leverage the service.instance.id to send info regarding the agentID (not the ULID)
25+
pub const OPAMP_SERVICE_INSTANCE_ID: &str = "service.instance.id";
26+
2427
pub const OPAMP_AGENT_VERSION_ATTRIBUTE_KEY: &str = "agent.version";
2528

2629
// Auth
@@ -32,6 +35,14 @@ pub const HOST_NAME_ATTRIBUTE_KEY: &str = opentelemetry_semantic_conventions::at
3235
pub const CLUSTER_NAME_ATTRIBUTE_KEY: &str = "cluster.name";
3336
pub const HOST_ID_ATTRIBUTE_KEY: &str = opentelemetry_semantic_conventions::attribute::HOST_ID;
3437
pub const FLEET_ID_ATTRIBUTE_KEY: &str = "fleet.guid";
38+
pub const OS_ATTRIBUTE_KEY: &str = "os"; //TODO ask ferran
39+
40+
#[cfg(target_os = "macos")]
41+
pub const OS_VERSION_ATTRIBUTE_VALUE: &str = "macos";
42+
#[cfg(target_os = "linux")]
43+
pub const OS_VERSION_ATTRIBUTE_VALUE: &str = "linux";
44+
#[cfg(target_os = "windows")]
45+
pub const OS_VERSION_ATTRIBUTE_VALUE: &str = "windows";
3546

3647
// Paths
3748
// TODO: should we rename AGENT_CONTROL_DATA_DIR to AGENT_CONTROL_REMOTE_DATA_DIR?

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::agent_control::config_repository::store::AgentControlConfigStore;
55
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
66
use crate::agent_control::config_validator::k8s::K8sReleaseNamesConfigValidator;
77
use crate::agent_control::defaults::{
8-
AGENT_CONTROL_VERSION, FLEET_ID_ATTRIBUTE_KEY, HOST_NAME_ATTRIBUTE_KEY,
9-
OPAMP_AC_CHART_VERSION_ATTRIBUTE_KEY, OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
10-
OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY,
8+
AGENT_CONTROL_VERSION, CLUSTER_NAME_ATTRIBUTE_KEY, FLEET_ID_ATTRIBUTE_KEY,
9+
HOST_NAME_ATTRIBUTE_KEY, OPAMP_AC_CHART_VERSION_ATTRIBUTE_KEY,
10+
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY,
1111
};
1212
use crate::agent_control::health_checker::k8s::agent_control_health_checker_builder;
1313
use crate::agent_control::http_server::runner::Runner;
@@ -87,12 +87,11 @@ impl AgentControlRunner {
8787
let identifiers = get_identifiers(self.k8s_config.cluster_name.clone(), fleet_id);
8888
info!("Instance Identifiers: {}", identifiers);
8989

90-
let mut non_identifying_attributes =
91-
agent_control_opamp_non_identifying_attributes(&identifiers);
92-
non_identifying_attributes.insert(
93-
"cluster.name".to_string(),
94-
self.k8s_config.cluster_name.clone().into(),
90+
let non_identifying_attributes = agent_control_opamp_non_identifying_attributes(
91+
&identifiers,
92+
self.k8s_config.cluster_name.clone(),
9593
);
94+
9695
let additional_identifying_attributes =
9796
agent_control_additional_opamp_identifying_attributes(&self.k8s_config);
9897

@@ -293,21 +292,20 @@ fn start_cd_version_checker(
293292

294293
pub fn agent_control_opamp_non_identifying_attributes(
295294
identifiers: &Identifiers,
295+
cluster_name: String,
296296
) -> HashMap<String, DescriptionValueType> {
297297
let hostname = get_hostname().unwrap_or_else(|e| {
298298
error!("cannot retrieve hostname: {}", e.to_string());
299299
"unknown_hostname".to_string()
300300
});
301301

302302
HashMap::from([
303-
(
304-
HOST_NAME_ATTRIBUTE_KEY.to_string(),
305-
DescriptionValueType::String(hostname),
306-
),
303+
(HOST_NAME_ATTRIBUTE_KEY.to_string(), hostname.into()),
307304
(
308305
FLEET_ID_ATTRIBUTE_KEY.to_string(),
309-
DescriptionValueType::String(identifiers.fleet_id.clone()),
306+
identifiers.fleet_id.clone().into(),
310307
),
308+
(CLUSTER_NAME_ATTRIBUTE_KEY.to_string(), cluster_name.into()),
311309
])
312310
}
313311

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::agent_control::config_repository::store::AgentControlConfigStore;
44
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
55
use crate::agent_control::defaults::{
66
AGENT_CONTROL_VERSION, FLEET_ID_ATTRIBUTE_KEY, HOST_ID_ATTRIBUTE_KEY, HOST_NAME_ATTRIBUTE_KEY,
7-
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
7+
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, OS_ATTRIBUTE_KEY, OS_VERSION_ATTRIBUTE_VALUE,
88
};
99
use crate::agent_control::http_server::runner::Runner;
1010
use crate::agent_control::resource_cleaner::no_op::NoOpResourceCleaner;
@@ -207,15 +207,19 @@ pub fn agent_control_opamp_non_identifying_attributes(
207207
HashMap::from([
208208
(
209209
HOST_NAME_ATTRIBUTE_KEY.to_string(),
210-
DescriptionValueType::String(identifiers.hostname.clone()),
210+
identifiers.hostname.clone().into(),
211211
),
212212
(
213213
HOST_ID_ATTRIBUTE_KEY.to_string(),
214-
DescriptionValueType::String(identifiers.host_id.clone()),
214+
identifiers.host_id.clone().into(),
215215
),
216216
(
217217
FLEET_ID_ATTRIBUTE_KEY.to_string(),
218-
DescriptionValueType::String(identifiers.fleet_id.clone()),
218+
identifiers.fleet_id.clone().into(),
219+
),
220+
(
221+
OS_ATTRIBUTE_KEY.to_string(),
222+
OS_VERSION_ATTRIBUTE_VALUE.to_string().into(),
219223
),
220224
])
221225
}

agent-control/src/opamp/operations.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use super::{
44
instance_id::getter::InstanceIDGetter,
55
};
66
use crate::agent_control::defaults::{
7-
OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE, PARENT_AGENT_ID_ATTRIBUTE_KEY,
8-
default_capabilities, get_custom_capabilities,
7+
OPAMP_SERVICE_INSTANCE_ID, OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE,
8+
PARENT_AGENT_ID_ATTRIBUTE_KEY, default_capabilities, get_custom_capabilities,
99
};
10-
use crate::agent_type::agent_type_id::AgentTypeID;
1110
use crate::sub_agent::identity::AgentIdentity;
1211
use crate::{
1312
agent_control::agent_id::AgentID,
@@ -66,7 +65,7 @@ where
6665
let (opamp_publisher, opamp_consumer) = pub_sub();
6766
let start_settings = start_settings(
6867
instance_id_getter.get(&agent_identity.id)?,
69-
&agent_identity.agent_type_id,
68+
agent_identity,
7069
additional_identifying_attributes,
7170
non_identifying_attributes,
7271
);
@@ -82,15 +81,22 @@ where
8281
/// Builds the OpAMP StartSettings corresponding to the provided arguments for any sub agent and agent control.
8382
pub fn start_settings(
8483
instance_id: InstanceID,
85-
agent_type_id: &AgentTypeID,
84+
agent_identity: &AgentIdentity,
8685
additional_identifying_attributes: HashMap<String, DescriptionValueType>,
8786
non_identifying_attributes: HashMap<String, DescriptionValueType>,
8887
) -> StartSettings {
8988
let mut identifying_attributes = HashMap::from([
90-
(OPAMP_SERVICE_NAME.to_string(), agent_type_id.name().into()),
89+
(
90+
OPAMP_SERVICE_NAME.to_string(),
91+
agent_identity.agent_type_id.name().into(),
92+
),
9193
(
9294
OPAMP_SERVICE_NAMESPACE.to_string(),
93-
agent_type_id.namespace().into(),
95+
agent_identity.agent_type_id.namespace().into(),
96+
),
97+
(
98+
OPAMP_SERVICE_INSTANCE_ID.to_string(),
99+
agent_identity.id.to_string().into(),
94100
),
95101
]);
96102

@@ -99,7 +105,7 @@ pub fn start_settings(
99105
StartSettings {
100106
instance_uid: instance_id.into(),
101107
capabilities: default_capabilities(),
102-
custom_capabilities: get_custom_capabilities(agent_type_id),
108+
custom_capabilities: get_custom_capabilities(&agent_identity.agent_type_id),
103109
agent_description: AgentDescription {
104110
identifying_attributes,
105111
non_identifying_attributes,

agent-control/src/sub_agent/k8s/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ pub mod tests {
375375
let mut opamp_builder = MockOpAMPClientBuilder::new();
376376
let start_settings = start_settings(
377377
instance_id.clone(),
378-
&agent_identity.agent_type_id,
378+
&agent_identity,
379379
HashMap::from([(
380380
OPAMP_SERVICE_VERSION.to_string(),
381381
agent_identity.agent_type_id.version().to_string().into(),

agent-control/src/sub_agent/on_host/builder.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::agent_control::defaults::{HOST_NAME_ATTRIBUTE_KEY, OPAMP_SERVICE_VERSION};
1+
use crate::agent_control::defaults::{
2+
HOST_NAME_ATTRIBUTE_KEY, OPAMP_SERVICE_VERSION, OS_ATTRIBUTE_KEY, OS_VERSION_ATTRIBUTE_VALUE,
3+
};
24
use crate::agent_control::run::Environment;
35
use crate::agent_type::runtime_config::on_host::filesystem::rendered::FileSystemEntries;
46
use crate::event::SubAgentEvent;
@@ -18,6 +20,7 @@ use crate::{
1820
opamp::client_builder::OpAMPClientBuilder,
1921
sub_agent::{SubAgentBuilder, error::SubAgentBuilderError},
2022
};
23+
use opamp_client::operation::settings::DescriptionValueType;
2124
use resource_detection::system::hostname::get_hostname;
2225
use std::collections::HashMap;
2326
use std::path::PathBuf;
@@ -105,7 +108,13 @@ where
105108
OPAMP_SERVICE_VERSION.to_string(),
106109
agent_identity.agent_type_id.version().to_string().into(),
107110
)]),
108-
HashMap::from([(HOST_NAME_ATTRIBUTE_KEY.to_string(), hostname)]),
111+
HashMap::from([
112+
(HOST_NAME_ATTRIBUTE_KEY.to_string(), hostname),
113+
(
114+
OS_ATTRIBUTE_KEY.to_string(),
115+
DescriptionValueType::String(OS_VERSION_ATTRIBUTE_VALUE.to_string()),
116+
),
117+
]),
109118
)
110119
.map_err(|e| SubAgentBuilderError::OpampClientBuilderError(e.to_string()))
111120
})
@@ -183,9 +192,8 @@ impl SupervisorBuilder for SupervisortBuilderOnHost {
183192
mod tests {
184193
use super::*;
185194
use crate::agent_control::agent_id::AgentID;
186-
187195
use crate::agent_control::defaults::{
188-
OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE, OPAMP_SERVICE_VERSION,
196+
OPAMP_SERVICE_INSTANCE_ID, OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE,
189197
PARENT_AGENT_ID_ATTRIBUTE_KEY, default_capabilities, default_sub_agent_custom_capabilities,
190198
};
191199
use crate::agent_type::agent_type_id::AgentTypeID;
@@ -237,7 +245,7 @@ mod tests {
237245
&hostname,
238246
agent_control_instance_id.clone(),
239247
sub_agent_instance_id.clone(),
240-
&agent_identity.agent_type_id,
248+
&agent_identity,
241249
);
242250

243251
let agent_control_id = AgentID::AgentControl;
@@ -354,7 +362,7 @@ mod tests {
354362
&hostname,
355363
agent_control_instance_id.clone(),
356364
sub_agent_instance_id.clone(),
357-
&agent_identity.agent_type_id,
365+
&agent_identity,
358366
);
359367

360368
let remote_config_values = RemoteConfig {
@@ -461,17 +469,24 @@ mod tests {
461469
hostname: &str,
462470
agent_control_instance_id: InstanceID,
463471
sub_agent_instance_id: InstanceID,
464-
agent_fqn: &AgentTypeID,
472+
agent_identity: &AgentIdentity,
465473
) -> StartSettings {
466474
let identifying_attributes = HashMap::<String, DescriptionValueType>::from([
467-
(OPAMP_SERVICE_NAME.to_string(), agent_fqn.name().into()),
475+
(
476+
OPAMP_SERVICE_NAME.to_string(),
477+
agent_identity.agent_type_id.name().into(),
478+
),
468479
(
469480
OPAMP_SERVICE_NAMESPACE.to_string(),
470-
agent_fqn.namespace().into(),
481+
agent_identity.agent_type_id.namespace().into(),
482+
),
483+
(
484+
OPAMP_SERVICE_INSTANCE_ID.to_string(),
485+
agent_identity.id.to_string().into(),
471486
),
472487
(
473488
OPAMP_SERVICE_VERSION.to_string(),
474-
agent_fqn.version().to_string().into(),
489+
agent_identity.agent_type_id.version().to_string().into(),
475490
),
476491
]);
477492
StartSettings {
@@ -489,6 +504,10 @@ mod tests {
489504
PARENT_AGENT_ID_ATTRIBUTE_KEY.to_string(),
490505
DescriptionValueType::Bytes(agent_control_instance_id.into()),
491506
),
507+
(
508+
OS_ATTRIBUTE_KEY.to_string(),
509+
OS_VERSION_ATTRIBUTE_VALUE.into(),
510+
),
492511
]),
493512
},
494513
}

agent-control/tests/k8s/flux_self_update.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ use kube::api::PostParams;
2929
use kube::{Api, Client};
3030
use newrelic_agent_control::agent_control::agent_id::AgentID;
3131
use newrelic_agent_control::agent_control::defaults::{
32-
AGENT_CONTROL_VERSION, OPAMP_AC_CHART_VERSION_ATTRIBUTE_KEY, OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
33-
OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY, OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE,
32+
AGENT_CONTROL_ID, AGENT_CONTROL_VERSION, OPAMP_AC_CHART_VERSION_ATTRIBUTE_KEY,
33+
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY,
34+
OPAMP_SERVICE_INSTANCE_ID, OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE,
3435
};
3536
use newrelic_agent_control::cli::k8s::install::flux::HELM_REPOSITORY_NAME;
36-
use opamp_client::opamp::proto::{self, KeyValue, RemoteConfigStatuses};
37+
use opamp_client::opamp::proto::any_value::Value;
38+
use opamp_client::opamp::proto::{KeyValue, RemoteConfigStatuses};
3739
use std::time::Duration;
3840
use tempfile::tempdir;
3941

@@ -227,25 +229,29 @@ fn expected_identifying_attributes(
227229
cd_chart_version: &str,
228230
) -> Vec<KeyValue> {
229231
convert_to_vec_key_value(Vec::from([
232+
(
233+
OPAMP_SERVICE_INSTANCE_ID,
234+
Value::StringValue(AGENT_CONTROL_ID.to_string()),
235+
),
230236
(
231237
OPAMP_SERVICE_NAMESPACE,
232-
proto::any_value::Value::StringValue("newrelic".to_string()),
238+
Value::StringValue("newrelic".to_string()),
233239
),
234240
(
235241
OPAMP_SERVICE_NAME,
236-
proto::any_value::Value::StringValue("com.newrelic.agent_control".to_string()),
242+
Value::StringValue("com.newrelic.agent_control".to_string()),
237243
),
238244
(
239245
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
240-
proto::any_value::Value::StringValue(AGENT_CONTROL_VERSION.to_string()),
246+
Value::StringValue(AGENT_CONTROL_VERSION.to_string()),
241247
),
242248
(
243249
OPAMP_AC_CHART_VERSION_ATTRIBUTE_KEY,
244-
proto::any_value::Value::StringValue(ac_chart_version.to_string()),
250+
Value::StringValue(ac_chart_version.to_string()),
245251
),
246252
(
247253
OPAMP_CD_CHART_VERSION_ATTRIBUTE_KEY,
248-
proto::any_value::Value::StringValue(cd_chart_version.to_string()),
254+
Value::StringValue(cd_chart_version.to_string()),
249255
),
250256
]))
251257
}

agent-control/tests/k8s/scenarios/attributes.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::k8s::tools::{
1212
use newrelic_agent_control::agent_control::agent_id::AgentID;
1313
use newrelic_agent_control::agent_control::defaults::{
1414
AGENT_CONTROL_VERSION, CLUSTER_NAME_ATTRIBUTE_KEY, FLEET_ID_ATTRIBUTE_KEY,
15-
HOST_NAME_ATTRIBUTE_KEY, OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, OPAMP_SERVICE_NAME,
16-
OPAMP_SERVICE_NAMESPACE, OPAMP_SERVICE_VERSION, OPAMP_SUBAGENT_CHART_VERSION_ATTRIBUTE_KEY,
17-
PARENT_AGENT_ID_ATTRIBUTE_KEY,
15+
HOST_NAME_ATTRIBUTE_KEY, OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, OPAMP_SERVICE_INSTANCE_ID,
16+
OPAMP_SERVICE_NAME, OPAMP_SERVICE_NAMESPACE, OPAMP_SERVICE_VERSION,
17+
OPAMP_SUBAGENT_CHART_VERSION_ATTRIBUTE_KEY, PARENT_AGENT_ID_ATTRIBUTE_KEY,
1818
};
1919
use nix::unistd::gethostname;
2020
use opamp_client::opamp::proto::any_value::Value;
@@ -61,6 +61,10 @@ agents:
6161
);
6262

6363
let ac_expected_identifying_attributes = convert_to_vec_key_value(Vec::from([
64+
(
65+
OPAMP_SERVICE_INSTANCE_ID,
66+
Value::StringValue("hello-world".to_string()),
67+
),
6468
(
6569
OPAMP_SERVICE_NAMESPACE,
6670
Value::StringValue("newrelic".to_string()),

0 commit comments

Comments
 (0)