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

Enable OpenTelemetry support #4454

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 16 additions & 2 deletions bootstrap/eks/controllers/eksconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/internal/userdata"
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bsutil "sigs.k8s.io/cluster-api/bootstrap/util"
expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
Expand All @@ -65,7 +66,14 @@ type EKSConfigReconciler struct {
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;delete;

func (r *EKSConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, rerr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"bootstrap.eks.controllers.eksconfig.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// get EKSConfig
config := &eksbootstrapv1.EKSConfig{}
Expand Down Expand Up @@ -290,10 +298,16 @@ func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1
}

func (r *EKSConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, option controller.Options) error {
ctx, log, done := tele.StartSpanWithLogger(ctx,
"bootstrap.eks.controllers.EKSConfigReconciler.SetupWithManager",
tele.KVP("controller", "EKSConfig"),
)
defer done()

b := ctrl.NewControllerManagedBy(mgr).
For(&eksbootstrapv1.EKSConfig{}).
WithOptions(option).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue)).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log.GetLogger(), r.WatchFilterValue)).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
Expand Down
17 changes: 15 additions & 2 deletions controllers/awscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/securitygroup"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
infrautilconditions "sigs.k8s.io/cluster-api-provider-aws/v2/util/conditions"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
capiannotations "sigs.k8s.io/cluster-api/util/annotations"
Expand Down Expand Up @@ -131,7 +132,14 @@ func (r *AWSClusterReconciler) getSecurityGroupService(scope scope.ClusterScope)
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclustercontrolleridentities,verbs=get;list;watch;create

func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"controllers.awscluster.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// Fetch the AWSCluster instance
awsCluster := &infrav1.AWSCluster{}
Expand Down Expand Up @@ -346,7 +354,12 @@ func (r *AWSClusterReconciler) reconcileNormal(clusterScope *scope.ClusterScope)
}

func (r *AWSClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(ctx,
"controllers.AWSClusterReconciler.SetupWithManager",
tele.KVP("controller", "AWSCluster"),
)
defer done()

controller, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrav1.AWSCluster{}).
Expand Down
17 changes: 15 additions & 2 deletions controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ssm"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/userdata"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
capierrors "sigs.k8s.io/cluster-api/errors"
Expand Down Expand Up @@ -148,7 +149,14 @@ func (r *AWSMachineReconciler) getObjectStoreService(scope scope.S3Scope) servic
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch

func (r *AWSMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"controllers.awsmachine.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// Fetch the AWSMachine instance.
awsMachine := &infrav1.AWSMachine{}
Expand Down Expand Up @@ -236,7 +244,12 @@ func (r *AWSMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

func (r *AWSMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(ctx,
"controllers.AWSMachineReconciler.SetupWithManager",
tele.KVP("controller", "AWSMachine"),
)
defer done()

AWSClusterToAWSMachines := r.AWSClusterToAWSMachines(log)

controller, err := ctrl.NewControllerManagedBy(mgr).
Expand Down
18 changes: 15 additions & 3 deletions controllers/awsmanagedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
Expand All @@ -56,7 +57,14 @@ type AWSManagedClusterReconciler struct {
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete

func (r *AWSManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := ctrl.LoggerFrom(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"controllers.awsmanagedcluster.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// Fetch the AWSManagedCluster instance
awsManagedCluster := &infrav1.AWSManagedCluster{}
Expand Down Expand Up @@ -117,14 +125,18 @@ func (r *AWSManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
}

func (r *AWSManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(ctx,
"controllers.AWSManagedClusterReconciler.SetupWithManager",
tele.KVP("controller", "AWSManagedCluster"),
)
defer done()

awsManagedCluster := &infrav1.AWSManagedCluster{}

controller, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(awsManagedCluster).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log.GetLogger(), r.WatchFilterValue)).
Build(r)

if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions controlplane/eks/controllers/awsmanagedcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/network"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/securitygroup"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
capiannotations "sigs.k8s.io/cluster-api/util/annotations"
Expand Down Expand Up @@ -98,7 +99,11 @@ type AWSManagedControlPlaneReconciler struct {

// SetupWithManager is used to setup the controller.
func (r *AWSManagedControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(ctx,
"controllers.AWSManagedControlPlaneReconciler.SetupWithManager",
tele.KVP("controller", "AWSManagedControlPlane"),
)
defer done()

awsManagedControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
c, err := ctrl.NewControllerManagedBy(mgr).
Expand Down Expand Up @@ -146,7 +151,14 @@ func (r *AWSManagedControlPlaneReconciler) SetupWithManager(ctx context.Context,

// Reconcile will reconcile AWSManagedControlPlane Resources.
func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"controllers.awsmanagedcontrolplane.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// Get the control plane instance
awsControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
Expand Down
19 changes: 16 additions & 3 deletions exp/controlleridentitycreator/awscontrolleridentity_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
"sigs.k8s.io/cluster-api/util/predicates"
)

Expand All @@ -50,7 +50,14 @@ type AWSControllerIdentityReconciler struct {
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclustercontrolleridentities,verbs=get;list;watch;create

func (r *AWSControllerIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"exp.controlleridentity.awscontrolleridentity.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

var identityRef *infrav1.AWSIdentityReference

Expand Down Expand Up @@ -132,10 +139,16 @@ func (r *AWSControllerIdentityReconciler) Reconcile(ctx context.Context, req ctr
}

func (r *AWSControllerIdentityReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
_, log, done := tele.StartSpanWithLogger(ctx,
"controllers.AWSControllerIdentityReconciler.SetupWithManager",
tele.KVP("controller", "AWSControllerIdentity"),
)
defer done()

controller := ctrl.NewControllerManagedBy(mgr).
For(&infrav1.AWSCluster{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue))
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log.GetLogger(), r.WatchFilterValue))

if feature.Gates.Enabled(feature.EKS) {
controller.Watches(
Expand Down
18 changes: 16 additions & 2 deletions exp/controllers/awsfargatepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
Expand All @@ -53,11 +54,17 @@ type AWSFargateProfileReconciler struct {

// SetupWithManager is used to setup the controller.
func (r *AWSFargateProfileReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
ctx, log, done := tele.StartSpanWithLogger(ctx,
"exp.controllers.AWSFargateProfileReconciler.SetupWithManager",
tele.KVP("controller", "AWSFargateProfile"),
)
defer done()

managedControlPlaneToFargateProfileMap := managedControlPlaneToFargateProfileMapFunc(r.Client, logger.FromContext(ctx))
return ctrl.NewControllerManagedBy(mgr).
For(&expinfrav1.AWSFargateProfile{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue)).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log.GetLogger(), r.WatchFilterValue)).
Watches(
&source.Kind{Type: &ekscontrolplanev1.AWSManagedControlPlane{}},
handler.EnqueueRequestsFromMapFunc(managedControlPlaneToFargateProfileMap),
Expand All @@ -73,7 +80,14 @@ func (r *AWSFargateProfileReconciler) SetupWithManager(ctx context.Context, mgr

// Reconcile reconciles AWSFargateProfiles.
func (r *AWSFargateProfileReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"exp.controllers.awsfargatepool.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

fargateProfile := &expinfrav1.AWSFargateProfile{}
if err := r.Get(ctx, req.NamespacedName, fargateProfile); err != nil {
Expand Down
18 changes: 16 additions & 2 deletions exp/controllers/awsmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
asg "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/autoscaling"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ec2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -88,7 +89,14 @@ func (r *AWSMachinePoolReconciler) getEC2Service(scope scope.EC2Scope) services.

// Reconcile is the reconciliation loop for AWSMachinePool.
func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"exp.controllers.awsmachinepool.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

// Fetch the AWSMachinePool .
awsMachinePool := &expinfrav1.AWSMachinePool{}
Expand Down Expand Up @@ -180,14 +188,20 @@ func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}

func (r *AWSMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
_, log, done := tele.StartSpanWithLogger(ctx,
"exp.controllers.AWSMachinePoolReconciler.SetupWithManager",
tele.KVP("controller", "AWSMachinePool"),
)
defer done()

return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&expinfrav1.AWSMachinePool{}).
Watches(
&source.Kind{Type: &expclusterv1.MachinePool{}},
handler.EnqueueRequestsFromMapFunc(machinePoolToInfrastructureMapFunc(expinfrav1.GroupVersion.WithKind("AWSMachinePool"))),
).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue)).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log.GetLogger(), r.WatchFilterValue)).
Complete(r)
}

Expand Down
16 changes: 14 additions & 2 deletions exp/controllers/awsmanagedmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ec2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
Expand All @@ -63,7 +64,11 @@ type AWSManagedMachinePoolReconciler struct {

// SetupWithManager is used to setup the controller.
func (r *AWSManagedMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := logger.FromContext(ctx)
_, log, done := tele.StartSpanWithLogger(ctx,
"exp.controllers.AWSManagedMachinePoolReconciler.SetupWithManager",
tele.KVP("controller", "AWSManagedMachinePool"),
)
defer done()

gvk, err := apiutil.GVKForObject(new(expinfrav1.AWSManagedMachinePool), mgr.GetScheme())
if err != nil {
Expand Down Expand Up @@ -93,7 +98,14 @@ func (r *AWSManagedMachinePoolReconciler) SetupWithManager(ctx context.Context,

// Reconcile reconciles AWSManagedMachinePools.
func (r *AWSManagedMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := logger.FromContext(ctx)
ctx, log, done := tele.StartSpanWithLogger(
ctx,
"exp.controllers.awsmanagedmachinepool.Reconcile",
tele.KVP("namespace", req.Namespace),
tele.KVP("name", req.Name),
tele.KVP("reconcileID", string(controller.ReconcileIDFromContext(ctx))),
)
defer done()

awsPool := &expinfrav1.AWSManagedMachinePool{}
if err := r.Get(ctx, req.NamespacedName, awsPool); err != nil {
Expand Down
Loading