Skip to content

Commit 20ddfa5

Browse files
feat(OpAMP): adding new attributes
Signed-off-by: Paolo Gallina <paologallina1992@gmail.com>
1 parent 56d5c3b commit 20ddfa5

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

Tiltfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- mode: Python -*-
22
# This Tiltfile is used by the e2e tests to setup the environment and for local development.
3-
ci_settings(readiness_timeout = '10m')
4-
53
load('ext://helm_resource', 'helm_repo','helm_resource')
64
load('ext://git_resource', 'git_checkout')
75

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ variables:
2323
type: yaml
2424
default: [ ]
2525
required: false
26+
app_id_poc:
27+
description: "Application ID"
28+
type: string
29+
default: ""
30+
required: false
2631
health_env:
2732
description: "environment variables to pass to health sidecar"
2833
type: yaml

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::agent_control::config::K8sConfig;
2-
use crate::agent_control::defaults::{CLUSTER_NAME_ATTRIBUTE_KEY, OPAMP_SERVICE_VERSION};
2+
use crate::agent_control::defaults::{
3+
CLUSTER_NAME_ATTRIBUTE_KEY, OPAMP_SERVICE_VERSION, default_capabilities,
4+
};
35
use crate::agent_control::run::Environment;
6+
use crate::agent_type::templates::Templateable;
47
use crate::event::SubAgentEvent;
58
use crate::event::broadcaster::unbounded::UnboundedBroadcast;
69
use crate::event::channel::pub_sub;
@@ -94,6 +97,18 @@ where
9497
agent_identity: &AgentIdentity,
9598
) -> Result<Self::NotStartedSubAgent, SubAgentBuilderError> {
9699
debug!("building subAgent");
100+
let unknown = "unknown";
101+
let app_id_poc = self
102+
.config_repository
103+
.load_remote_fallback_local(&agent_identity.id, &default_capabilities())
104+
.unwrap_or_default()
105+
.unwrap_or_default()
106+
.get_yaml_config()
107+
.get("app_id_poc")
108+
.map(|x| x.as_str())
109+
.unwrap_or_default()
110+
.unwrap_or_else(|| &unknown)
111+
.to_string();
97112

98113
let (maybe_opamp_client, sub_agent_opamp_consumer) = self
99114
.opamp_builder
@@ -102,10 +117,13 @@ where
102117
builder,
103118
self.instance_id_getter,
104119
agent_identity,
105-
HashMap::from([(
106-
OPAMP_SERVICE_VERSION.to_string(),
107-
agent_identity.agent_type_id.version().to_string().into(),
108-
)]),
120+
HashMap::from([
121+
(
122+
OPAMP_SERVICE_VERSION.to_string(),
123+
agent_identity.agent_type_id.version().to_string().into(),
124+
),
125+
("apm.application.id".to_string(), app_id_poc.into()),
126+
]),
109127
HashMap::from([(
110128
CLUSTER_NAME_ATTRIBUTE_KEY.to_string(),
111129
DescriptionValueType::String(self.k8s_config.cluster_name.to_string()),

agent-control/src/values/yaml_config.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::agent_type::templates::Templateable;
44
use opamp_client::opamp::proto::AgentCapabilities;
55
use opamp_client::operation::capabilities::Capabilities;
66
use serde::{Deserialize, Serialize};
7+
use serde_yaml::Value;
78
use std::collections::HashMap;
89
use thiserror::Error;
910

@@ -36,6 +37,17 @@ impl Templateable for HashMap<String, serde_yaml::Value> {
3637
}
3738
}
3839

40+
impl YAMLConfig {
41+
pub(crate) fn new(values: HashMap<String, Value>) -> Self {
42+
Self(values)
43+
}
44+
45+
#[allow(dead_code)]
46+
pub(crate) fn get(&self, key: &str) -> Option<&Value> {
47+
self.0.get(key)
48+
}
49+
}
50+
3951
impl From<YAMLConfig> for HashMap<String, serde_yaml::Value> {
4052
fn from(values: YAMLConfig) -> Self {
4153
values.0
@@ -88,17 +100,6 @@ mod tests {
88100

89101
use super::*;
90102

91-
impl YAMLConfig {
92-
pub(crate) fn new(values: HashMap<String, Value>) -> Self {
93-
Self(values)
94-
}
95-
96-
#[allow(dead_code)]
97-
pub(crate) fn get(&self, key: &str) -> Option<&Value> {
98-
self.0.get(key)
99-
}
100-
}
101-
102103
const EXAMPLE_CONFIG: &str = r#"
103104
description:
104105
name: newrelic-infra

test/k8s-e2e/apm/ac-values-apm.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ agentControlDeployment:
3535
- key: "app"
3636
operator: "In"
3737
values: [ "javaapp" ]
38+
app_id_poc: my-java-app-id
3839
python-agent:
3940
podLabelSelector:
4041
matchExpressions:

0 commit comments

Comments
 (0)