Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,23 @@ nfpms:
file_info:
mode: 0700
- src: build/package/config.yaml
dst: /etc/newrelic-agent-control/config.yaml
dst: /etc/newrelic-agent-control/local-data/agent-control/local_config.yaml
type: config
file_info:
mode: 0600
- src: build/package/newrelic-agent-control.service
dst: /lib/systemd/system/newrelic-agent-control.service
- src: build/package/newrelic-agent-control.conf
dst: /etc/newrelic-agent-control/newrelic-agent-control.conf
dst: /etc/newrelic-agent-control/systemd-env.conf
type: config|noreplace
file_info:
mode: 0600
- dst: /etc/newrelic-agent-control/fleet/agents.d
type: dir
file_info:
mode: 0700
- src: LICENSE.md
dst: /usr/share/doc/newrelic/newrelic-agent-control/LICENSE.md
- dst: /var/lib/newrelic-agent-control
type: dir
file_info:
mode: 0700
- dst: /var/lib/newrelic-agent-control/fleet/agents.d
type: dir
file_info:
mode: 0700
- dst: /var/lib/newrelic-agent-control/auto-generated
type: dir
file_info:
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace = os.getenv('NAMESPACE','default')
sa_chart_values_file = os.getenv('SA_CHART_VALUES_FILE','local/agent-control-tilt.yml')
cluster = os.getenv('CLUSTER', "")
# Branch of the helm-charts repo to use.
feature_branch = os.getenv('FEATURE_BRANCH', "master")
feature_branch = os.getenv('FEATURE_BRANCH', "change-config-volume-path-for-agent-control")

# Remote updates are disabled by default in order to avoid accidental downgrades.
enable_ac_remote_update = os.getenv('ENABLE_AC_REMOTE_UPDATE', "false")
Expand Down
30 changes: 24 additions & 6 deletions agent-control/src/agent_control/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::agent_type::agent_type_id::AgentTypeID;
use crate::k8s::store::StoreKey;
use crate::opamp::remote_config::signature::SIGNATURE_CUSTOM_CAPABILITY;
use crate::sub_agent::identity::AgentIdentity;
use opamp_client::capabilities;
Expand Down Expand Up @@ -40,19 +41,36 @@ cfg_if::cfg_if! {
pub const AGENT_CONTROL_DATA_DIR: &str = "/opt/homebrew/var/lib/newrelic-agent-control";
pub const AGENT_CONTROL_LOG_DIR: &str = "/opt/homebrew/var/log/newrelic-agent-control";

}else{
} else if #[cfg(target_os = "windows")] {
pub const AGENT_CONTROL_LOCAL_DATA_DIR: &str = "C:\\Program Files\\New Relic\\newrelic-agent-control";
pub const AGENT_CONTROL_DATA_DIR: &str = "C:\\ProgramData\\New Relic\\newrelic-agent-control";
pub const AGENT_CONTROL_LOG_DIR: &str = "C:\\ProgramData\\New Relic\\newrelic-agent-control\\logs";

} else {
pub const AGENT_CONTROL_LOCAL_DATA_DIR: &str = "/etc/newrelic-agent-control";
pub const AGENT_CONTROL_DATA_DIR: &str = "/var/lib/newrelic-agent-control";
pub const AGENT_CONTROL_LOG_DIR: &str = "/var/log/newrelic-agent-control";
}
}

pub const SUB_AGENT_DIR: &str = "fleet/agents.d";
pub const AGENT_CONTROL_CONFIG_FILENAME: &str = "config.yaml";
/// - **On-host**: Used as the directory name (e.g., `.../local-data/`).
/// - **k8s**: Used as a ConfigMap prefix, followed by a hyphen (e.g., `local-data-agentid`).
pub const FOLDER_NAME_LOCAL_DATA: &str = "local-data";

/// - **On-host**: Used as the directory name (e.g., `.../fleet-data/`).
/// - **k8s**: Used as a ConfigMap prefix, followed by a hyphen (e.g., `fleet-data-agentid`).
pub const FOLDER_NAME_FLEET_DATA: &str = "fleet-data";

/// - **On-host**: Used as the base filename, combined with ".yaml" (e.g., `local_config.yaml`).
/// - **k8s**: Used as the data key within the local ConfigMap.
pub const STORE_KEY_LOCAL_DATA_CONFIG: &StoreKey = "local_config";

/// - **On-host**: Used as the base filename, combined with ".yaml" (e.g., `remote_config.yaml`).
/// - **k8s**: Used as the data key within the OpAMP/fleet ConfigMap.
pub const STORE_KEY_OPAMP_DATA_CONFIG: &StoreKey = "remote_config";
pub const STORE_KEY_INSTANCE_ID: &StoreKey = "instance_id";
pub const DYNAMIC_AGENT_TYPE_DIR: &str = "dynamic-agent-types";
pub const IDENTIFIERS_FILENAME: &str = "identifiers.yaml";
pub const VALUES_DIR: &str = "values";
pub const VALUES_FILENAME: &str = "values.yaml";
pub const INSTANCE_ID_FILENAME: &str = "instance_id.yaml";
pub const GENERATED_FOLDER_NAME: &str = "auto-generated";
pub const AGENT_CONTROL_LOG_FILENAME: &str = "newrelic-agent-control.log";
pub const STDOUT_LOG_PREFIX: &str = "stdout.log";
Expand Down
6 changes: 2 additions & 4 deletions agent-control/src/agent_control/run/on_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::agent_control::config_repository::store::AgentControlConfigStore;
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
use crate::agent_control::defaults::{
AGENT_CONTROL_VERSION, FLEET_ID_ATTRIBUTE_KEY, HOST_ID_ATTRIBUTE_KEY, HOST_NAME_ATTRIBUTE_KEY,
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, SUB_AGENT_DIR,
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
};
use crate::agent_control::http_server::runner::Runner;
use crate::agent_control::resource_cleaner::no_op::NoOpResourceCleaner;
Expand Down Expand Up @@ -100,7 +100,6 @@ impl AgentControlRunner {
LocalFile,
DirectoryManagerFs,
self.base_paths.remote_dir.clone(),
self.base_paths.remote_dir.join(SUB_AGENT_DIR),
);
let instance_id_getter =
InstanceIDWithIdentifiersGetter::new(instance_id_storer, identifiers);
Expand Down Expand Up @@ -154,8 +153,7 @@ impl AgentControlRunner {
&self.base_paths.remote_dir,
));

let supervisor_builder =
SupervisortBuilderOnHost::new(self.base_paths.log_dir.join(SUB_AGENT_DIR));
let supervisor_builder = SupervisortBuilderOnHost::new(self.base_paths.log_dir);

let signature_validator = Arc::new(self.signature_validator);
let remote_config_validators = vec![
Expand Down
2 changes: 1 addition & 1 deletion agent-control/src/bin/main_config_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let config_migrator = ConfigMigrator::new(
ConfigConverter::default(),
AgentConfigGetter::new(sa_local_config_loader),
ValuesPersisterFile::new(cli.local_sub_agent_data_dir()),
ValuesPersisterFile::new(cli.local_data_dir()),
);

let legacy_config_renamer = LegacyConfigRenamer::default();
Expand Down
6 changes: 1 addition & 5 deletions agent-control/src/config_migrate/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
agent_control::defaults::{
AGENT_CONTROL_DATA_DIR, AGENT_CONTROL_LOCAL_DATA_DIR, AGENT_CONTROL_LOG_DIR, SUB_AGENT_DIR,
AGENT_CONTROL_DATA_DIR, AGENT_CONTROL_LOCAL_DATA_DIR, AGENT_CONTROL_LOG_DIR,
},
config_migrate::migration::defaults::NEWRELIC_INFRA_AGENT_TYPE_CONFIG_MAPPING,
};
Expand Down Expand Up @@ -38,10 +38,6 @@ impl Cli {
self.local_dir.to_path_buf()
}

pub fn local_sub_agent_data_dir(&self) -> PathBuf {
self.local_dir.join(SUB_AGENT_DIR)
}

pub fn remote_data_dir(&self) -> PathBuf {
self.remote_dir.to_path_buf()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::agent_control::agent_id::AgentID;
use crate::agent_control::defaults::{VALUES_DIR, VALUES_FILENAME};
use crate::agent_control::defaults::{FOLDER_NAME_LOCAL_DATA, STORE_KEY_LOCAL_DATA_CONFIG};
use crate::opamp::instance_id::on_host::storer::build_config_name;
use fs::LocalFile;
use fs::directory_manager::{DirectoryManagementError, DirectoryManager, DirectoryManagerFs};
use fs::writer_file::{FileWriter, WriteError};
Expand Down Expand Up @@ -47,15 +48,12 @@ where
values_content: &str,
) -> Result<(), PersistError> {
let mut path = PathBuf::from(&self.local_agent_data_dir);
path.push(FOLDER_NAME_LOCAL_DATA);
path.push(agent_id);
if !path.exists() {
self.create_directory(&path)?;
}
path.push(VALUES_DIR);
if !path.exists() {
self.create_directory(&path)?;
}
path.push(VALUES_FILENAME);
path.push(build_config_name(STORE_KEY_LOCAL_DATA_CONFIG));

debug!("writing to file {:?}", path.as_path());

Expand Down
41 changes: 12 additions & 29 deletions agent-control/src/k8s/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ use super::Error;
use super::client::SyncK8sClient;
use super::labels::Labels;
use crate::agent_control::agent_id::AgentID;
use crate::agent_control::defaults::{FOLDER_NAME_FLEET_DATA, FOLDER_NAME_LOCAL_DATA};
use std::sync::{Arc, RwLock};

/// The prefixes for the ConfigMap name.
/// The cm having CM_NAME_LOCAL_DATA_PREFIX stores all the config that are "local",
/// the SA treats those CM as read-only.
pub const CM_NAME_LOCAL_DATA_PREFIX: &str = "local-data-";
/// The cm having CM_NAME_OPAMP_DATA_PREFIX as prefix stores all the data related with opamp:
/// Instance IDs, hashes, and remote configs. The Sa reads and writes those CMs.
pub const CM_NAME_OPAMP_DATA_PREFIX: &str = "fleet-data-";

/// The key used to identify the data in the Store.
pub type StoreKey = str;

pub const STORE_KEY_LOCAL_DATA_CONFIG: &StoreKey = "local_config";
pub const STORE_KEY_OPAMP_DATA_CONFIG: &StoreKey = "remote_config";
pub const STORE_KEY_INSTANCE_ID: &StoreKey = "instance_id";

/// Represents a Kubernetes persistent store of Agents data such as instance id and configs.
/// The store is implemented using one ConfigMap per Agent with all the data.
pub struct K8sStore {
Expand All @@ -44,7 +33,7 @@ impl K8sStore {
where
T: serde::de::DeserializeOwned,
{
self.get(agent_id, CM_NAME_OPAMP_DATA_PREFIX, key)
self.get(agent_id, FOLDER_NAME_FLEET_DATA, key)
}

/// get_local_data is used to get data from CMs storing local configurations. I.e. all the CMs
Expand All @@ -53,7 +42,7 @@ impl K8sStore {
where
T: serde::de::DeserializeOwned,
{
self.get(agent_id, CM_NAME_LOCAL_DATA_PREFIX, key)
self.get(agent_id, FOLDER_NAME_LOCAL_DATA, key)
}

/// Retrieves data from an Agent store.
Expand Down Expand Up @@ -91,7 +80,7 @@ impl K8sStore {
let _write_guard = self.rw_lock.write().unwrap();

let data_as_string = serde_yaml::to_string(data)?;
let configmap_name = K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX);
let configmap_name = K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA);
self.k8s_client.set_configmap_key(
&configmap_name,
self.namespace.as_str(),
Expand All @@ -106,21 +95,21 @@ impl K8sStore {
#[allow(clippy::readonly_write_lock)]
let _write_guard = self.rw_lock.write().unwrap();

let configmap_name = K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX);
let configmap_name = K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA);
self.k8s_client
.delete_configmap_key(&configmap_name, self.namespace.as_str(), key)
}

pub fn build_cm_name(agent_id: &AgentID, prefix: &str) -> String {
format!("{prefix}{agent_id}")
format!("{prefix}-{agent_id}")
}
}

#[cfg(test)]
pub mod tests {
use super::{CM_NAME_LOCAL_DATA_PREFIX, CM_NAME_OPAMP_DATA_PREFIX};
use super::{K8sStore, StoreKey};
use crate::agent_control::agent_id::AgentID;
use crate::agent_control::defaults::{FOLDER_NAME_FLEET_DATA, FOLDER_NAME_LOCAL_DATA};
use crate::k8s::client::MockSyncK8sClient;
use crate::k8s::error::K8sError;
use crate::k8s::labels::Labels;
Expand All @@ -132,7 +121,7 @@ pub mod tests {
const DATA_STORED: &str = "test: foo\n";
pub const STORE_KEY_TEST: &StoreKey = "data_to_be_stored";
const TEST_NAMESPACE: &str = "test-namespace";
pub const PREFIX_TEST: &StoreKey = "prefix-";
pub const PREFIX_TEST: &StoreKey = "prefix";

#[derive(Deserialize, Serialize, Default, Debug, PartialEq)]
pub struct DataToBeStored {
Expand All @@ -150,10 +139,7 @@ pub mod tests {
.expect_set_configmap_key()
.once()
.with(
predicate::eq(K8sStore::build_cm_name(
&agent_id,
CM_NAME_OPAMP_DATA_PREFIX,
)),
predicate::eq(K8sStore::build_cm_name(&agent_id, FOLDER_NAME_FLEET_DATA)),
predicate::eq(TEST_NAMESPACE),
predicate::eq(Labels::new(&AgentID::try_from(AGENT_NAME).unwrap()).get()),
predicate::eq(STORE_KEY_TEST),
Expand All @@ -164,10 +150,7 @@ pub mod tests {
.expect_delete_configmap_key()
.once()
.with(
predicate::eq(K8sStore::build_cm_name(
&agent_id,
CM_NAME_OPAMP_DATA_PREFIX,
)),
predicate::eq(K8sStore::build_cm_name(&agent_id, FOLDER_NAME_FLEET_DATA)),
predicate::eq(TEST_NAMESPACE),
predicate::eq(STORE_KEY_TEST),
)
Expand Down Expand Up @@ -195,7 +178,7 @@ pub mod tests {
k8s_client
.expect_get_configmap_key()
.with(
predicate::eq(K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX)),
predicate::eq(K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA)),
predicate::eq(TEST_NAMESPACE),
predicate::eq(STORE_KEY_TEST),
)
Expand All @@ -209,7 +192,7 @@ pub mod tests {
k8s_client
.expect_get_configmap_key()
.with(
predicate::eq(K8sStore::build_cm_name(agent_id, CM_NAME_LOCAL_DATA_PREFIX)),
predicate::eq(K8sStore::build_cm_name(agent_id, FOLDER_NAME_LOCAL_DATA)),
predicate::eq(TEST_NAMESPACE),
predicate::always(),
)
Expand Down
9 changes: 3 additions & 6 deletions agent-control/src/opamp/instance_id/k8s/storer.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use crate::agent_control::agent_id::AgentID;

use crate::k8s::{
self,
store::{K8sStore, STORE_KEY_INSTANCE_ID},
};
use super::getter::Identifiers;
use crate::agent_control::defaults::STORE_KEY_INSTANCE_ID;
use crate::k8s::{self, store::K8sStore};
use crate::opamp::instance_id::getter::DataStored;
use crate::opamp::instance_id::storer::InstanceIDStorer;
use std::sync::Arc;
use tracing::debug;

use super::getter::Identifiers;

pub struct Storer {
k8s_store: Arc<K8sStore>,
}
Expand Down
Loading
Loading