Skip to content

Commit ab6e785

Browse files
committed
Use structured logging
This change uses GetLogger instead of direct use of log.FromContext to support structured logging.
1 parent 6c42079 commit ab6e785

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

controllers/autoscaling_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
955955
func (r *AutoscalingReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
956956
requests := []reconcile.Request{}
957957

958-
l := log.FromContext(ctx).WithName("Controllers").WithName("Autoscaling")
958+
Log := r.GetLogger(ctx)
959959

960960
for _, field := range autoscalingAllWatchFields {
961961
crList := &telemetryv1.AutoscalingList{}
@@ -969,7 +969,7 @@ func (r *AutoscalingReconciler) findObjectsForSrc(ctx context.Context, src clien
969969
}
970970

971971
for _, item := range crList.Items {
972-
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
972+
Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
973973

974974
requests = append(requests,
975975
reconcile.Request{
@@ -988,20 +988,20 @@ func (r *AutoscalingReconciler) findObjectsForSrc(ctx context.Context, src clien
988988
func (r *AutoscalingReconciler) findObjectForSrc(ctx context.Context, src client.Object) []reconcile.Request {
989989
requests := []reconcile.Request{}
990990

991-
l := log.FromContext(ctx).WithName("Controllers").WithName("Autoscaling")
991+
Log := r.GetLogger(ctx)
992992

993993
crList := &telemetryv1.AutoscalingList{}
994994
listOps := &client.ListOptions{
995995
Namespace: src.GetNamespace(),
996996
}
997997
err := r.Client.List(ctx, crList, listOps)
998998
if err != nil {
999-
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
999+
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
10001000
return requests
10011001
}
10021002

10031003
for _, item := range crList.Items {
1004-
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
1004+
Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
10051005

10061006
requests = append(requests,
10071007
reconcile.Request{

controllers/ceilometer_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ func (r *CeilometerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
18261826
func (r *CeilometerReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
18271827
requests := []reconcile.Request{}
18281828

1829-
l := log.FromContext(ctx).WithName("Controllers").WithName("Ceilometer")
1829+
Log := r.GetLogger(ctx)
18301830

18311831
for _, field := range ceilometerWatchFields {
18321832
crList := &telemetryv1.CeilometerList{}
@@ -1836,12 +1836,12 @@ func (r *CeilometerReconciler) findObjectsForSrc(ctx context.Context, src client
18361836
}
18371837
err := r.Client.List(ctx, crList, listOps)
18381838
if err != nil {
1839-
l.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
1839+
Log.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
18401840
return requests
18411841
}
18421842

18431843
for _, item := range crList.Items {
1844-
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
1844+
Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
18451845

18461846
requests = append(requests,
18471847
reconcile.Request{
@@ -1860,20 +1860,20 @@ func (r *CeilometerReconciler) findObjectsForSrc(ctx context.Context, src client
18601860
func (r *CeilometerReconciler) findObjectForSrc(ctx context.Context, src client.Object) []reconcile.Request {
18611861
requests := []reconcile.Request{}
18621862

1863-
l := log.FromContext(ctx).WithName("Controllers").WithName("Ceilometer")
1863+
Log := r.GetLogger(ctx)
18641864

18651865
crList := &telemetryv1.CeilometerList{}
18661866
listOps := &client.ListOptions{
18671867
Namespace: src.GetNamespace(),
18681868
}
18691869
err := r.Client.List(ctx, crList, listOps)
18701870
if err != nil {
1871-
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
1871+
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
18721872
return requests
18731873
}
18741874

18751875
for _, item := range crList.Items {
1876-
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
1876+
Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
18771877

18781878
requests = append(requests,
18791879
reconcile.Request{

controllers/metricstorage_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
14391439
func (r *MetricStorageReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
14401440
requests := []reconcile.Request{}
14411441

1442-
l := log.FromContext(context.Background()).WithName("Controllers").WithName("MetricStorage")
1442+
Log := r.GetLogger(ctx)
14431443

14441444
for _, field := range prometheusAllWatchFields {
14451445
crList := &telemetryv1.MetricStorageList{}
@@ -1453,7 +1453,7 @@ func (r *MetricStorageReconciler) findObjectsForSrc(ctx context.Context, src cli
14531453
}
14541454

14551455
for _, item := range crList.Items {
1456-
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
1456+
Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
14571457

14581458
requests = append(requests,
14591459
reconcile.Request{
@@ -1470,7 +1470,7 @@ func (r *MetricStorageReconciler) findObjectsForSrc(ctx context.Context, src cli
14701470
}
14711471

14721472
func (r *MetricStorageReconciler) nodeSetWatchFn(ctx context.Context, o client.Object) []reconcile.Request {
1473-
l := log.FromContext(context.Background()).WithName("Controllers").WithName("MetricStorage")
1473+
Log := r.GetLogger(ctx)
14741474
// Reconcile all metricstorages when a nodeset changes
14751475
result := []reconcile.Request{}
14761476

@@ -1480,7 +1480,7 @@ func (r *MetricStorageReconciler) nodeSetWatchFn(ctx context.Context, o client.O
14801480
client.InNamespace(o.GetNamespace()),
14811481
}
14821482
if err := r.Client.List(ctx, metricstorages, listOpts...); err != nil {
1483-
l.Error(err, "Unable to retrieve MetricStorage CRs %v")
1483+
Log.Error(err, "Unable to retrieve MetricStorage CRs %v")
14841484
return nil
14851485
}
14861486
for _, cr := range metricstorages.Items {

0 commit comments

Comments
 (0)