Skip to content

Commit

Permalink
remove fmt.Sprintf from log msg
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten committed Oct 17, 2019
1 parent 510220b commit 618a1d9
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 45 deletions.
9 changes: 4 additions & 5 deletions pkg/blockstorage/awsebs/awsebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package awsebs

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -340,7 +339,7 @@ func (s *ebsStorage) SnapshotCreateWaitForCompletion(ctx context.Context, snap *
}

func (s *ebsStorage) SnapshotDelete(ctx context.Context, snapshot *blockstorage.Snapshot) error {
log.Print(fmt.Sprintf("EBS Snapshot ID %s", snapshot.ID))
log.Print("Deleting EBS Snapshot", field.M{"SnapshotID": snapshot.ID})
rmsi := &ec2.DeleteSnapshotInput{}
rmsi.SetSnapshotId(snapshot.ID)
rmsi.SetDryRun(s.ec2Cli.DryRun)
Expand Down Expand Up @@ -523,7 +522,7 @@ func waitOnVolume(ctx context.Context, ec2Cli *EC2, vol *ec2.Volume) error {
for {
dvo, err := ec2Cli.DescribeVolumesWithContext(ctx, dvi)
if err != nil {
log.WithError(err).Print(fmt.Sprintf("Failed to describe volume %s", aws.StringValue(vol.VolumeId)))
log.WithError(err).Print("Failed to describe volume", field.M{"VolumeID": aws.StringValue(vol.VolumeId)})
return err
}
if len(dvo.Volumes) != 1 {
Expand All @@ -534,7 +533,7 @@ func waitOnVolume(ctx context.Context, ec2Cli *EC2, vol *ec2.Volume) error {
return errors.New("Creating EBS volume failed")
}
if *s.State == ec2.VolumeStateAvailable {
log.Print(fmt.Sprintf("Volume %s complete", *vol.VolumeId))
log.Print("Volume creation complete", field.M{"VolumeID": *vol.VolumeId})
return nil
}
log.Print("Update", field.M{"Volume": *vol.VolumeId, "State": *s.State})
Expand Down Expand Up @@ -569,7 +568,7 @@ func waitOnSnapshotID(ctx context.Context, ec2Cli *EC2, snapID string) error {
return false, errors.New("Snapshot EBS volume failed")
}
if *s.State == ec2.SnapshotStateCompleted {
log.Print(fmt.Sprintf("Snapshot with snapshot_id: %s completed", snapID))
log.Print("Snapshot completed", field.M{"SnapshotID": snapID})
return true, nil
}
log.Debug().Print("Snapshot progress", field.M{"snapshot_id": snapID, "progress": *s.Progress})
Expand Down
3 changes: 1 addition & 2 deletions pkg/blockstorage/blockstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package blockstorage_test

import (
"context"
"fmt"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -151,7 +150,7 @@ func (s *BlockStorageProviderSuite) TestSnapshotCopy(c *C) {
snap, err := s.provider.SnapshotCopy(context.TODO(), *srcSnapshot, *dstSnapshot)
c.Assert(err, IsNil)

log.Print(fmt.Sprintf("Copied snapshot %v to %v", srcSnapshot.ID, snap.ID))
log.Print("Snapshot copied", field.M{"FromSnapshotID": srcSnapshot.ID, "ToSnapshotID": snap.ID})

config := s.getConfig(c, dstSnapshot.Region)
provider, err := getter.New().Get(s.storageType, config)
Expand Down
6 changes: 3 additions & 3 deletions pkg/blockstorage/gcepd/gcepd.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s *gpdStorage) SnapshotCreateWaitForCompletion(ctx context.Context, snap *
func (s *gpdStorage) SnapshotDelete(ctx context.Context, snapshot *blockstorage.Snapshot) error {
op, err := s.service.Snapshots.Delete(s.project, snapshot.ID).Context(ctx).Do()
if isNotFoundError(err) {
log.Debug().Print("Cannot delete snapshot.", field.M{"SnapshotID": snapshot.ID, "reason": "Snapshot not found"})
log.Debug().Print("Cannot delete snapshot", field.M{"SnapshotID": snapshot.ID, "reason": "Snapshot not found"})
return nil
}
if err != nil {
Expand Down Expand Up @@ -494,7 +494,7 @@ func (s *gpdStorage) waitOnOperation(ctx context.Context, op *compute.Operation,
}
return false, errors.Errorf("%s", errJSON)
}
log.Print(fmt.Sprintf("Operation %s done", op.OperationType))
log.Print("Operation done", field.M{"OperationType": op.OperationType})
return true, nil
case operationPending, operationRunning:
log.Debug().Print("Operation status update", field.M{"Operation": op.OperationType, "Status": op.Status, "Status message": op.StatusMessage, "Progress": op.Progress})
Expand Down Expand Up @@ -522,7 +522,7 @@ func (s *gpdStorage) waitOnSnapshotID(ctx context.Context, id string) error {
return false, errors.New("Snapshot GCP volume failed")
}
if snap.Status == "READY" {
log.Print(fmt.Sprintf("Snapshot with snapshot_id: %s completed", id))
log.Print("Snapshot completed", field.M{"SnapshotID": id})
return true, nil
}
log.Debug().Print("Snapshot status", field.M{"snapshot_id": id, "status": snap.Status})
Expand Down
6 changes: 3 additions & 3 deletions pkg/blockstorage/ibm/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *ibmCloud) SnapshotCreate(ctx context.Context, volume blockstorage.Volum
}

if ibmvol.SnapshotSpace == nil {
log.Debug().Print(fmt.Sprintf("Ordering snapshot space for volume %+v", ibmvol))
log.Debug().Print("Ordering snapshot space for volume", field.M{"Volume": ibmvol})
ibmvol.SnapshotSpace = ibmvol.Capacity
err = s.cli.Service.OrderSnapshot(*ibmvol)
if err != nil {
Expand All @@ -238,7 +238,7 @@ func (s *ibmCloud) SnapshotCreate(ctx context.Context, volume blockstorage.Volum
return nil, errors.Wrapf(err, "Wait is expired for order Snapshot space, volume_id :%s", volume.ID)
}
}
log.Debug().Print(fmt.Sprintf("Creating snapshot for vol %+v", ibmvol))
log.Debug().Print("Creating snapshot", field.M{"Volume": ibmvol})
snap, err := s.cli.Service.CreateSnapshot(ibmvol, alltags)
if err != nil {
return nil, errors.Wrapf(err, "Failed to create snapshot, volume_id: %s", volume.ID)
Expand Down Expand Up @@ -300,7 +300,7 @@ func (s *ibmCloud) VolumeCreateFromSnapshot(ctx context.Context, snapshot blocks
// GetSnapshot doens't return correct Volume info
snap.VolumeID = snapshot.Volume.ID
snap.Volume.VolumeID = snapshot.Volume.ID
log.Debug().Print(fmt.Sprintf("Snapshot with new volume ID %+v", snap))
log.Debug().Print("Creating Volume from Snapshot with new volume ID", field.M{"inputSnapshot": snap})

vol, err := s.cli.Service.CreateVolumeFromSnapshot(*snap, tags)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/blockstorage/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package tags

import (
"fmt"
"os"
"regexp"
"strings"

"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/log"
)

Expand Down Expand Up @@ -63,7 +63,7 @@ func AddMissingTags(existingTags map[string]string, tagsToAdd map[string]string)
// Add missing tags
for k, v := range tagsToAdd {
if val, ok := ret[k]; ok {
log.Print(fmt.Sprintf("Ignoring duplicate tag: %s:%s. Retained value: %s", k, v, val))
log.Print("Ignoring duplicate tag", field.M{k: v, "RetainedValue": val})
} else {
ret[k] = v
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/chronicle/chronicle_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pkg/errors"

"github.com/kanisterio/kanister/pkg/envdir"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/location"
"github.com/kanisterio/kanister/pkg/log"
"github.com/kanisterio/kanister/pkg/param"
Expand All @@ -47,7 +48,7 @@ func (p PushParams) Validate() error {
}

func Push(p PushParams) error {
log.Debug().Print(fmt.Sprintf("%#v", p))
log.Debug().Print("", field.M{"PushParams": p})
ctx := setupSignalHandler(context.Background())
var i int
for {
Expand Down Expand Up @@ -100,7 +101,7 @@ func push(ctx context.Context, p PushParams, ord int) error {
}
}
ap, err := readArtifactPathFile(p.ArtifactFile)
log.Debug().Print(fmt.Sprintf("Pushing output from Command %d: %v. Environment: %v", ord, p.Command, env))
log.Debug().Print("Pushing output from Command ", field.M{"order": ord, "command": p.Command, "Environment": env})
return pushWithEnv(ctx, p.Command, ap, ord, prof, env)
}

Expand Down
28 changes: 16 additions & 12 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func checkCRAccess(cli versioned.Interface, ns string) error {
func (c *Controller) onAdd(obj interface{}) {
o, ok := obj.(runtime.Object)
if !ok {
log.Error().Print(fmt.Sprintf("Added object type <%T> does not implement runtime.Object", obj))
objType := fmt.Sprintf("%T", obj)
log.Error().Print("Added object type does not implement runtime.Object", field.M{"ObjectType": objType})
return
}
o = o.DeepCopyObject()
Expand All @@ -145,7 +146,8 @@ func (c *Controller) onAdd(obj interface{}) {
log.Error().WithError(err).Print("Callback onAddBlueprint() failed")
}
default:
log.Error().Print(fmt.Sprintf("Unknown object type <%T>", o))
objType := fmt.Sprintf("%T", o)
log.Error().Print("Unknown object type", field.M{"ObjectType": objType})
}
}

Expand All @@ -165,7 +167,8 @@ func (c *Controller) onUpdate(oldObj, newObj interface{}) {
c.logAndErrorEvent(nil, "Callback onUpdateBlueprint() failed:", "Error", err, new)
}
default:
log.Error().Print(fmt.Sprintf("Unknown object type <%T>", oldObj))
objType := fmt.Sprintf("%T", oldObj)
log.Error().Print("Unknown object type", field.M{"ObjectType": objType})
}
}

Expand All @@ -182,7 +185,8 @@ func (c *Controller) onDelete(obj interface{}) {
c.logAndErrorEvent(nil, "Callback onDeleteBlueprint() failed:", "Error", err, v)
}
default:
log.Error().Print(fmt.Sprintf("Unknown object type <%T>", obj))
objType := fmt.Sprintf("%T", obj)
log.Error().Print("Unknown object type", field.M{"ObjectType": objType})
}
}

Expand Down Expand Up @@ -212,23 +216,23 @@ func (c *Controller) onAddBlueprint(bp *crv1alpha1.Blueprint) error {

func (c *Controller) onUpdateActionSet(oldAS, newAS *crv1alpha1.ActionSet) error {
if err := validate.ActionSet(newAS); err != nil {
log.Print(fmt.Sprintf("Updated ActionSet '%s'", newAS.Name))
log.Print("Updated ActionSet", field.M{"ActionSetName": newAS.Name})
return err
}
if newAS.Status == nil || newAS.Status.State != crv1alpha1.StateRunning {
if newAS.Status == nil {
log.Print(fmt.Sprintf("Updated ActionSet '%s' Status->nil", newAS.Name))
log.Print("Updated ActionSet", field.M{"Actionset": newAS.Name, "Status": "nil"})
} else if newAS.Status.State == crv1alpha1.StateComplete {
c.logAndSuccessEvent(nil, fmt.Sprintf("Updated ActionSet '%s' Status->%s", newAS.Name, newAS.Status.State), "Update Complete", newAS)
} else {
log.Print(fmt.Sprintf("Updated ActionSet '%s' Status->%s", newAS.Name, newAS.Status.State))
log.Print("Updated ActionSet", field.M{"Actionset": newAS.Name, "Status": newAS.Status.State})
}
return nil
}
for _, as := range newAS.Status.Actions {
for _, p := range as.Phases {
if p.State != crv1alpha1.StateComplete {
log.Print(fmt.Sprintf("Updated ActionSet '%s' Status->%s, Phase: %s->%s", newAS.Name, newAS.Status.State, p.Name, p.State))
log.Print("Updated ActionSet", field.M{"Actionset": newAS.Name, "Status": newAS.Status.State, "Phase": fmt.Sprintf("%s->%s", p.Name, p.State)})
return nil
}
}
Expand All @@ -243,13 +247,13 @@ func (c *Controller) onUpdateActionSet(oldAS, newAS *crv1alpha1.ActionSet) error
}

func (c *Controller) onUpdateBlueprint(oldBP, newBP *crv1alpha1.Blueprint) error {
log.Print(fmt.Sprintf("Updated Blueprint '%s'", newBP.Name))
log.Print("Updated Blueprint", field.M{"BlueprintName": newBP.Name})
return nil
}

func (c *Controller) onDeleteActionSet(as *crv1alpha1.ActionSet) error {
asName := as.GetName()
log.Print(fmt.Sprintf("Deleted ActionSet %s", asName))
log.Print("Deleted ActionSet", field.M{"ActionSetName": asName})
v, ok := c.actionSetTombMap.Load(asName)
if !ok {
return nil
Expand All @@ -264,7 +268,7 @@ func (c *Controller) onDeleteActionSet(as *crv1alpha1.ActionSet) error {
}

func (c *Controller) onDeleteBlueprint(bp *crv1alpha1.Blueprint) error {
log.Print(fmt.Sprintf("Deleted Blueprint %s", bp.GetName()))
log.Print("Deleted Blueprint ", field.M{"BlueprintName": bp.GetName()})
return nil
}

Expand Down Expand Up @@ -361,7 +365,7 @@ func (c *Controller) handleActionSet(as *crv1alpha1.ActionSet) (err error) {
return errors.WithStack(err)
}
}
log.WithContext(ctx).Print(fmt.Sprintf("Created actionset %s and started executing actions", as.GetName()))
log.WithContext(ctx).Print("Created actionset and started executing actions", field.M{"NewActionSetName": as.GetName()})
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package format

import (
"bufio"
"fmt"
"io"
"regexp"
"strings"

"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/log"
)

Expand All @@ -44,14 +44,14 @@ func LogStream(podName string, containerName string, output io.ReadCloser) chan
logCh <- l
}
if err := s.Err(); err != nil {
log.Error().Print(fmt.Sprintf("Pod: %s, Container: %s, Failed to stream log from pod: %s", podName, containerName, err.Error()))
log.Error().WithError(err).Print("Failed to stream log from pod", field.M{"Pod": podName, "Container": containerName})
}
}()
return logCh
}

func info(podName string, containerName string, l string) {
if strings.TrimSpace(l) != "" {
log.Print(fmt.Sprintf("Pod: %s, Container: %s, Out: %s", podName, containerName, l))
log.Print("Pod Update", field.M{"Pod": podName, "Container": containerName, "Out": l})
}
}
4 changes: 2 additions & 2 deletions pkg/function/create_volume_from_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package function
import (
"context"
"encoding/json"
"fmt"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/kanisterio/kanister/pkg/blockstorage"
"github.com/kanisterio/kanister/pkg/blockstorage/getter"
awsconfig "github.com/kanisterio/kanister/pkg/config/aws"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/kube"
kubevolume "github.com/kanisterio/kanister/pkg/kube/volume"
"github.com/kanisterio/kanister/pkg/log"
Expand Down Expand Up @@ -117,7 +117,7 @@ func createVolumeFromSnapshot(ctx context.Context, cli kubernetes.Interface, nam
if err != nil {
return nil, errors.Wrapf(err, "Unable to create PV for volume %v", *vol)
}
log.Print(fmt.Sprintf("Restore/Create volume from snapshot completed for pvc: %s, volume: %s", pvc, pv))
log.Print("Restore/Create volume from snapshot completed", field.M{"PVC": pvc, "Volume": pv})
providerList[pvcInfo.PVCName] = provider
}
return providerList, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/function/delete_volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package function
import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/pkg/errors"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/kanisterio/kanister/pkg/blockstorage"
"github.com/kanisterio/kanister/pkg/blockstorage/getter"
awsconfig "github.com/kanisterio/kanister/pkg/config/aws"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/log"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -81,15 +81,15 @@ func deleteVolumeSnapshot(ctx context.Context, cli kubernetes.Interface, namespa
snapshot, err := provider.SnapshotGet(ctx, pvcInfo.SnapshotID)
if err != nil {
if strings.Contains(err.Error(), SnapshotDoesNotExistError) {
log.Debug().Print(fmt.Sprintf("Snapshot %s already deleted", pvcInfo.SnapshotID))
log.Debug().Print("Snapshot already deleted", field.M{"SnapshotID": pvcInfo.SnapshotID})
} else {
return nil, errors.Wrapf(err, "Failed to get Snapshot from Provider")
}
}
if err = provider.SnapshotDelete(ctx, snapshot); err != nil {
return nil, err
}
log.Print(fmt.Sprintf("Successfully deleted snapshot %s", pvcInfo.SnapshotID))
log.Print("Successfully deleted snapshot", field.M{"SnapshotID": pvcInfo.SnapshotID})
providerList[pvcInfo.PVCName] = provider
}
return providerList, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/kube/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/log"
)

Expand Down Expand Up @@ -115,7 +116,7 @@ func (job *Job) Create() error {
return errors.Wrapf(err, "Failed to create job %s", job.name)
}
job.name = newJob.Name
log.Print(fmt.Sprintf("New job %s created", job.name))
log.Print("New job created", field.M{"JobName": job.name})

return nil
}
Expand Down Expand Up @@ -173,7 +174,7 @@ func (job *Job) WaitForCompletion(ctx context.Context) error {
conditions := k8sJob.Status.Conditions
for _, condition := range conditions {
if condition.Type == batch.JobComplete {
log.Print(fmt.Sprintf("Job %s reported complete\n", job.name))
log.Print("Job reported complete\n", field.M{"JobName": job.name})
return nil
} else if condition.Type == batch.JobFailed {
return errors.Errorf("Job %s failed", job.name)
Expand All @@ -195,7 +196,7 @@ func (job *Job) Delete() error {
if err != nil {
return errors.Wrapf(err, "Failed to delete job %s", job.name)
}
log.Print(fmt.Sprintf("Deleted job %s", job.name))
log.Print("Deleted job", field.M{"JobName": job.name})

return nil
}
Loading

0 comments on commit 618a1d9

Please sign in to comment.