Skip to content

Commit f46e096

Browse files
committed
pr review
1 parent 4e46084 commit f46e096

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

processor/k8sattributesprocessor/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ type ExtractConfig struct {
173173
OtelAnnotations bool `mapstructure:"otel_annotations"`
174174

175175
// ServiceAttributes allows to extract service attributes based on kubernetes metadata.
176-
ServiceAttributes ServiceAttributeConfig `mapstructure:"service_attributes"`
176+
ServiceAttributes ServiceAttributesConfig `mapstructure:"service_attributes"`
177177
}
178178

179-
// ServiceAttributeConfig allows to extract service attributes based on kubernetes metadata.
180-
type ServiceAttributeConfig struct {
179+
// ServiceAttributesConfig allows to extract service attributes based on kubernetes metadata.
180+
type ServiceAttributesConfig struct {
181181
// Enabled enables the extraction of service attributes based on kubernetes metadata.
182182
Enabled bool `mapstructure:"enabled"`
183183
// WellKnownLabels enables the extraction of well-known labels as service attributes.

processor/k8sattributesprocessor/internal/kube/client.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
457457
if c.Rules.PodName {
458458
tags[conventions.AttributeK8SPodName] = pod.Name
459459
}
460-
if c.Rules.Service {
460+
if c.Rules.ServiceAttributes {
461461
serviceNames[conventions.AttributeK8SPodName] = pod.Name
462462
}
463463

@@ -494,7 +494,7 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
494494
c.Rules.JobUID || c.Rules.JobName ||
495495
c.Rules.StatefulSetUID || c.Rules.StatefulSetName ||
496496
c.Rules.DeploymentName || c.Rules.DeploymentUID ||
497-
c.Rules.CronJobName || c.Rules.Service {
497+
c.Rules.CronJobName || c.Rules.ServiceAttributes {
498498
for _, ref := range pod.OwnerReferences {
499499
switch ref.Kind {
500500
case "ReplicaSet":
@@ -504,17 +504,17 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
504504
if c.Rules.ReplicaSetName {
505505
tags[conventions.AttributeK8SReplicaSetName] = ref.Name
506506
}
507-
if c.Rules.Service {
507+
if c.Rules.ServiceAttributes {
508508
serviceNames[conventions.AttributeK8SReplicaSetName] = ref.Name
509509
}
510-
if c.Rules.DeploymentName || c.Rules.Service {
510+
if c.Rules.DeploymentName || c.Rules.ServiceAttributes {
511511
if replicaset, ok := c.getReplicaSet(string(ref.UID)); ok {
512512
name := replicaset.Deployment.Name
513513
if name != "" {
514514
if c.Rules.DeploymentName {
515515
tags[conventions.AttributeK8SDeploymentName] = name
516516
}
517-
if c.Rules.Service {
517+
if c.Rules.ServiceAttributes {
518518
serviceNames[conventions.AttributeK8SDeploymentName] = name
519519
}
520520
}
@@ -534,7 +534,7 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
534534
if c.Rules.DaemonSetName {
535535
tags[conventions.AttributeK8SDaemonSetName] = ref.Name
536536
}
537-
if c.Rules.Service {
537+
if c.Rules.ServiceAttributes {
538538
serviceNames[conventions.AttributeK8SDaemonSetName] = ref.Name
539539
}
540540
case "StatefulSet":
@@ -544,18 +544,18 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
544544
if c.Rules.StatefulSetName {
545545
tags[conventions.AttributeK8SStatefulSetName] = ref.Name
546546
}
547-
if c.Rules.Service {
547+
if c.Rules.ServiceAttributes {
548548
serviceNames[conventions.AttributeK8SStatefulSetName] = ref.Name
549549
}
550550
case "Job":
551-
if c.Rules.CronJobName || c.Rules.Service {
551+
if c.Rules.CronJobName || c.Rules.ServiceAttributes {
552552
parts := c.cronJobRegex.FindStringSubmatch(ref.Name)
553553
if len(parts) == 2 {
554554
name := parts[1]
555555
if c.Rules.CronJobName {
556556
tags[conventions.AttributeK8SCronJobName] = name
557557
}
558-
if c.Rules.Service {
558+
if c.Rules.ServiceAttributes {
559559
serviceNames[conventions.AttributeK8SCronJobName] = name
560560
}
561561
}
@@ -566,7 +566,7 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) (map[string]string,
566566
if c.Rules.JobName {
567567
tags[conventions.AttributeK8SJobName] = ref.Name
568568
}
569-
if c.Rules.Service {
569+
if c.Rules.ServiceAttributes {
570570
serviceNames[conventions.AttributeK8SJobName] = ref.Name
571571
}
572572
}
@@ -657,7 +657,7 @@ func removeUnnecessaryPodData(pod *api_v1.Pod, rules ExtractionRules) *api_v1.Po
657657
removeUnnecessaryContainerData := func(c api_v1.Container) api_v1.Container {
658658
transformedContainer := api_v1.Container{}
659659
transformedContainer.Name = c.Name // we always need the name, it's used for identification
660-
if rules.ContainerImageName || rules.ContainerImageTag || rules.Service {
660+
if rules.ContainerImageName || rules.ContainerImageTag || rules.ServiceAttributes {
661661
transformedContainer.Image = c.Image
662662
}
663663
return transformedContainer
@@ -730,7 +730,7 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain
730730
if !needContainerAttributes(c.Rules) {
731731
return containers
732732
}
733-
if c.Rules.ContainerImageName || c.Rules.ContainerImageTag || c.Rules.Service {
733+
if c.Rules.ContainerImageName || c.Rules.ContainerImageTag || c.Rules.ServiceAttributes {
734734
for _, spec := range append(pod.Spec.Containers, pod.Spec.InitContainers...) {
735735
container := &Container{}
736736
imageRef, err := dcommon.ParseImageName(spec.Image)
@@ -743,7 +743,7 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain
743743
}
744744
serviceVersion, err := parseServiceVersionFromImage(spec.Image)
745745
if err == nil {
746-
if c.Rules.Service {
746+
if c.Rules.ServiceAttributes {
747747
container.ServiceVersion = serviceVersion
748748
}
749749
}
@@ -761,7 +761,7 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain
761761
if c.Rules.ContainerName {
762762
container.Name = containerName
763763
}
764-
if c.Rules.Service {
764+
if c.Rules.ServiceAttributes {
765765
container.ServiceInstanceID = automaticServiceInstanceID(pod, containerName)
766766
container.ServiceName = containerName
767767
}
@@ -1097,7 +1097,7 @@ func needContainerAttributes(rules ExtractionRules) bool {
10971097
rules.ContainerImageTag ||
10981098
rules.ContainerImageRepoDigests ||
10991099
rules.ContainerID ||
1100-
rules.Service
1100+
rules.ServiceAttributes
11011101
}
11021102

11031103
func (c *WatchClient) handleReplicaSetAdd(obj any) {

processor/k8sattributesprocessor/internal/kube/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,9 @@ func TestExtractionRules(t *testing.T) {
703703
}
704704

705705
automaticRules := ExtractionRules{
706-
Service: true,
707-
Labels: AutomaticLabelRules,
708-
Annotations: []FieldExtractionRule{OtelAnnotations()},
706+
ServiceAttributes: true,
707+
Labels: AutomaticLabelRules,
708+
Annotations: []FieldExtractionRule{OtelAnnotations()},
709709
}
710710

711711
testCases := []struct {
@@ -1639,7 +1639,7 @@ func Test_extractPodContainersAttributes(t *testing.T) {
16391639
{
16401640
name: "automatic-container-level-attributes",
16411641
rules: ExtractionRules{
1642-
Service: true,
1642+
ServiceAttributes: true,
16431643
},
16441644
pod: &pod,
16451645
want: PodContainers{

processor/k8sattributesprocessor/internal/kube/kube.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ type ExtractionRules struct {
246246
Annotations []FieldExtractionRule
247247
Labels []FieldExtractionRule
248248

249-
Service bool
249+
ServiceAttributes bool
250250
}
251251

252252
// IncludesOwnerMetadata determines whether the ExtractionRules include metadata about Pod Owners
@@ -269,7 +269,7 @@ func (rules *ExtractionRules) IncludesOwnerMetadata() bool {
269269
return true
270270
}
271271
}
272-
return rules.Service
272+
return rules.ServiceAttributes
273273
}
274274

275275
// FieldExtractionRule is used to specify which fields to extract from pod fields
File renamed without changes.

processor/k8sattributesprocessor/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ func withOtelAnnotations(enabled bool) option {
207207
}
208208
}
209209

210-
func withServiceAttributes(config ServiceAttributeConfig) option {
210+
func withServiceAttributes(config ServiceAttributesConfig) option {
211211
return func(p *kubernetesprocessor) error {
212212
if config.Enabled {
213-
p.rules.Service = true
213+
p.rules.ServiceAttributes = true
214214
if config.Labels {
215215
p.rules.Labels = append(p.rules.Labels, kube.AutomaticLabelRules...)
216216
}

processor/k8sattributesprocessor/processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) {
14041404
t,
14051405
NewFactory().CreateDefaultConfig(),
14061406
nil,
1407-
withServiceAttributes(ServiceAttributeConfig{Enabled: true}),
1407+
withServiceAttributes(ServiceAttributesConfig{Enabled: true}),
14081408
)
14091409
m.kubernetesProcessorOperation(tt.op)
14101410
m.testConsume(context.Background(),

0 commit comments

Comments
 (0)