Skip to content

Commit

Permalink
Adjusted logs to be consistent across the code base (#237)
Browse files Browse the repository at this point in the history
Adjusted logs to be consistent across the code base

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored Feb 28, 2019
1 parent 401ef74 commit f80e13f
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 184 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/io/v1alpha1/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1alpha1

import log "github.com/sirupsen/logrus"

// Logger returns a logger filled with context-related fields, such as Name and Namespace
func (j *Jaeger) Logger() *log.Entry {
return log.WithFields(log.Fields{
"instance": j.Name,
"namespace": j.Namespace,
})
}
15 changes: 7 additions & 8 deletions pkg/cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ func start(cmd *cobra.Command, args []string) {
}

log.WithFields(log.Fields{
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"version": runtime.Version(),
"operator-sdk": version.Get().OperatorSdk,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"version": runtime.Version(),
"operator-sdk": version.Get().OperatorSdk,
"jaeger-operator": version.Get().Operator,
}).Info("Versions")

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
log.Fatalf("failed to get watch namespace: %v", err)
log.WithError(err).Fatal("failed to get watch namespace")
}

// Get a config to talk to the apiserver
Expand All @@ -106,7 +107,7 @@ func start(cmd *cobra.Command, args []string) {
log.Debug("Attempting to auto-detect the platform")
os, err := detectOpenShift(mgr.GetConfig())
if err != nil {
log.WithError(err).Info("failed to auto-detect the platform, falling back to 'kubernetes'")
log.WithError(err).Info("Failed to auto-detect the platform, falling back to 'kubernetes'")
}

if os {
Expand All @@ -130,8 +131,6 @@ func start(cmd *cobra.Command, args []string) {
log.Fatal(err)
}

log.Print("Starting the Cmd.")

// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/sampling/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sampling
import (
"fmt"

"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -40,7 +39,7 @@ func (u *Config) Get() *v1.ConfigMap {
return nil
}

logrus.WithField("instance", u.jaeger.Name).Debug("Assembling the Sampling configmap")
u.jaeger.Logger().Debug("Assembling the Sampling configmap")
trueVar := true

data := map[string]string{
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package configmap
import (
"fmt"

"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -32,7 +31,7 @@ func (u *UIConfig) Get() *v1.ConfigMap {
return nil
}

logrus.Debug("Assembling the UI configmap")
u.jaeger.Logger().Debug("Assembling the UI configmap")
trueVar := true
data := map[string]string{
"ui": string(json),
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyAccounts(jaeger v1alpha1.Jaeger, desired []v1.Ser
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForAccounts(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("account", d.Name).Debug("creating service account")
jaeger.Logger().WithField("account", d.Name).Debug("creating service account")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("account", d.Name).Debug("updating service account")
jaeger.Logger().WithField("account", d.Name).Debug("updating service account")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("account", d.Name).Debug("deleting service account")
jaeger.Logger().WithField("account", d.Name).Debug("deleting service account")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyConfigMaps(jaeger v1alpha1.Jaeger, desired []v1.C
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForConfigMaps(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("configMap", d.Name).Debug("creating config maps")
jaeger.Logger().WithField("configMap", d.Name).Debug("creating config maps")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("configMap", d.Name).Debug("updating config maps")
jaeger.Logger().WithField("configMap", d.Name).Debug("updating config maps")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("configMap", d.Name).Debug("deleting config maps")
jaeger.Logger().WithField("configMap", d.Name).Debug("deleting config maps")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
batchv1beta1 "k8s.io/api/batch/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyCronJobs(jaeger v1alpha1.Jaeger, desired []batchv
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForCronJobs(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("cronjob", d.Name).Debug("creating cronjob")
jaeger.Logger().WithField("cronjob", d.Name).Debug("creating cronjob")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("cronjob", d.Name).Debug("updating cronjob")
jaeger.Logger().WithField("cronjob", d.Name).Debug("updating cronjob")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("cronjob", d.Name).Debug("deleting cronjob")
jaeger.Logger().WithField("cronjob", d.Name).Debug("deleting cronjob")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyDaemonSets(jaeger v1alpha1.Jaeger, desired []apps
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForDaemonSets(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("daemonset", d.Name).Debug("creating daemonset")
jaeger.Logger().WithField("daemonset", d.Name).Debug("creating daemonset")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("daemonset", d.Name).Debug("updating daemonset")
jaeger.Logger().WithField("daemonset", d.Name).Debug("updating daemonset")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("daemonset", d.Name).Debug("deleting daemonset")
jaeger.Logger().WithField("daemonset", d.Name).Debug("deleting daemonset")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
11 changes: 3 additions & 8 deletions pkg/controller/jaeger/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,20 @@ func (r *ReconcileJaeger) applyDeployments(jaeger v1alpha1.Jaeger, desired []app
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

// we now traverse the list, so that we end up with three lists:
// 1) deployments that are on both `desired` and `existing` (update)
// 2) deployments that are only on `desired` (create)
// 3) deployments that are only on `existing` (delete)
depInventory := inventory.ForDeployments(depList.Items, desired)
for _, d := range depInventory.Create {
logFields.WithField("deployment", d.Name).Debug("creating deployment")
jaeger.Logger().WithField("deployment", d.Name).Debug("creating deployment")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range depInventory.Update {
logFields.WithField("deployment", d.Name).Debug("updating deployment")
jaeger.Logger().WithField("deployment", d.Name).Debug("updating deployment")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
Expand All @@ -62,7 +57,7 @@ func (r *ReconcileJaeger) applyDeployments(jaeger v1alpha1.Jaeger, desired []app
}

for _, d := range depInventory.Delete {
logFields.WithField("deployment", d.Name).Debug("deleting deployment")
jaeger.Logger().WithField("deployment", d.Name).Debug("deleting deployment")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyElasticsearches(jaeger v1alpha1.Jaeger, desired [
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForElasticsearches(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("elasticsearch", d.Name).Debug("creating elasticsearch")
jaeger.Logger().WithField("elasticsearch", d.Name).Debug("creating elasticsearch")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("elasticsearch", d.Name).Debug("updating elasticsearch")
jaeger.Logger().WithField("elasticsearch", d.Name).Debug("updating elasticsearch")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("elasticsearch", d.Name).Debug("deleting elasticsearch")
jaeger.Logger().WithField("elasticsearch", d.Name).Debug("deleting elasticsearch")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/jaeger/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jaeger
import (
"context"

log "github.com/sirupsen/logrus"
"k8s.io/api/extensions/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -21,28 +20,23 @@ func (r *ReconcileJaeger) applyIngresses(jaeger v1alpha1.Jaeger, desired []v1bet
return err
}

logFields := log.WithFields(log.Fields{
"namespace": jaeger.Namespace,
"instance": jaeger.Name,
})

inv := inventory.ForIngresses(list.Items, desired)
for _, d := range inv.Create {
logFields.WithField("ingress", d.Name).Debug("creating ingress")
jaeger.Logger().WithField("ingress", d.Name).Debug("creating ingress")
if err := r.client.Create(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Update {
logFields.WithField("ingress", d.Name).Debug("updating ingress")
jaeger.Logger().WithField("ingress", d.Name).Debug("updating ingress")
if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
logFields.WithField("ingress", d.Name).Debug("deleting ingress")
jaeger.Logger().WithField("ingress", d.Name).Debug("deleting ingress")
if err := r.client.Delete(context.Background(), &d); err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/controller/jaeger/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
Expand Down Expand Up @@ -65,12 +66,13 @@ type ReconcileJaeger struct {
// The Controller will requeue the Request to be processed again if the returned error is non-nil or
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcileJaeger) Reconcile(request reconcile.Request) (reconcile.Result, error) {
logFields := log.WithFields(log.Fields{
execution := time.Now().UTC()

log.WithFields(log.Fields{
"namespace": request.Namespace,
"instance": request.Name,
})

logFields.Debug("Reconciling Jaeger")
"execution": execution,
}).Debug("Reconciling Jaeger")

// Fetch the Jaeger instance
instance := &v1alpha1.Jaeger{}
Expand All @@ -94,6 +96,8 @@ func (r *ReconcileJaeger) Reconcile(request reconcile.Request) (reconcile.Result

str := r.runStrategyChooser(instance)

logFields := instance.Logger().WithField("execution", execution)

// wait for all the dependencies to succeed
if err := r.handleDependencies(str); err != nil {
logFields.WithError(err).Error("failed to handle the dependencies")
Expand Down
Loading

0 comments on commit f80e13f

Please sign in to comment.