Skip to content

Commit 3973401

Browse files
Merge pull request #296 from newrelic/0.5.2_fixes
0.5.2 fixes
2 parents 797bacf + 6ae149d commit 3973401

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "newrelic_super_agent"
33
description = "New Relic Super Agent Limited Preview"
4-
version = "0.5.2"
4+
version = "0.5.3"
55
edition = "2021"
66
authors = ["The New Relic Core Agent & Open Standards (CAOS) Team"]
77
publish = false

src/bin/main.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ use newrelic_super_agent::opamp::instance_id::getter::ULIDInstanceIDGetter;
33
use newrelic_super_agent::opamp::instance_id::{self, Identifiers, Storer};
44
use newrelic_super_agent::opamp::remote_config_hash::HashRepositoryFile;
55
use newrelic_super_agent::sub_agent::values::values_repository::ValuesRepositoryFile;
6-
use newrelic_super_agent::super_agent::defaults::SUPER_AGENT_TYPE;
76
use newrelic_super_agent::super_agent::error::AgentError;
87
use newrelic_super_agent::super_agent::opamp::client_builder::SuperAgentOpAMPHttpBuilder;
9-
use newrelic_super_agent::super_agent::super_agent::{SuperAgent, SuperAgentEvent};
8+
use newrelic_super_agent::super_agent::super_agent::{
9+
super_agent_fqn, SuperAgent, SuperAgentEvent,
10+
};
1011
use newrelic_super_agent::{cli::Cli, context::Context, logging::Logging};
12+
use nix::unistd::gethostname;
13+
use opamp_client::operation::settings::DescriptionValueType;
14+
use std::collections::HashMap;
1115
use std::error::Error;
1216
use tracing::{error, info};
1317

@@ -83,11 +87,8 @@ fn run_super_agent(
8387
opamp_client_builder: Option<SuperAgentOpAMPHttpBuilder>,
8488
instance_id_getter: ULIDInstanceIDGetter<Storer>,
8589
) -> Result<(), AgentError> {
86-
use std::collections::HashMap;
87-
8890
use newrelic_super_agent::{
89-
config::super_agent_configs::{AgentID, AgentTypeFQN},
90-
opamp::operations::build_opamp_and_start_client,
91+
config::super_agent_configs::AgentID, opamp::operations::build_opamp_and_start_client,
9192
sub_agent::opamp::client_builder::SubAgentOpAMPHttpBuilder,
9293
super_agent::effective_agents_assembler::LocalEffectiveAgentsAssembler,
9394
};
@@ -119,8 +120,8 @@ fn run_super_agent(
119120
opamp_client_builder.as_ref(),
120121
&instance_id_getter,
121122
AgentID::new_super_agent_id(),
122-
&AgentTypeFQN::from(SUPER_AGENT_TYPE),
123-
HashMap::new(),
123+
&super_agent_fqn(),
124+
super_agent_opamp_non_identifying_attributes(),
124125
)?;
125126

126127
SuperAgent::new(
@@ -141,11 +142,8 @@ fn run_super_agent(
141142
opamp_client_builder: Option<SuperAgentOpAMPHttpBuilder>,
142143
instance_id_getter: ULIDInstanceIDGetter<Storer>,
143144
) -> Result<(), AgentError> {
144-
use std::collections::HashMap;
145-
146145
use newrelic_super_agent::{
147-
config::super_agent_configs::{AgentID, AgentTypeFQN},
148-
opamp::operations::build_opamp_and_start_client,
146+
config::super_agent_configs::AgentID, opamp::operations::build_opamp_and_start_client,
149147
};
150148

151149
let hash_repository = HashRepositoryFile::default();
@@ -163,8 +161,8 @@ fn run_super_agent(
163161
opamp_client_builder.as_ref(),
164162
&instance_id_getter,
165163
AgentID::new_super_agent_id(),
166-
&AgentTypeFQN::from(SUPER_AGENT_TYPE),
167-
HashMap::new(),
164+
&super_agent_fqn(),
165+
super_agent_opamp_non_identifying_attributes(),
168166
)?;
169167

170168
SuperAgent::new(
@@ -190,3 +188,14 @@ fn create_shutdown_signal_handler(
190188

191189
Ok(())
192190
}
191+
192+
fn super_agent_opamp_non_identifying_attributes() -> HashMap<String, DescriptionValueType> {
193+
HashMap::from([(
194+
"host.name".to_string(),
195+
gethostname()
196+
.unwrap_or_default()
197+
.into_string()
198+
.unwrap()
199+
.into(),
200+
)])
201+
}

src/config/store.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::config::super_agent_configs::SuperAgentConfig;
22
use crate::{config::error::SuperAgentConfigError, super_agent::defaults::SUPER_AGENT_DATA_DIR};
33
use std::fs;
4-
use std::fs::OpenOptions;
54
use std::path::{Path, PathBuf};
65
use thiserror::Error;
76
use tracing::warn;
@@ -81,12 +80,6 @@ impl SuperAgentConfigStoreFile {
8180

8281
pub fn with_remote(self) -> Result<Self, SuperAgentConfigStoreError> {
8382
let remote_path = format!("{}/{}", SUPER_AGENT_DATA_DIR, "config.yaml");
84-
// create and open the file in read-write mode even if does not exists
85-
let _ = OpenOptions::new()
86-
.read(true)
87-
.write(true)
88-
.create(true)
89-
.open(&remote_path)?;
9083

9184
Ok(Self {
9285
local_path: self.local_path,
@@ -119,6 +112,7 @@ impl SuperAgentConfigStoreFile {
119112
&self,
120113
sub_agents: &SubAgentsConfig,
121114
) -> Result<(), SuperAgentConfigStoreError> {
115+
//TODO we should inject DirectoryManager and ensure the directory exists
122116
if let Some(remote_path_file) = &self.remote_path {
123117
Ok(serde_yaml::to_writer(
124118
fs::File::create(remote_path_file)?,

src/super_agent/super_agent.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config::error::SuperAgentConfigError;
44
use crate::config::persister::config_writer_file::WriterFile;
55
use crate::config::persister::directory_manager::DirectoryManagerFs;
66
use crate::config::store::{SubAgentsConfigStore, SuperAgentConfigStoreFile};
7-
use crate::config::super_agent_configs::{AgentID, SubAgentConfig, SubAgentsConfig};
7+
use crate::config::super_agent_configs::{AgentID, AgentTypeFQN, SubAgentConfig, SubAgentsConfig};
88
use crate::context::Context;
99
use crate::opamp::callbacks::AgentCallbacks;
1010
use crate::opamp::remote_config::{RemoteConfig, RemoteConfigError};
@@ -20,6 +20,7 @@ use crate::sub_agent::SubAgentBuilder;
2020

2121
use crate::sub_agent::values::values_repository::{ValuesRepository, ValuesRepositoryFile};
2222
use crate::sub_agent::{error::SubAgentError, NotStartedSubAgent};
23+
use crate::super_agent::defaults::{SUPER_AGENT_NAMESPACE, SUPER_AGENT_TYPE, SUPER_AGENT_VERSION};
2324
use crate::super_agent::error::AgentError;
2425
use crate::super_agent::super_agent::EffectiveAgentsError::{
2526
EffectiveAgentExists, EffectiveAgentNotFound,
@@ -107,6 +108,16 @@ where
107108
}
108109
}
109110

111+
pub fn super_agent_fqn() -> AgentTypeFQN {
112+
AgentTypeFQN::from(
113+
format!(
114+
"{}/{}:{}",
115+
SUPER_AGENT_NAMESPACE, SUPER_AGENT_TYPE, SUPER_AGENT_VERSION
116+
)
117+
.as_str(),
118+
)
119+
}
120+
110121
impl<'a, S, O, HR, SL, HRS, VR> SuperAgent<'a, S, O, HR, SL, HRS, VR>
111122
where
112123
O: StartedClient<SuperAgentCallbacks>,

0 commit comments

Comments
 (0)