Skip to content

Commit fb38a29

Browse files
feat(apm): pass application name
1 parent 800dedc commit fb38a29

File tree

12 files changed

+140
-23
lines changed

12 files changed

+140
-23
lines changed

Tiltfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ local_resource(
109109
)
110110

111111
ac_flags = [
112-
'--timeout=150s',
112+
'--timeout=100s',
113113
'--create-namespace',
114114
'--set=agentControlDeployment.chartRepositoryUrl=http://chartmuseum.default.svc.cluster.local:8080',
115115
'--set=agentControlDeployment.chartVersion=0.0.1',
@@ -190,4 +190,4 @@ helm_resource(
190190
)
191191

192192
# We had flaky e2e test failing due to timeout applying the chart on 30s
193-
update_settings(k8s_upsert_timeout_secs=200)
193+
update_settings(k8s_upsert_timeout_secs=100)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: com.newrelic.apm_dotnet
33
version: 0.1.0
44
variables:
55
k8s:
6+
applicationName:
7+
description: "application name to leverage"
8+
type: string
9+
required: true
610
podLabelSelector:
711
description: "Pod label selector"
812
type: yaml
@@ -86,6 +90,8 @@ deployment:
8690
# Hence, the namespace is set to "nr-ac:namespace_agents".
8791
# Reference: https://github.com/newrelic/k8s-agents-operator/blob/92c19208864f051f03f457ee04b772fca5042162/api/v1beta1/instrumentation_webhook.go#L110C27-L110C72
8892
namespace: ${nr-ac:namespace_agents}
93+
annotations:
94+
newrelic.com/app-name: ${nr-var:applicationName}
8995
spec:
9096
agent:
9197
language: dotnet

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: com.newrelic.apm_java
33
version: 0.1.0
44
variables:
55
k8s:
6+
applicationName:
7+
description: "application name to leverage"
8+
type: string
9+
required: true
610
podLabelSelector:
711
description: "Pod label selector"
812
type: yaml
@@ -91,6 +95,8 @@ deployment:
9195
# Hence, the namespace is set to "nr-ac:namespace_agents".
9296
# Reference: https://github.com/newrelic/k8s-agents-operator/blob/92c19208864f051f03f457ee04b772fca5042162/api/v1beta1/instrumentation_webhook.go#L110C27-L110C72
9397
namespace: ${nr-ac:namespace_agents}
98+
annotations:
99+
newrelic.com/app-name: ${nr-var:applicationName}
94100
spec:
95101
agent:
96102
language: java

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: com.newrelic.apm_node
33
version: 0.1.0
44
variables:
55
k8s:
6+
applicationName:
7+
description: "application name to leverage"
8+
type: string
9+
required: true
610
podLabelSelector:
711
description: "Pod label selector"
812
type: yaml
@@ -86,6 +90,8 @@ deployment:
8690
# Hence, the namespace is set to "nr-ac:namespace_agents".
8791
# Reference: https://github.com/newrelic/k8s-agents-operator/blob/92c19208864f051f03f457ee04b772fca5042162/api/v1beta1/instrumentation_webhook.go#L110C27-L110C72
8892
namespace: ${nr-ac:namespace_agents}
93+
annotations:
94+
newrelic.com/app-name: ${nr-var:applicationName}
8995
spec:
9096
agent:
9197
language: nodejs

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: com.newrelic.apm_python
33
version: 0.1.0
44
variables:
55
k8s:
6+
applicationName:
7+
description: "application name to leverage"
8+
type: string
9+
required: true
610
podLabelSelector:
711
description: "Pod label selector"
812
type: yaml
@@ -86,6 +90,8 @@ deployment:
8690
# Hence, the namespace is set to "nr-ac:namespace_agents".
8791
# Reference: https://github.com/newrelic/k8s-agents-operator/blob/92c19208864f051f03f457ee04b772fca5042162/api/v1beta1/instrumentation_webhook.go#L110C27-L110C72
8892
namespace: ${nr-ac:namespace_agents}
93+
annotations:
94+
newrelic.com/app-name: ${nr-var:applicationName}
8995
spec:
9096
agent:
9197
language: python

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: com.newrelic.apm_ruby
33
version: 0.1.0
44
variables:
55
k8s:
6+
applicationName:
7+
description: "application name to leverage"
8+
type: string
9+
required: true
610
podLabelSelector:
711
description: "Pod label selector"
812
type: yaml
@@ -86,6 +90,8 @@ deployment:
8690
# Hence, the namespace is set to "nr-ac:namespace_agents".
8791
# Reference: https://github.com/newrelic/k8s-agents-operator/blob/92c19208864f051f03f457ee04b772fca5042162/api/v1beta1/instrumentation_webhook.go#L110C27-L110C72
8892
namespace: ${nr-ac:namespace_agents}
93+
annotations:
94+
newrelic.com/app-name: ${nr-var:applicationName}
8995
spec:
9096
agent:
9197
language: ruby

agent-control/src/agent_type/definition/agent_type_validation_tests.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ static AGENT_TYPE_APM_DOTNET: LazyLock<AgentTypeValuesTestCase> =
4545
agent_type: "newrelic/com.newrelic.apm_dotnet:0.1.0",
4646
values_k8s: AgentTypeValues {
4747
cases: HashMap::from([
48-
("mandatory fields only", r#"version: "some-version""#),
48+
(
49+
"mandatory fields only",
50+
r#"
51+
version: "some-version"
52+
applicationName: "whatever"
53+
"#,
54+
),
4955
(
5056
"check all value types are correct",
5157
r#"
5258
version: "some-string"
59+
applicationName: "whatever"
5360
podLabelSelector:
5461
yaml: object
5562
namespaceLabelSelector:
@@ -70,11 +77,18 @@ static AGENT_TYPE_APM_JAVA: LazyLock<AgentTypeValuesTestCase> =
7077
agent_type: "newrelic/com.newrelic.apm_java:0.1.0",
7178
values_k8s: AgentTypeValues {
7279
cases: HashMap::from([
73-
("mandatory fields only", r#"version: "some-version""#),
80+
(
81+
"mandatory fields only",
82+
r#"
83+
version: "some-version"
84+
applicationName: "whatever"
85+
"#,
86+
),
7487
(
7588
"check all value types are correct",
7689
r#"
7790
version: "some-string"
91+
applicationName: "whatever"
7892
podLabelSelector:
7993
yaml: object
8094
namespaceLabelSelector:
@@ -95,11 +109,18 @@ static AGENT_TYPE_APM_NODE: LazyLock<AgentTypeValuesTestCase> =
95109
agent_type: "newrelic/com.newrelic.apm_node:0.1.0",
96110
values_k8s: AgentTypeValues {
97111
cases: HashMap::from([
98-
("mandatory fields only", r#"version: "some-version""#),
112+
(
113+
"mandatory fields only",
114+
r#"
115+
version: "some-version"
116+
applicationName: "whatever"
117+
"#,
118+
),
99119
(
100120
"check all value types are correct",
101121
r#"
102122
version: "some-string"
123+
applicationName: "whatever"
103124
podLabelSelector:
104125
yaml: object
105126
namespaceLabelSelector:
@@ -120,11 +141,18 @@ static AGENT_TYPE_APM_PYTHON: LazyLock<AgentTypeValuesTestCase> =
120141
agent_type: "newrelic/com.newrelic.apm_python:0.1.0",
121142
values_k8s: AgentTypeValues {
122143
cases: HashMap::from([
123-
("mandatory fields only", r#"version: "some-version""#),
144+
(
145+
"mandatory fields only",
146+
r#"
147+
version: "some-version"
148+
applicationName: "whatever"
149+
"#,
150+
),
124151
(
125152
"check all value types are correct",
126153
r#"
127154
version: "some-string"
155+
applicationName: "whatever"
128156
podLabelSelector:
129157
yaml: object
130158
namespaceLabelSelector:
@@ -145,11 +173,18 @@ static AGENT_TYPE_APM_RUBY: LazyLock<AgentTypeValuesTestCase> =
145173
agent_type: "newrelic/com.newrelic.apm_ruby:0.1.0",
146174
values_k8s: AgentTypeValues {
147175
cases: HashMap::from([
148-
("mandatory fields only", r#"version: "some-version""#),
176+
(
177+
"mandatory fields only",
178+
r#"
179+
version: "some-version"
180+
applicationName: "whatever"
181+
"#,
182+
),
149183
(
150184
"check all value types are correct",
151185
r#"
152186
version: "some-string"
187+
applicationName: "whatever"
153188
podLabelSelector:
154189
yaml: object
155190
namespaceLabelSelector:

agent-control/src/agent_type/runtime_config/k8s.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct K8sObject {
3737
pub struct K8sObjectMeta {
3838
#[serde(default)]
3939
pub labels: BTreeMap<String, String>,
40+
#[serde(default)]
41+
pub annotations: BTreeMap<String, String>,
4042
pub name: String,
4143
pub namespace: String,
4244
}
@@ -79,6 +81,11 @@ impl Templateable for K8sObjectMeta {
7981
.into_iter()
8082
.map(|(k, v)| Ok((k.template_with(variables)?, v.template_with(variables)?)))
8183
.collect::<Result<BTreeMap<String, String>, AgentTypeError>>()?,
84+
annotations: self
85+
.annotations
86+
.into_iter()
87+
.map(|(k, v)| Ok((k.template_with(variables)?, v.template_with(variables)?)))
88+
.collect::<Result<BTreeMap<String, String>, AgentTypeError>>()?,
8289
name: self.name.template_with(variables)?,
8390
namespace: self.namespace.template_with(variables)?,
8491
})
@@ -157,6 +164,8 @@ objects:
157164
namespace: test-namespace
158165
labels:
159166
foo: bar
167+
annotations:
168+
foo2: bar2
160169
key: value # no spec field
161170
"#;
162171

@@ -189,6 +198,11 @@ objects:
189198
&k8s.objects["cr4"].metadata.clone().labels["foo"].clone()
190199
);
191200

201+
assert_eq!(
202+
"bar2",
203+
&k8s.objects["cr4"].metadata.clone().annotations["foo2"].clone()
204+
);
205+
192206
assert_eq!("test", &k8s.objects["cr4"].metadata.clone().name);
193207
}
194208

agent-control/src/k8s/annotations.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ impl Annotations {
1717
annotations
1818
}
1919

20+
/// Adds extra annotations to the collection WITHOUT replacing existing ones.
21+
pub fn append_extra_annotations(&mut self, annotations: &BTreeMap<String, String>) {
22+
for (label, value) in annotations.iter() {
23+
self.0.entry(label.clone()).or_insert(value.clone());
24+
}
25+
}
26+
2027
pub fn get(&self) -> BTreeMap<String, String> {
2128
self.0.clone()
2229
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ impl NotStartedSupervisorK8s {
131131
// Merge default labels with the ones coming from the config with default labels taking precedence.
132132
labels.append_extra_labels(&k8s_obj.metadata.labels);
133133

134-
let annotations =
134+
let mut annotations =
135135
Annotations::new_agent_type_id_annotation(&self.agent_identity.agent_type_id);
136+
annotations.append_extra_annotations(&k8s_obj.metadata.annotations);
136137

137138
let metadata = ObjectMeta {
138139
name: Some(k8s_obj.metadata.name.clone()),
@@ -575,6 +576,7 @@ pub mod tests {
575576
]),
576577
name: TEST_NAME.to_string(),
577578
namespace: TEST_NAMESPACE.to_string(),
579+
..Default::default()
578580
},
579581
..Default::default()
580582
}

0 commit comments

Comments
 (0)