cluster-api-provider-aws icon indicating copy to clipboard operation
cluster-api-provider-aws copied to clipboard

Unify the logger interface in CAPA

Open Skarlso opened this issue 3 years ago • 2 comments
trafficstars

What type of PR is this?

/kind feature

What this PR does / why we need it:

Create a unified Logger interface which developers can use to log debug and trace information. It's just a soft wrapper around logr.Logger.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged): Fixes https://github.com/kubernetes-sigs/cluster-api-provider-aws/issues/3152

Special notes for your reviewer:

Checklist:

  • [x] squashed commits
  • [ ] includes documentation
  • [ ] adds unit tests
  • [ ] adds or updates e2e tests

Skarlso avatar Oct 13 '22 12:10 Skarlso

@richardcase When you review this, please take note of the Debug vs Trace messages. I wasn't sure which belonged to what category at times. :D so please take a look at them and see if they are at the correct level. :) Thanks! 👍

Skarlso avatar Oct 13 '22 20:10 Skarlso

Some output with this logging interface:

Tags:map[]} {ID:subnet-01f36f8d65e926fd6 CidrBlock:10.0.64.0/18 IPv6CidrBlock: AvailabilityZone:eu-central-1a IsPublic:false IsIPv6:false RouteTableID:<nil> NatGatewayID:<nil> Tags:map[]} {ID:subnet-0711ca7fb292bc564 CidrBlock:10.0.16.0/20 IPv6CidrBlock: AvailabilityZone:eu-central-1b IsPublic:true IsIPv6:false RouteTableID:<nil> NatGatewayID:<nil> Tags:map[]} {ID:subnet-090dc1ec75941ec5b CidrBlock:10.0.128.0/18 IPv6CidrBlock: AvailabilityZone:eu-central-1b IsPublic:false IsIPv6:false RouteTableID:<nil> NatGatewayID:<nil> Tags:map[]} {ID:subnet-06560f282e7a2c07b CidrBlock:10.0.32.0/20 IPv6CidrBlock: AvailabilityZone:eu-central-1c IsPublic:true IsIPv6:false RouteTableID:<nil> NatGatewayID:<nil> Tags:map[]} {ID:subnet-0b65deb3c514aa670 CidrBlock:10.0.192.0/18 IPv6CidrBlock: AvailabilityZone:eu-central-1c IsPublic:false IsIPv6:false RouteTableID:<nil> NatGatewayID:<nil> Tags:map[]}]
I1016 07:58:15.420742      12 logger.go:56] "Reconciling internet gateways"
I1016 07:58:15.636314      12 logger.go:52] "Created Internet gateway for VPC" internet-gateway-id="igw-049f01e0f647b8455" vpc-id="vpc-0fcc6fc7ce974c4a0"
I1016 07:58:15.636453      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateInternetGateway" message="Created new managed Internet Gateway \"igw-049f01e0f647b8455\""
I1016 07:58:15.636796      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateInternetGateway" message="Created new managed Internet Gateway \"igw-049f01e0f647b8455\""
I1016 07:58:15.790775      12 logger.go:56] "attached internet gateway to VPC" internet-gateway-id="igw-049f01e0f647b8455" vpc-id="vpc-0fcc6fc7ce974c4a0"
I1016 07:58:15.790840      12 logger.go:56] "Reconciling NAT gateways"
I1016 07:58:15.791063      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulAttachInternetGateway" message="Internet Gateway \"igw-049f01e0f647b8455\" attached to VPC \"vpc-0fcc6fc7ce974c4a0\""
I1016 07:58:15.791110      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulAttachInternetGateway" message="Internet Gateway \"igw-049f01e0f647b8455\" attached to VPC \"vpc-0fcc6fc7ce974c4a0\""
I1016 07:58:15.915308      12 http.go:96] "controller-runtime/webhook/webhooks: received request" webhook="/mutate-controlplane-cluster-x-k8s-io-v1beta2-awsmanagedcontrolplane" UID=fd327d65-2309-4a55-b453-017184219a56 kind="controlplane.cluster.x-k8s.io/v1beta2, Kind=AWSManagedControlPlane" resource={Group:controlplane.cluster.x-k8s.io Version:v1beta2 Resource:awsmanagedcontrolplanes}
I1016 07:58:15.915686      12 logr.go:261] "awsmanagedcontrolplane-resource: AWSManagedControlPlane setting defaults" control-plane="default/managed-cluster-control-plane"
I1016 07:58:15.916635      12 http.go:143] "controller-runtime/webhook/webhooks: wrote response" webhook="/mutate-controlplane-cluster-x-k8s-io-v1beta2-awsmanagedcontrolplane" code=200 reason= UID=fd327d65-2309-4a55-b453-017184219a56 allowed=true
I1016 07:58:15.922013      12 http.go:96] "controller-runtime/webhook/webhooks: received request" webhook="/validate-controlplane-cluster-x-k8s-io-v1beta2-awsmanagedcontrolplane" UID=0459f7e1-83ef-44fe-9f82-979afb5947fb kind="controlplane.cluster.x-k8s.io/v1beta2, Kind=AWSManagedControlPlane" resource={Group:controlplane.cluster.x-k8s.io Version:v1beta2 Resource:awsmanagedcontrolplanes}
I1016 07:58:15.922540      12 logr.go:261] "awsmanagedcontrolplane-resource: AWSManagedControlPlane validate update" control-plane="default/managed-cluster-control-plane"
I1016 07:58:15.922703      12 http.go:143] "controller-runtime/webhook/webhooks: wrote response" webhook="/validate-controlplane-cluster-x-k8s-io-v1beta2-awsmanagedcontrolplane" code=200 reason= UID=0459f7e1-83ef-44fe-9f82-979afb5947fb allowed=true
I1016 07:58:17.366588      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0ccac7e239d4d3b01\""
I1016 07:58:17.366589      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0ccac7e239d4d3b01\""
I1016 07:58:17.470873      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0711abc19de6ef624\""
I1016 07:58:17.470893      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0711abc19de6ef624\""
I1016 07:58:17.550041      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0dab5ddae2b8a8e57\""
I1016 07:58:17.550132      12 recorder.go:103] "events: Normal" object={Kind:AWSManagedControlPlane Namespace:default Name:managed-cluster-control-plane UID:c6bc345c-a26b-4d5d-8dc4-fb4f5568e515 APIVersion:controlplane.cluster.x-k8s.io/v1beta2 ResourceVersion:1322 FieldPath:} reason="SuccessfulCreateNATGateway" message="Created new NAT Gateway \"nat-0dab5ddae2b8a8e57\""

Skarlso avatar Oct 16 '22 08:10 Skarlso

Damn.......:D

Skarlso avatar Oct 20 '22 18:10 Skarlso

@richardcase @Ankitasw 👋 If you have time, can I get a review on this, please? :D it touches a lot of files and had some major git conflicts.

Skarlso avatar Oct 24 '22 06:10 Skarlso

@Skarlso I am on PTO today, will take a look sometime this week.

Ankitasw avatar Oct 24 '22 07:10 Ankitasw

@Ankitasw Thank you! That's perfectly fine. :)

Skarlso avatar Oct 24 '22 07:10 Skarlso

@Skarlso Did you run e2e tests to see if the logs look fine? I think log level in E2E is set to 4 by default if I am not wrong.

Ankitasw avatar Oct 25 '22 07:10 Ankitasw

The overall changes looks much cleaner to me, so once i see the logs, it LGTM.

Ankitasw avatar Oct 25 '22 07:10 Ankitasw

/test pull-cluster-api-provider-aws-e2e-blocking

Ankitasw avatar Oct 25 '22 07:10 Ankitasw

@Skarlso Did you run e2e tests to see if the logs look fine? I think log level in E2E is set to 4 by default if I am not wrong.

Hello 👋 :) I pasted in the logs from a normal cluster create above. However, I agree it's a very good call to run the e2e tests! :)

Also, it is kind of a small sample too.

I adjusted the levels here and there as I was talking to Richard. It seemed like they were actually misnumbered.

Skarlso avatar Oct 25 '22 07:10 Skarlso

The e2e logs have much refiner trace logs which is good for debugging. Hence, /lgtm /approve

Ankitasw avatar Oct 25 '22 07:10 Ankitasw

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ankitasw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Oct 25 '22 07:10 k8s-ci-robot

Thank you, Ankita! :)

Skarlso avatar Oct 25 '22 09:10 Skarlso