Skip to content

Commit 2f46968

Browse files
rmarraChrsMark
andauthored
feat: include container name, container ID, and container image to port endpoint (#43684)
#### Description Include container name, container ID, and container image to PortType #### Link to tracking issue Fixes [#41309](#41309) Co-authored-by: Christos Markou <[email protected]>
1 parent 2ad62f4 commit 2f46968

File tree

12 files changed

+167
-38
lines changed

12 files changed

+167
-38
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: extension/observer
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add container name, container ID, and container image to port endpoint
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [41309]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

extension/observer/endpoints.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,23 @@ type Port struct {
238238
Port uint16
239239
// Transport is the transport protocol used by the Endpoint. (TCP or UDP).
240240
Transport Transport
241+
// ContainerName is the name of the container.
242+
ContainerName string
243+
// ContainerID is the ID of the container.
244+
ContainerID string
245+
// ContainerImage is the image of the container.
246+
ContainerImage string
241247
}
242248

243249
func (p *Port) Env() EndpointEnv {
244250
return map[string]any{
245-
"name": p.Name,
246-
"port": p.Port,
247-
"pod": p.Pod.Env(),
248-
"transport": p.Transport,
251+
"name": p.Name,
252+
"port": p.Port,
253+
"pod": p.Pod.Env(),
254+
"transport": p.Transport,
255+
"container_name": p.ContainerName,
256+
"container_id": p.ContainerID,
257+
"container_image": p.ContainerImage,
249258
}
250259
}
251260

extension/observer/endpoints_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ func TestEndpointEnv(t *testing.T) {
6767
Namespace: "pod-namespace",
6868
UID: "pod-uid",
6969
},
70-
Port: 2379,
71-
Transport: ProtocolTCP,
70+
Port: 2379,
71+
Transport: ProtocolTCP,
72+
ContainerName: "test-container",
73+
ContainerID: "container-id-123456",
74+
ContainerImage: "test-app:v1.0.0",
7275
},
7376
},
7477
want: EndpointEnv{
@@ -88,8 +91,11 @@ func TestEndpointEnv(t *testing.T) {
8891
"uid": "pod-uid",
8992
"namespace": "pod-namespace",
9093
},
91-
"transport": ProtocolTCP,
92-
"host": "192.68.73.2",
94+
"transport": ProtocolTCP,
95+
"host": "192.68.73.2",
96+
"container_name": "test-container",
97+
"container_id": "container-id-123456",
98+
"container_image": "test-app:v1.0.0",
9399
},
94100
},
95101
{
@@ -257,8 +263,11 @@ func TestEndpointEnv(t *testing.T) {
257263
Namespace: "pod-namespace",
258264
UID: "pod-uid",
259265
},
260-
Port: 2379,
261-
Transport: ProtocolTCP,
266+
Port: 2379,
267+
Transport: ProtocolTCP,
268+
ContainerName: "test-container",
269+
ContainerID: "container-id-123456",
270+
ContainerImage: "test-app:v1.0.0",
262271
},
263272
},
264273
want: EndpointEnv{
@@ -278,8 +287,11 @@ func TestEndpointEnv(t *testing.T) {
278287
"uid": "pod-uid",
279288
"namespace": "pod-namespace",
280289
},
281-
"transport": ProtocolTCP,
282-
"host": "192.68.73.2",
290+
"transport": ProtocolTCP,
291+
"host": "192.68.73.2",
292+
"container_name": "test-container",
293+
"container_id": "container-id-123456",
294+
"container_image": "test-app:v1.0.0",
283295
},
284296
},
285297
{

extension/observer/endpointswatcher/endpointswatcher_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,42 @@ func TestEndpointsEqual(t *testing.T) {
344344
second: observer.Endpoint{Details: &observer.Port{Transport: "second"}},
345345
areEqual: false,
346346
},
347+
{
348+
name: "equal observer.Port ContainerName",
349+
first: observer.Endpoint{Details: &observer.Port{ContainerName: "container_name"}},
350+
second: observer.Endpoint{Details: &observer.Port{ContainerName: "container_name"}},
351+
areEqual: true,
352+
},
353+
{
354+
name: "unequal observer.Port ContainerName",
355+
first: observer.Endpoint{Details: &observer.Port{ContainerName: "first"}},
356+
second: observer.Endpoint{Details: &observer.Port{ContainerName: "second"}},
357+
areEqual: false,
358+
},
359+
{
360+
name: "equal observer.Port ContainerID",
361+
first: observer.Endpoint{Details: &observer.Port{ContainerID: "container_id"}},
362+
second: observer.Endpoint{Details: &observer.Port{ContainerID: "container_id"}},
363+
areEqual: true,
364+
},
365+
{
366+
name: "unequal observer.Port ContainerID",
367+
first: observer.Endpoint{Details: &observer.Port{ContainerID: "first"}},
368+
second: observer.Endpoint{Details: &observer.Port{ContainerID: "second"}},
369+
areEqual: false,
370+
},
371+
{
372+
name: "equal observer.Port ContainerImage",
373+
first: observer.Endpoint{Details: &observer.Port{ContainerImage: "container_image"}},
374+
second: observer.Endpoint{Details: &observer.Port{ContainerImage: "container_image"}},
375+
areEqual: true,
376+
},
377+
{
378+
name: "unequal observer.Port ContainerImage",
379+
first: observer.Endpoint{Details: &observer.Port{ContainerImage: "first"}},
380+
second: observer.Endpoint{Details: &observer.Port{ContainerImage: "second"}},
381+
areEqual: false,
382+
},
347383
{
348384
name: "equal observer.Port",
349385
first: observer.Endpoint{

extension/observer/k8sobserver/handler_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ func TestPodEndpointsAdded(t *testing.T) {
6363
Name: "pod-2",
6464
Labels: map[string]string{"env": "prod"},
6565
},
66-
Port: 443,
67-
Transport: observer.ProtocolTCP,
66+
Port: 443,
67+
Transport: observer.ProtocolTCP,
68+
ContainerName: "container-2",
69+
ContainerID: "a808232bb4a57d421bb16f20dc9ab2a441343cb0aae8c369dc375838c7a49fd7",
70+
ContainerImage: "container-image-2",
6871
},
6972
},
7073
}, th.ListEndpoints())
@@ -134,8 +137,11 @@ func TestPodEndpointsChanged(t *testing.T) {
134137
UID: "pod-2-UID",
135138
Labels: map[string]string{"env": "prod", "updated-label": "true"},
136139
},
137-
Port: 443,
138-
Transport: observer.ProtocolTCP,
140+
Port: 443,
141+
Transport: observer.ProtocolTCP,
142+
ContainerName: "container-2",
143+
ContainerID: "a808232bb4a57d421bb16f20dc9ab2a441343cb0aae8c369dc375838c7a49fd7",
144+
ContainerImage: "container-image-2",
139145
},
140146
},
141147
}, th.ListEndpoints())

extension/observer/k8sobserver/pod_endpoint.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ func convertPodToEndpoints(idNamespace string, pod *v1.Pod) []observer.Endpoint
8484
ID: endpointID,
8585
Target: fmt.Sprintf("%s:%d", podIP, port.ContainerPort),
8686
Details: &observer.Port{
87-
Pod: podDetails,
88-
Name: port.Name,
89-
Port: uint16(port.ContainerPort),
90-
Transport: getTransport(port.Protocol),
87+
Pod: podDetails,
88+
Name: port.Name,
89+
Port: uint16(port.ContainerPort),
90+
Transport: getTransport(port.Protocol),
91+
ContainerName: container.Name,
92+
ContainerID: rc.ID,
93+
ContainerImage: container.Image,
9194
},
9295
})
9396
}

extension/observer/k8sobserver/pod_endpoint_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ func TestPodObjectToPortEndpoint(t *testing.T) {
4848
UID: "pod-2-UID",
4949
Labels: map[string]string{"env": "prod"},
5050
},
51-
Port: 443,
52-
Transport: observer.ProtocolTCP,
51+
Port: 443,
52+
Transport: observer.ProtocolTCP,
53+
ContainerName: "container-2",
54+
ContainerID: "a808232bb4a57d421bb16f20dc9ab2a441343cb0aae8c369dc375838c7a49fd7",
55+
ContainerImage: "container-image-2",
5356
},
5457
},
5558
}

receiver/receivercreator/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ Note that the backticks below are not typos--they indicate the value is set dyna
115115
| k8s.pod.name | \`pod.name\` |
116116
| k8s.pod.uid | \`pod.uid\` |
117117
| k8s.namespace.name | \`pod.namespace\` |
118+
| k8s.container.name | \`container_name\` |
119+
| container.image.name | \`container_image\` |
120+
| container.id | \`container_id\` |
118121

119122
`type == "pod.container"`
120123

receiver/receivercreator/consumer_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ func TestNewEnhancingConsumer(t *testing.T) {
8383
metrics: &consumertest.MetricsSink{},
8484
traces: &consumertest.TracesSink{},
8585
attrs: map[string]string{
86-
"k8s.pod.uid": "uid-1",
87-
"k8s.pod.name": "pod-1",
88-
"k8s.namespace.name": "default",
86+
"k8s.pod.uid": "uid-1",
87+
"k8s.pod.name": "pod-1",
88+
"k8s.namespace.name": "default",
89+
"k8s.container.name": "container-1",
90+
"container.id": "container-id-1",
91+
"container.image.name": "redis:latest",
8992
},
9093
},
9194
},

receiver/receivercreator/discovery_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ endpoint: 1.2.3.4:6379`
5757
otelMetricsHints + "/config": config,
5858
},
5959
},
60-
Port: 6379,
60+
Port: 6379,
61+
ContainerName: "redis",
62+
ContainerID: "container-id-redis",
63+
ContainerImage: "redis:6.0",
6164
},
6265
},
6366
expectedReceiver: receiverTemplate{
@@ -84,7 +87,10 @@ endpoint: 1.2.3.4:6379`
8487
otelMetricsHints + "/config": config,
8588
},
8689
},
87-
Port: 6379,
90+
Port: 6379,
91+
ContainerName: "redis",
92+
ContainerID: "container-id-redis",
93+
ContainerImage: "redis:6.0",
8894
},
8995
},
9096
expectedReceiver: receiverTemplate{},
@@ -105,7 +111,10 @@ endpoint: 1.2.3.4:6379`
105111
otelMetricsHints + "/scraper": "redis",
106112
},
107113
},
108-
Port: 6379,
114+
Port: 6379,
115+
ContainerName: "redis",
116+
ContainerID: "container-id-redis",
117+
ContainerImage: "redis:6.0",
109118
},
110119
},
111120
expectedReceiver: receiverTemplate{
@@ -132,7 +141,10 @@ endpoint: 1.2.3.4:6379`
132141
otelMetricsHints + ".6379/config": config,
133142
},
134143
},
135-
Port: 6379,
144+
Port: 6379,
145+
ContainerName: "redis",
146+
ContainerID: "container-id-redis",
147+
ContainerImage: "redis:6.0",
136148
},
137149
},
138150
expectedReceiver: receiverTemplate{
@@ -160,7 +172,10 @@ endpoint: 1.2.3.4:6379`
160172
otelMetricsHints + ".6379/config": configRedis,
161173
},
162174
},
163-
Port: 6379,
175+
Port: 6379,
176+
ContainerName: "redis",
177+
ContainerID: "container-id-redis",
178+
ContainerImage: "redis:6.0",
164179
},
165180
},
166181
expectedReceiver: receiverTemplate{
@@ -187,6 +202,9 @@ endpoint: 1.2.3.4:6379`
187202
otelMetricsHints + "/config": config,
188203
},
189204
},
205+
ContainerName: "redis",
206+
ContainerID: "container-id-redis",
207+
ContainerImage: "redis:6.0",
190208
},
191209
},
192210
expectedReceiver: receiverTemplate{},

0 commit comments

Comments
 (0)