Skip to content

Commit 4d38cf2

Browse files
authored
ci(apm): preload PoC basic testing improvements (#2554)
* ci: preload PoC basic testing * style: fmt * style: useless formatting directive * fix: string escapes * fix: search for shared object file
1 parent d09e834 commit 4d38cf2

5 files changed

Lines changed: 98 additions & 115 deletions

File tree

.github/workflows/component_onhost_e2e.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ permissions:
3030
env:
3131
HOST_E2E_INFRA_AGENT_VERSION: "1.74.3"
3232
HOST_E2E_NRDOT_VERSION: "1.14.0"
33+
HOST_E2E_PRELOAD_VERSION: "0.1.0"
3334

3435
jobs:
3536
build-packages:
@@ -53,6 +54,7 @@ jobs:
5354
- infra-agent
5455
- nrdot-agent
5556
- proxy
57+
- preload-agent
5658
steps:
5759
- name: Record job start time
5860
run: echo "JOB_START_TIME=$(date +%s)" >> "$GITHUB_ENV"
@@ -79,7 +81,8 @@ jobs:
7981
--agent-control-version "0.900.${{ github.run_id }}" \
8082
--recipes-repo-branch "main" \
8183
--infra-agent-version "${{ env.HOST_E2E_INFRA_AGENT_VERSION }}" \
82-
--nrdot-version "${{ env.HOST_E2E_NRDOT_VERSION }}"
84+
--nrdot-version "${{ env.HOST_E2E_NRDOT_VERSION }}" \
85+
--preload-version "${{ env.HOST_E2E_PRELOAD_VERSION }}"
8386
8487
- name: Report test result to New Relic
8588
if: always()

agent-control/agent-type-registry/newrelic/com.newrelic.preload-0.1.0.yaml

Lines changed: 0 additions & 81 deletions
This file was deleted.

test/e2e-runner/src/linux.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub fn local_config_path(agent_id: &str) -> String {
1717

1818
const DEFAULT_LOG_PATH: &str = "/var/log/newrelic-agent-control/agent-control/";
1919

20+
pub const AGENT_CONTROL_DATA_DIR: &str = "/var/lib/newrelic-agent-control";
21+
2022
const SERVICE_NAME: &str = "newrelic-agent-control";
2123

2224
/// Run Linux e2e corresponding scenario which will panic on failure
Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
use crate::common::config::{DEBUG_LOGGING_CONFIG, update_config, write_agent_local_config};
2+
use crate::common::file::write;
23
use crate::common::on_drop::CleanUp;
4+
use crate::common::test::{TestResult, retry_panic};
35
use crate::common::{InstallationArgs, RecipeData};
4-
use crate::{
5-
linux::{
6-
self,
7-
install::{install_agent_control_from_recipe, tear_down_test},
8-
bash::exec_bash_command
9-
},
6+
use crate::linux::{
7+
self,
8+
bash::exec_bash_command,
9+
install::{install_agent_control_from_recipe, tear_down_test},
1010
};
11+
use glob::glob;
12+
use std::time::Duration;
1113
use tracing::{debug, info};
1214

15+
/// Directory where Agent Control loads dynamic (custom) agent type definitions.
16+
const DYNAMIC_AGENT_TYPES_DIR: &str = "/etc/newrelic-agent-control/dynamic-agent-types";
17+
18+
/// Expected package installation directory for the preload agent.
19+
fn preload_package_dir() -> String {
20+
format!(
21+
"{}/packages/nr-preload/stored_packages/preload-agent",
22+
linux::AGENT_CONTROL_DATA_DIR
23+
)
24+
}
25+
1326
pub fn test_installation_with_preload_agent(args: InstallationArgs) {
1427
let preload_version = args
1528
.preload_version
1629
.clone()
17-
.expect("--preload-agent-version is required for this scenario");
18-
19-
let staging = matches!(args.nr_region.to_lowercase().as_str(), "staging");
30+
.expect("--preload-version is required for this scenario");
2031

2132
let recipe_data = RecipeData {
2233
args,
@@ -35,6 +46,40 @@ pub fn test_installation_with_preload_agent(args: InstallationArgs) {
3546

3647
let preload_agent_id = "nr-preload";
3748

49+
info!("Writing custom preload agent type definition");
50+
let custom_agent_type_path = format!("{DYNAMIC_AGENT_TYPES_DIR}/preload.yaml");
51+
let custom_agent_type = r#"namespace: newrelic
52+
name: com.newrelic.preload
53+
version: 0.1.0
54+
variables:
55+
linux:
56+
oci:
57+
repository:
58+
description: "Package repository name"
59+
type: string
60+
required: false
61+
default: newrelic/preload-agent-artifacts
62+
variants:
63+
ac_config_field: "oci_repository_urls"
64+
values: ["newrelic/preload-agent-artifacts"]
65+
version:
66+
description: "Agent version"
67+
type: string
68+
required: true
69+
deployment:
70+
linux:
71+
packages:
72+
preload-agent:
73+
download:
74+
oci:
75+
repository: ${nr-var:oci.repository}
76+
version: ${nr-var:version}
77+
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrpreloadagent/jwks.json
78+
"#;
79+
exec_bash_command(&format!("mkdir -p {DYNAMIC_AGENT_TYPES_DIR}"))
80+
.unwrap_or_else(|err| panic!("Failed to create dynamic agent types directory: {err}"));
81+
write(&custom_agent_type_path, custom_agent_type);
82+
3883
info!("Setup Agent Control config");
3984
update_config(
4085
linux::DEFAULT_AC_CONFIG_PATH,
@@ -51,35 +96,48 @@ agents:
5196

5297
write_agent_local_config(
5398
&linux::local_config_path(preload_agent_id),
54-
// Correct Config?
5599
format! {r#"
56-
fleet_id: alphanumeric_id # needed anymore?
57-
apm_language: java
58-
agent_version: 8.13.0
59-
application_names:
60-
- my-app
61-
- functions
62-
- lib
63-
- bin
64-
new_relic_license_key: '{{{{NEW_RELIC_LICENSE_KEY}}}}'
65-
staging: {staging}
66-
version: {preload_version}"#},
100+
version: {preload_version}"#},
67101
);
68102

103+
linux::service::restart_service(linux::SERVICE_NAME);
69104

70-
// ToDo update with actual path
71-
let ld_preload_path = "path_to_ld_preload";
72-
let install_command = format!(r#"echo "{ld_preload_path}" >> /ec/ld.so.preload"#);
73-
let output = exec_bash_command(&install_command)
74-
.unwrap_or_else(|err| panic!("Editing /ec/ld.so.preload failed: {err}"));
75-
debug!("echo output:\n{output}");
105+
info!("Waiting for preload OCI package to be downloaded and extracted");
106+
let package_dir = preload_package_dir();
107+
let retries = 60;
108+
retry_panic(
109+
retries,
110+
Duration::from_secs(10),
111+
"preload package download assertion",
112+
|| assert_preload_package_downloaded(&package_dir),
113+
);
76114

77-
linux::service::restart_service(linux::SERVICE_NAME);
115+
info!("Searching for shared library inside extracted package");
116+
let so_path = glob(&format!("{package_dir}/**/*.so"))
117+
.expect("Failed to read glob pattern")
118+
.find_map(|entry| entry.ok())
119+
.map(|path| path.to_string_lossy().into_owned())
120+
.unwrap_or_default();
121+
if so_path.is_empty() {
122+
panic!("No .so file found in extracted preload package at {package_dir}");
123+
}
124+
info!("Found shared library: {so_path}");
78125

79-
let ls_command = format!("ls {ld_preload_path}");
80-
let output = exec_bash_command(&ls_command)
81-
.unwrap_or_else(|err| panic!("Installation failed: {err}"));
82-
debug!("ls output:\n{output}");
126+
info!("Installing shared library into /etc/ld.so.preload");
127+
let install_command = format!(r#"echo "{so_path}" >> /etc/ld.so.preload"#);
128+
let output = exec_bash_command(&install_command)
129+
.unwrap_or_else(|err| panic!("Editing /etc/ld.so.preload failed: {err}"));
130+
debug!("Install output:\n{output}");
83131

84132
info!("Test completed successfully");
85133
}
134+
135+
fn assert_preload_package_downloaded(package_dir: &str) -> TestResult<()> {
136+
let output = exec_bash_command(&format!("ls -d {package_dir}"))?;
137+
if output.contains("No such file") || output.contains("cannot access") {
138+
return Err(format!("Preload package directory not found yet at {package_dir}").into());
139+
}
140+
let listing = exec_bash_command(&format!("ls -la {package_dir}"))?;
141+
debug!("Package listing:\n{listing}");
142+
Ok(())
143+
}

test/e2e-runner/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum LinuxScenarios {
3030
EBPFAgent(InstallationArgs),
3131
/// Local installation of Agent Control with NRDot. It checks that nr-dot eventually reports data.
3232
NrdotAgent(InstallationArgs),
33-
/// Local installation of Agent Control with Preload Agent. It checks that the preload-agent eventually reports data.
33+
/// Local installation of Agent Control with a custom preload agent type. Verifies that the
34+
/// OCI artifact is downloaded and present in the environment.
3435
PreloadAgent(InstallationArgs),
3536
/// Checks that remote configuration for a sub-agent has been applied.
3637
RemoteConfig(InstallationArgs),

0 commit comments

Comments
 (0)