From 550ca8714f0c6db70fbd063d58c1e48dc9e82e31 Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Fri, 7 Apr 2023 15:37:34 -0700 Subject: [PATCH] chore: logging touchups (#3723) Co-authored-by: Jonathan Innis --- pkg/providers/amifamily/ami.go | 2 +- pkg/providers/instance/instance.go | 2 +- pkg/providers/instancetype/instancetype.go | 4 ++-- pkg/providers/launchtemplate/launchtemplate.go | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/providers/amifamily/ami.go b/pkg/providers/amifamily/ami.go index a4f601f64888..9431b58a218d 100644 --- a/pkg/providers/amifamily/ami.go +++ b/pkg/providers/amifamily/ami.go @@ -176,7 +176,7 @@ func (p *Provider) fetchAMIsFromSSM(ctx context.Context, ssmQuery string) (strin ami := aws.StringValue(output.Parameter.Value) p.ssmCache.SetDefault(ssmQuery, ami) if p.cm.HasChanged("ssmquery-"+ssmQuery, ami) { - logging.FromContext(ctx).With("ami", ami, "query", ssmQuery).Debugf("discovered new ami") + logging.FromContext(ctx).With("ami", ami, "query", ssmQuery).Debugf("discovered ami") } return ami, nil } diff --git a/pkg/providers/instance/instance.go b/pkg/providers/instance/instance.go index 2611d24f26b9..aabf14862edf 100644 --- a/pkg/providers/instance/instance.go +++ b/pkg/providers/instance/instance.go @@ -124,7 +124,7 @@ func (p *Provider) Create(ctx context.Context, nodeTemplate *v1alpha1.AWSNodeTem "instance-type", aws.StringValue(instance.InstanceType), "zone", aws.StringValue(instance.Placement.AvailabilityZone), "capacity-type", GetCapacityType(instance), - "capacity", capacity).Infof("launched new instance") + "capacity", capacity).Infof("launched instance") return instance, nil } diff --git a/pkg/providers/instancetype/instancetype.go b/pkg/providers/instancetype/instancetype.go index a30459c0f974..080dd56c8dac 100644 --- a/pkg/providers/instancetype/instancetype.go +++ b/pkg/providers/instancetype/instancetype.go @@ -186,7 +186,7 @@ func (p *Provider) getInstanceTypeZones(ctx context.Context, nodeTemplate *v1alp return nil, fmt.Errorf("describing instance type zone offerings, %w", err) } if p.cm.HasChanged("zonal-offerings", nodeTemplate.Spec.SubnetSelector) { - logging.FromContext(ctx).With("subnet-selector", pretty.Concise(nodeTemplate.Spec.SubnetSelector)).Debugf("discovered EC2 instance types zonal offerings for subnets") + logging.FromContext(ctx).With("zones", zones.List(), "instance-type-count", len(instanceTypeZones), "node-template", nodeTemplate.Name).Debugf("discovered offerings for instance types") } p.cache.SetDefault(cacheKey, instanceTypeZones) return instanceTypeZones, nil @@ -225,7 +225,7 @@ func (p *Provider) GetInstanceTypes(ctx context.Context) ([]*ec2.InstanceTypeInf } if p.cm.HasChanged("instance-types", instanceTypes) { logging.FromContext(ctx).With( - "instance-type-count", len(instanceTypes)).Debugf("discovered EC2 instance types") + "count", len(instanceTypes)).Debugf("discovered instance types") } atomic.AddUint64(&p.instanceTypesSeqNum, 1) p.cache.SetDefault(InstanceTypesCacheKey, instanceTypes) diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index f585c28d7e38..c20c8e44af6f 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -278,7 +278,6 @@ func (p *Provider) volumeSize(quantity *resource.Quantity) *int64 { func (p *Provider) hydrateCache(ctx context.Context) { clusterName := settings.FromContext(ctx).ClusterName ctx = logging.WithLogger(ctx, logging.FromContext(ctx).With("tag-key", karpenterManagedTagKey, "tag-value", clusterName)) - logging.FromContext(ctx).Debugf("hydrating the launch template cache") if err := p.ec2api.DescribeLaunchTemplatesPagesWithContext(ctx, &ec2.DescribeLaunchTemplatesInput{ Filters: []*ec2.Filter{{Name: aws.String(fmt.Sprintf("tag:%s", karpenterManagedTagKey)), Values: []*string{aws.String(clusterName)}}}, }, func(output *ec2.DescribeLaunchTemplatesOutput, _ bool) bool { @@ -288,8 +287,9 @@ func (p *Provider) hydrateCache(ctx context.Context) { return true }); err != nil { logging.FromContext(ctx).Errorf(fmt.Sprintf("Unable to hydrate the AWS launch template cache, %s", err)) + } else { + logging.FromContext(ctx).With("count", p.cache.ItemCount()).Debugf("hydrated launch template cache") } - logging.FromContext(ctx).With("item-count", p.cache.ItemCount()).Debugf("finished hydrating the launch template cache") } func (p *Provider) cachedEvictedFunc(ctx context.Context) func(string, interface{}) { @@ -301,7 +301,7 @@ func (p *Provider) cachedEvictedFunc(ctx context.Context) func(string, interface } launchTemplate := lt.(*ec2.LaunchTemplate) if _, err := p.ec2api.DeleteLaunchTemplate(&ec2.DeleteLaunchTemplateInput{LaunchTemplateId: launchTemplate.LaunchTemplateId}); err != nil { - logging.FromContext(ctx).With("launch-template", launchTemplate.LaunchTemplateName).Errorf("Unable to delete launch template, %v", err) + logging.FromContext(ctx).With("launch-template", launchTemplate.LaunchTemplateName).Errorf("failed to delete launch template, %v", err) return } logging.FromContext(ctx).With("launch-template", launchTemplate.LaunchTemplateName).Debugf("deleted launch template")