Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ coverage/

# zig compiler
.zig-cache/

# vscode config dir
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace: newrelic
name: com.newrelic.preload
version: 0.1.0
variables:
linux:
config_agent:
description: "Newrelic preload configuration"
type: yaml
required: false
default: ""
enable_file_logging:
description: "enable logging the on host executables' logs to files"
type: bool
required: false
default: false
oci:
repository:
description: "Package repository name"
type: string
required: false
default: newrelic/preload-agent-artifacts
variants:
ac_config_field: "oci_repository_urls"
values: [ "newrelic/preload-agent-artifacts" ]
version:
description: "Agent version"
type: string
required: true

deployment:
linux:
enable_file_logging: ${nr-var:enable_file_logging}
packages:
preload-agent:
download:
oci:
repository: ${nr-var:oci.repository}
version: ${nr-var:version}
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrpreloadagent/jwks.json
version:
path: ${nr-sub:packages.preload-agent.dir}/newrelic-preload
args:
- --version
regex: \d+\.\d+\.\d+
filesystem:
config:
newrelic-preload.yaml: |
${nr-var:config_agent}
logging.d: ${nr-var:config_logging}
executables:
- id: newrelic-preload
path: ${nr-sub:packages.preload-agent.dir}/newrelic-preload
args:
- --config
- ${nr-sub:filesystem_agent_dir}/config/newrelic-preload.yaml
env:
# NRIA_AGENT_DIR is needed in order to change the root directory for the agent data on Linux.
# This is useful to make sure that all the data generated by the agent is stored inside the AC managed filesystem directory.
# Otherwise, a user could write data to a folder with lower permissions and potentially escalate privileges.
# For the same reason we are also changing the location of the integration binaries.
NRIA_AGENT_DIR: "${nr-sub:filesystem_agent_dir}/newrelic-preload"
# TODO
# This is a non public preload-agent config variable that allows us to change the location of the agent temporary files, which is used currently
# for storing fluent-bit generated configuration files. Currently preload-agent does not clean-up on start this directory if
# not on the default location, making this configs to potentially grow indefinitely with fluent-bit generated files.
# In the future this clean up process should be handled by the preload-agent itself or by AC file system clean up policies (same as the ones
# that are going to remove integration configs whenever variables are removed)
NRIA_AGENT_TEMP_DIR: "${nr-sub:filesystem_agent_dir}/newrelic-preload/tmp"
NRIA_CUSTOM_PLUGIN_INSTALLATION_DIR: "${nr-sub:packages.preload-agent.dir}/integrations"
NRIA_SAFE_BIN_DIR: "${nr-sub:packages.preload-agent.dir}/integrations"
# Config folders where integrations and logging configs parsed from local/remote values are stored and looked for.
NRIA_PLUGIN_DIR: "${nr-sub:filesystem_agent_dir}/integrations.d"
NRIA_LOGGING_CONFIGS_DIR: "${nr-sub:filesystem_agent_dir}/logging.d"
# Where parsers.conf and out_newrelic.so are placed and fb.db will be created
NRIA_LOGGING_HOME_DIR: "${nr-sub:packages.preload-agent.dir}/logging"
# NRIA_LOGGING_BIN_DIR is not added because it continues being installed with apt, yum, zypp in its current location.
NRIA_STATUS_SERVER_ENABLED: true
NRIA_STATUS_SERVER_PORT: "${nr-var:health_port}"
NR_HOST_ID: "${nr-ac:host_id}"


4 changes: 4 additions & 0 deletions test/e2e-runner/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ pub struct InstallationArgs {
/// Version of the NRDot OCI image to use in tests
#[arg(long)]
pub nrdot_version: Option<String>,

/// Version of the preload OCI image to use in tests
#[arg(long)]
pub preload_version: Option<String>,
}

/// Arguments for Fleet Control scenarios that also install Agent Control
Expand Down
3 changes: 3 additions & 0 deletions test/e2e-runner/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub fn run_linux_e2e() {
LinuxScenarios::NrdotAgent(args) => {
scenarios::nrdot_agent::test_nrdot_agent(args);
}
LinuxScenarios::PreloadAgent(args) => {
scenarios::preload_agent::test_installation_with_preload_agent(args);
}
LinuxScenarios::RemoteConfig(args) => {
scenarios::remote_config::test_remote_config_is_applied(args);
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e-runner/src/linux/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pub mod ebpf_agent;
pub mod fleet_control;
pub mod infra_agent;
pub mod nrdot_agent;
pub mod preload_agent;
pub mod proxy;
pub mod remote_config;
81 changes: 81 additions & 0 deletions test/e2e-runner/src/linux/scenarios/preload_agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::common::config::{DEBUG_LOGGING_CONFIG, update_config, write_agent_local_config};
use crate::common::on_drop::CleanUp;
use crate::common::test::retry_panic;
use crate::common::{InstallationArgs, RecipeData};
use crate::{
common::nrql,
linux::{
self,
install::{install_agent_control_from_recipe, tear_down_test},
},
};
use std::time::Duration;
use tracing::info;

pub fn test_installation_with_preload_agent(args: InstallationArgs) {
let preload_version = args
.preload_version
.clone()
.expect("--preload-agent-version is required for this scenario");

let staging = matches!(args.nr_region.to_lowercase().as_str(), "staging");

let recipe_data = RecipeData {
args,
monitoring_source: "preload-agent".to_string(),
..Default::default()
};

let _clean_up = CleanUp::new(tear_down_test);

install_agent_control_from_recipe(&recipe_data);

let test_id = format!(
"onhost-e2e-preload-agent_{}",
chrono::Local::now().format("%Y-%m-%d_%H-%M-%S%.3f")
);

let preload_agent_id = "nr-preload";

info!("Setup Agent Control config");
update_config(
linux::DEFAULT_AC_CONFIG_PATH,
format!(
r#"
host_id: {test_id}
agents:
nr-preload:
agent_type: "newrelic/com.newrelic.preload:0.1.0"
{DEBUG_LOGGING_CONFIG}
"#
),
);

write_agent_local_config(
&linux::local_config_path(preload_agent_id),
// Correct Config?
format! {r#"
fleet_id: alphanumeric_id # needed anymore?
apm_language: java
agent_version: 8.13.0
application_names:
- my-app
- functions
- lib
- bin
new_relic_license_key: '{{{{NEW_RELIC_LICENSE_KEY}}}}'
staging: {staging}
version: {preload_version}"#},
);

linux::service::restart_service(linux::SERVICE_NAME);

let nrql_query = format!(r#"SELECT * FROM SystemSample WHERE `host.id` = '{test_id}' LIMIT 1"#);
info!(nrql = nrql_query, "Checking results of NRQL to check logs");
let retries = 30;
retry_panic(retries, Duration::from_secs(10), "nrql assertion", || {
nrql::check_query_results_are_not_empty(&recipe_data.args, &nrql_query)
});

info!("Test completed successfully");
}
2 changes: 2 additions & 0 deletions test/e2e-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum LinuxScenarios {
EBPFAgent(InstallationArgs),
/// Local installation of Agent Control with NRDot. It checks that nr-dot eventually reports data.
NrdotAgent(InstallationArgs),
/// Local installation of Agent Control with Preload Agent. It checks that the preload-agent eventually reports data.
PreloadAgent(InstallationArgs),
/// Checks that remote configuration for a sub-agent has been applied.
RemoteConfig(InstallationArgs),
/// Checks that the Agent Control proxy support works as expected. It uses mitproxy as a docker service.
Expand Down
Loading