Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/awscontainerinsightreceiver] Add support for controller-name use with StatefulSet #34901

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions receiver/awscontainerinsightreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ type Config struct {
// If false FullPodName label is not added
// The default value is false
AddFullPodNameMetricLabel bool `mapstructure:"add_full_pod_name_metric_label"`

// By default a StatefulSet will always use its full "PodName" when storing metrics.
// If true this will instead use the name of the relevant controller instead to match Deployment, Daemonset, Job, ...
// The default value is false
PrefContollerNameForStatefulSet bool `mapstructure:"prefer_controller_name_for_stateful_set"`
jbeemster marked this conversation as resolved.
Show resolved Hide resolved
}
14 changes: 9 additions & 5 deletions receiver/awscontainerinsightreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (

// Don't tag pod full name by default
defaultAddFullPodNameMetricLabel = false

// Don't use controller name for StatefulSet metrics by default
defaultPrefContollerNameForStatefulSet = false
jbeemster marked this conversation as resolved.
Show resolved Hide resolved
)

// NewFactory creates a factory for AWS container insight receiver
Expand All @@ -43,11 +46,12 @@ func NewFactory() receiver.Factory {
// createDefaultConfig returns a default config for the receiver.
func createDefaultConfig() component.Config {
return &Config{
CollectionInterval: defaultCollectionInterval,
ContainerOrchestrator: defaultContainerOrchestrator,
TagService: defaultTagService,
PrefFullPodName: defaultPrefFullPodName,
AddFullPodNameMetricLabel: defaultAddFullPodNameMetricLabel,
CollectionInterval: defaultCollectionInterval,
ContainerOrchestrator: defaultContainerOrchestrator,
TagService: defaultTagService,
PrefFullPodName: defaultPrefFullPodName,
AddFullPodNameMetricLabel: defaultAddFullPodNameMetricLabel,
PrefContollerNameForStatefulSet: defaultPrefContollerNameForStatefulSet,
}
}

Expand Down
28 changes: 17 additions & 11 deletions receiver/awscontainerinsightreceiver/internal/stores/podstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ type PodStore struct {
prefFullPodName bool
logger *zap.Logger
sync.Mutex
addFullPodNameMetricLabel bool
addFullPodNameMetricLabel bool
prefControllerNameForStatefulSet bool
}

func NewPodStore(hostIP string, prefFullPodName bool, addFullPodNameMetricLabel bool, logger *zap.Logger) (*PodStore, error) {
func NewPodStore(hostIP string, prefFullPodName bool, addFullPodNameMetricLabel bool, prefControllerNameForStatefulSet bool, logger *zap.Logger) (*PodStore, error) {
podClient, err := kubeletutil.NewKubeletClient(hostIP, ci.KubeSecurePort, logger)
if err != nil {
return nil, err
Expand All @@ -122,14 +123,15 @@ func NewPodStore(hostIP string, prefFullPodName bool, addFullPodNameMetricLabel
}

podStore := &PodStore{
cache: newMapWithExpiry(podsExpiry),
prevMeasurements: make(map[string]*mapWithExpiry),
podClient: podClient,
nodeInfo: newNodeInfo(logger),
prefFullPodName: prefFullPodName,
k8sClient: k8sClient,
logger: logger,
addFullPodNameMetricLabel: addFullPodNameMetricLabel,
cache: newMapWithExpiry(podsExpiry),
prevMeasurements: make(map[string]*mapWithExpiry),
podClient: podClient,
nodeInfo: newNodeInfo(logger),
prefFullPodName: prefFullPodName,
k8sClient: k8sClient,
logger: logger,
addFullPodNameMetricLabel: addFullPodNameMetricLabel,
prefControllerNameForStatefulSet: prefControllerNameForStatefulSet,
}

return podStore, nil
Expand Down Expand Up @@ -589,7 +591,11 @@ func (p *PodStore) addPodOwnersAndPodName(metric CIMetric, pod *corev1.Pod, kube

if podName == "" {
if owner.Kind == ci.StatefulSet {
podName = pod.Name
if p.prefControllerNameForStatefulSet {
podName = name
} else {
podName = pod.Name
}
} else if owner.Kind == ci.DaemonSet || owner.Kind == ci.Job ||
owner.Kind == ci.ReplicaSet || owner.Kind == ci.ReplicationController {
podName = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type K8sDecorator struct {
podStore *PodStore
}

func NewK8sDecorator(ctx context.Context, tagService bool, prefFullPodName bool, addFullPodNameMetricLabel bool, logger *zap.Logger) (*K8sDecorator, error) {
func NewK8sDecorator(ctx context.Context, tagService bool, prefFullPodName bool, addFullPodNameMetricLabel bool, prefControllerNameForStatefulSet bool, logger *zap.Logger) (*K8sDecorator, error) {
hostIP := os.Getenv("HOST_IP")
if hostIP == "" {
return nil, errors.New("environment variable HOST_IP is not set in k8s deployment config")
Expand All @@ -54,7 +54,7 @@ func NewK8sDecorator(ctx context.Context, tagService bool, prefFullPodName bool,
ctx: ctx,
}

podstore, err := NewPodStore(hostIP, prefFullPodName, addFullPodNameMetricLabel, logger)
podstore, err := NewPodStore(hostIP, prefFullPodName, addFullPodNameMetricLabel, prefControllerNameForStatefulSet, logger)

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion receiver/awscontainerinsightreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}

if acir.config.ContainerOrchestrator == ci.EKS {
k8sDecorator, err := stores.NewK8sDecorator(ctx, acir.config.TagService, acir.config.PrefFullPodName, acir.config.AddFullPodNameMetricLabel, acir.settings.Logger)
k8sDecorator, err := stores.NewK8sDecorator(ctx, acir.config.TagService, acir.config.PrefFullPodName, acir.config.AddFullPodNameMetricLabel, acir.config.PrefControllerNameForStatefulSet, acir.settings.Logger)

Check failure on line 66 in receiver/awscontainerinsightreceiver/receiver.go

View workflow job for this annotation

GitHub Actions / govulncheck (receiver-0)

acir.config.PrefControllerNameForStatefulSet undefined (type *Config has no field or method PrefControllerNameForStatefulSet)
if err != nil {
return err
}
Expand Down
Loading