diff --git a/client/utils/servicepusher.go b/client/utils/servicepusher.go index 09c7b2683..880109d99 100644 --- a/client/utils/servicepusher.go +++ b/client/utils/servicepusher.go @@ -82,7 +82,7 @@ func (p *EndpointPusher) addCheck(endpoints []string) { func (p *EndpointPusher) pollReachability(ctx context.Context, endpoint string) { parts := strings.Split(endpoint, ":") if len(parts) != 2 { - log.Errorf(ctx, nil, "[EruResolver] wrong format of endpoint: %s", endpoint) + log.Errorf(ctx, types.ErrInvalidType, "[EruResolver] wrong format of endpoint: %s", endpoint) return } diff --git a/cluster/calcium/build.go b/cluster/calcium/build.go index 706353fb3..7571db09e 100644 --- a/cluster/calcium/build.go +++ b/cluster/calcium/build.go @@ -20,13 +20,13 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch logger := log.WithField("Calcium", "BuildImage").WithField("opts", opts) // Disable build API if scm not set if c.source == nil { - logger.Errorf(ctx, types.ErrSCMNotSet, "") + logger.Error(ctx, types.ErrSCMNotSet) return nil, types.ErrSCMNotSet } // select nodes node, err := c.selectBuildNode(ctx) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } @@ -44,15 +44,15 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch case types.BuildFromExist: refs, node, resp, err = c.buildFromExist(ctx, opts) default: - logger.Errorf(ctx, types.ErrUnknownBuildType, "") + logger.Error(ctx, types.ErrUnknownBuildType) return nil, types.ErrUnknownBuildType } if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } ch, err = c.pushImageAndClean(ctx, resp, node, refs) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return ch, err } @@ -171,7 +171,7 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod log.Infof(ctx, "[BuildImage] Push image %s", tag) rc, err := node.Engine.ImagePush(ctx, tag) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.BuildImageMessage{Error: err.Error()} continue } diff --git a/cluster/calcium/calcium.go b/cluster/calcium/calcium.go index 34a15c912..a9e32ea45 100644 --- a/cluster/calcium/calcium.go +++ b/cluster/calcium/calcium.go @@ -39,7 +39,7 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro // set store store, err := store.NewStore(config, t) if err != nil { - log.Errorf(ctx, err, "") + log.Error(ctx, err) return nil, err } @@ -65,7 +65,7 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro // set resource plugin manager rmgr, err := resources.NewPluginsManager(config) if err != nil { - log.Errorf(ctx, err, "") + log.Error(ctx, err) return nil, err } @@ -96,18 +96,18 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro cal.wal, err = enableWAL(config, cal, store) if err != nil { - log.Errorf(ctx, err, "") + log.Error(ctx, err) return nil, err } cal.identifier, err = config.Identifier() if err != nil { - log.Errorf(ctx, err, "") + log.Error(ctx, err) return nil, err } _ = pool.Invoke(func() { cal.InitMetrics(ctx) }) - log.Errorf(ctx, err, "") + log.Error(ctx, err) return cal, err } diff --git a/cluster/calcium/control.go b/cluster/calcium/control.go index 2232b2971..c402c6283 100644 --- a/cluster/calcium/control.go +++ b/cluster/calcium/control.go @@ -51,7 +51,7 @@ func (c *Calcium) ControlWorkload(ctx context.Context, ids []string, t string, f logger.Infof(ctx, "%v", "[ControlWorkload] Hook Output:") logger.Infof(ctx, "%v", string(utils.MergeHookOutputs(message))) } - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.ControlWorkloadMessage{ WorkloadID: id, Error: err, diff --git a/cluster/calcium/copy.go b/cluster/calcium/copy.go index 7d67ff9ab..3d84d2c4b 100644 --- a/cluster/calcium/copy.go +++ b/cluster/calcium/copy.go @@ -12,7 +12,7 @@ import ( func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *types.CopyMessage, error) { logger := log.WithField("Calcium", "Copy").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } @@ -34,7 +34,7 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type workload, err := c.GetWorkload(ctx, id) if err != nil { for _, path := range paths { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.CopyMessage{ ID: id, Path: path, diff --git a/cluster/calcium/create.go b/cluster/calcium/create.go index 658b35c16..aeff16552 100644 --- a/cluster/calcium/create.go +++ b/cluster/calcium/create.go @@ -23,7 +23,7 @@ import ( func (c *Calcium) CreateWorkload(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateWorkloadMessage, error) { logger := log.WithField("Calcium", "CreateWorkload").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } @@ -32,7 +32,7 @@ func (c *Calcium) CreateWorkload(ctx context.Context, opts *types.DeployOptions) // Count 要大于0 if opts.Count <= 0 { err := types.NewDetailedErr(types.ErrBadCount, opts.Count) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } @@ -97,7 +97,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio func(ctx context.Context) (err error) { defer func() { if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.CreateWorkloadMessage{Error: err} } }() @@ -156,7 +156,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio }) return c.rmgr.RollbackAlloc(ctx, nodename, resourceArgsToRollback) }); e != nil { - logger.Errorf(ctx, e, "") + logger.Error(ctx, e) err = e } } @@ -227,7 +227,7 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context, node, err := c.doGetAndPrepareNode(ctx, nodename, opts.Image) if err != nil { for i := 0; i < deploy; i++ { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.CreateWorkloadMessage{Error: err} } return utils.Range(deploy), err @@ -250,7 +250,7 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context, defer func() { if e != nil { err = e - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) createMsg.Error = err appendLock.Lock() indices = append(indices, idx) diff --git a/cluster/calcium/image.go b/cluster/calcium/image.go index fc4f7939d..88ff5ec66 100644 --- a/cluster/calcium/image.go +++ b/cluster/calcium/image.go @@ -15,18 +15,18 @@ import ( func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (chan *types.CacheImageMessage, error) { logger := log.WithField("Calcium", "CacheImage").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } if len(nodes) == 0 { - logger.Errorf(ctx, types.ErrPodNoNodes, "") + logger.Error(ctx, types.ErrPodNoNodes) return nil, types.ErrPodNoNodes } @@ -49,7 +49,7 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha Message: "", } if err := pullImage(ctx, node, image); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) m.Success = false m.Message = err.Error() } @@ -66,18 +66,18 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (chan *types.RemoveImageMessage, error) { logger := log.WithField("Calcium", "RemoveImage").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } if len(nodes) == 0 { - logger.Errorf(ctx, types.ErrPodNoNodes, "") + logger.Error(ctx, types.ErrPodNoNodes) return nil, types.ErrPodNoNodes } @@ -99,7 +99,7 @@ func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (ch Messages: []string{}, } if removeItems, err := node.Engine.ImageRemove(ctx, image, false, true); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) m.Messages = append(m.Messages, err.Error()) } else { m.Success = true @@ -129,12 +129,12 @@ func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } if len(nodes) == 0 { - logger.Errorf(ctx, types.ErrPodNoNodes, "") + logger.Error(ctx, types.ErrPodNoNodes) return nil, types.ErrPodNoNodes } @@ -155,7 +155,7 @@ func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan Error: nil, } if images, err := node.Engine.ImageList(ctx, opts.Filter); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) msg.Error = err } else { for _, image := range images { diff --git a/cluster/calcium/lambda.go b/cluster/calcium/lambda.go index 569fcfef4..3a5218e69 100644 --- a/cluster/calcium/lambda.go +++ b/cluster/calcium/lambda.go @@ -25,7 +25,7 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC logger := log.WithField("Calcium", "RunAndWait").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return workloadIDs, nil, err } opts.Lambda = true @@ -68,7 +68,7 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC commit, err := c.wal.Log(eventCreateLambda, message.WorkloadID) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return &types.AttachWorkloadMessage{ WorkloadID: message.WorkloadID, Data: []byte(fmt.Sprintf("Create wal failed: %s, %+v", message.WorkloadID, err)), diff --git a/cluster/calcium/log.go b/cluster/calcium/log.go index 87e63a20c..192d97385 100644 --- a/cluster/calcium/log.go +++ b/cluster/calcium/log.go @@ -17,7 +17,7 @@ func (c *Calcium) LogStream(ctx context.Context, opts *types.LogStreamOptions) ( defer close(ch) workload, err := c.GetWorkload(ctx, opts.ID) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.LogStreamMessage{ID: opts.ID, Error: err} return } @@ -31,7 +31,7 @@ func (c *Calcium) LogStream(ctx context.Context, opts *types.LogStreamOptions) ( Stdout: true, Stderr: true, }) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) if err != nil { ch <- &types.LogStreamMessage{ID: opts.ID, Error: err} return diff --git a/cluster/calcium/network.go b/cluster/calcium/network.go index 36d3f99f7..f89229c75 100644 --- a/cluster/calcium/network.go +++ b/cluster/calcium/network.go @@ -17,13 +17,13 @@ func (c *Calcium) ListNetworks(ctx context.Context, podname string, driver strin networks := []*enginetypes.Network{} nodes, err := c.store.GetNodesByPod(ctx, &types.NodeFilter{Podname: podname}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return networks, err } if len(nodes) == 0 { err := types.NewDetailedErr(types.ErrPodNoNodes, podname) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return networks, err } @@ -35,7 +35,7 @@ func (c *Calcium) ListNetworks(ctx context.Context, podname string, driver strin node := nodes[0] networks, err = node.Engine.NetworkList(ctx, drivers) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return networks, err } @@ -44,12 +44,12 @@ func (c *Calcium) ConnectNetwork(ctx context.Context, network, target, ipv4, ipv logger := log.WithField("Calcium", "ConnectNetwork").WithField("network", network).WithField("target", target).WithField("ipv4", ipv4).WithField("ipv6", ipv6) workload, err := c.GetWorkload(ctx, target) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } networks, err := workload.Engine.NetworkConnect(ctx, network, target, ipv4, ipv6) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return networks, err } @@ -58,11 +58,11 @@ func (c *Calcium) DisconnectNetwork(ctx context.Context, network, target string, logger := log.WithField("Calcium", "DisconnectNetwork").WithField("network", network).WithField("target", target).WithField("force", force) workload, err := c.GetWorkload(ctx, target) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } if err = workload.Engine.NetworkDisconnect(ctx, network, target, force); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) } return err } diff --git a/cluster/calcium/node.go b/cluster/calcium/node.go index 7ce4785b3..2219d9c15 100644 --- a/cluster/calcium/node.go +++ b/cluster/calcium/node.go @@ -17,7 +17,7 @@ import ( func (c *Calcium) AddNode(ctx context.Context, opts *types.AddNodeOptions) (*types.Node, error) { logger := log.WithField("Calcium", "AddNode").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } var resourceCapacity map[string]types.NodeResourceArgs @@ -68,18 +68,18 @@ func (c *Calcium) AddNode(ctx context.Context, opts *types.AddNodeOptions) (*typ func (c *Calcium) RemoveNode(ctx context.Context, nodename string) error { logger := log.WithField("Calcium", "RemoveNode").WithField("nodename", nodename) if nodename == "" { - logger.Errorf(ctx, types.ErrEmptyNodeName, "") + logger.Error(ctx, types.ErrEmptyNodeName) return types.ErrEmptyNodeName } return c.withNodePodLocked(ctx, nodename, func(ctx context.Context, node *types.Node) error { workloads, err := c.ListNodeWorkloads(ctx, node.Name, nil) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } // need drain first if len(workloads) > 0 { - logger.Errorf(ctx, types.ErrNodeNotEmpty, "") + logger.Error(ctx, types.ErrNodeNotEmpty) return types.ErrNodeNotEmpty } @@ -106,7 +106,7 @@ func (c *Calcium) ListPodNodes(ctx context.Context, opts *types.ListNodesOptions logger := log.WithField("Calcium", "ListPodNodes").WithField("podname", opts.Podname).WithField("labels", opts.Labels).WithField("all", opts.All).WithField("info", opts.CallInfo) nodes, err := c.store.GetNodesByPod(ctx, &types.NodeFilter{Podname: opts.Podname, Labels: opts.Labels, All: opts.All}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } ch := make(chan *types.Node) @@ -142,15 +142,15 @@ func (c *Calcium) ListPodNodes(ctx context.Context, opts *types.ListNodesOptions func (c *Calcium) GetNode(ctx context.Context, nodename string) (node *types.Node, err error) { logger := log.WithField("Calcium", "GetNode").WithField("nodename", nodename) if nodename == "" { - logger.Errorf(ctx, types.ErrEmptyNodeName, "") + logger.Error(ctx, types.ErrEmptyNodeName) return nil, types.ErrEmptyNodeName } if node, err = c.store.GetNode(ctx, nodename); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } if node.Resource.Capacity, node.Resource.Usage, node.Resource.Diffs, err = c.rmgr.GetNodeResourceInfo(ctx, node.Name, nil, false); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } return node, nil @@ -160,16 +160,16 @@ func (c *Calcium) GetNode(ctx context.Context, nodename string) (node *types.Nod func (c *Calcium) GetNodeEngineInfo(ctx context.Context, nodename string) (*enginetypes.Info, error) { logger := log.WithField("Calcium", "GetNodeEngine").WithField("nodename", nodename) if nodename == "" { - logger.Errorf(ctx, types.ErrEmptyNodeName, "") + logger.Error(ctx, types.ErrEmptyNodeName) return nil, types.ErrEmptyNodeName } node, err := c.store.GetNode(ctx, nodename) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } engineInfo, err := node.Engine.Info(ctx) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return engineInfo, err } @@ -178,7 +178,7 @@ func (c *Calcium) GetNodeEngineInfo(ctx context.Context, nodename string) (*engi func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*types.Node, error) { logger := log.WithField("Calcium", "SetNode").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } var n *types.Node diff --git a/cluster/calcium/pod.go b/cluster/calcium/pod.go index 96b831ac3..a4da21832 100644 --- a/cluster/calcium/pod.go +++ b/cluster/calcium/pod.go @@ -11,11 +11,11 @@ import ( func (c *Calcium) AddPod(ctx context.Context, podname, desc string) (*types.Pod, error) { logger := log.WithField("Calcium", "AddPod").WithField("podname", podname).WithField("desc", desc) if podname == "" { - logger.Errorf(ctx, types.ErrEmptyPodName, "") + logger.Error(ctx, types.ErrEmptyPodName) return nil, types.ErrEmptyPodName } pod, err := c.store.AddPod(ctx, podname, desc) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return pod, err } @@ -23,7 +23,7 @@ func (c *Calcium) AddPod(ctx context.Context, podname, desc string) (*types.Pod, func (c *Calcium) RemovePod(ctx context.Context, podname string) error { logger := log.WithField("Calcium", "RemovePod").WithField("podname", podname) if podname == "" { - logger.Errorf(ctx, types.ErrEmptyPodName, "") + logger.Error(ctx, types.ErrEmptyPodName) return types.ErrEmptyPodName } @@ -35,7 +35,7 @@ func (c *Calcium) RemovePod(ctx context.Context, podname string) error { // TODO dissociate workload to node // TODO should remove node first err := c.store.RemovePod(ctx, podname) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err }) } @@ -44,17 +44,17 @@ func (c *Calcium) RemovePod(ctx context.Context, podname string) error { func (c *Calcium) GetPod(ctx context.Context, podname string) (*types.Pod, error) { logger := log.WithField("Calcium", "GetPod").WithField("podname", podname) if podname == "" { - logger.Errorf(ctx, types.ErrEmptyPodName, "") + logger.Error(ctx, types.ErrEmptyPodName) return nil, types.ErrEmptyPodName } pod, err := c.store.GetPod(ctx, podname) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return pod, err } // ListPods show pods func (c *Calcium) ListPods(ctx context.Context) ([]*types.Pod, error) { pods, err := c.store.GetAllPods(ctx) - log.WithField("Calcium", "ListPods").Errorf(ctx, err, "") + log.WithField("Calcium", "ListPods").Error(ctx, err) return pods, err } diff --git a/cluster/calcium/realloc.go b/cluster/calcium/realloc.go index 376de801e..7a941f0c6 100644 --- a/cluster/calcium/realloc.go +++ b/cluster/calcium/realloc.go @@ -24,7 +24,7 @@ func (c *Calcium) ReallocResource(ctx context.Context, opts *types.ReallocOption return c.withNodePodLocked(ctx, workload.Nodename, func(ctx context.Context, node *types.Node) error { return c.withWorkloadLocked(ctx, opts.ID, func(ctx context.Context, workload *types.Workload) error { err := c.doReallocOnNode(ctx, node, workload, originWorkload, opts) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err }) }) diff --git a/cluster/calcium/remap.go b/cluster/calcium/remap.go index d31b06981..ad9908649 100644 --- a/cluster/calcium/remap.go +++ b/cluster/calcium/remap.go @@ -24,7 +24,7 @@ func (c *Calcium) doRemapResourceAndLog(ctx context.Context, logger *log.Fields, if ch, err := c.remapResource(ctx, node); err == nil { for msg := range ch { logger.Infof(ctx, "[doRemapResourceAndLog] id %v", msg.id) - logger.WithField("id", msg.id).Errorf(ctx, msg.err, "") // nolint:errcheck + logger.WithField("id", msg.id).Error(ctx, msg.err) // nolint:errcheck } } return nil diff --git a/cluster/calcium/replace.go b/cluster/calcium/replace.go index 9b2eacd11..880fc4de6 100644 --- a/cluster/calcium/replace.go +++ b/cluster/calcium/replace.go @@ -18,7 +18,7 @@ import ( func (c *Calcium) ReplaceWorkload(ctx context.Context, opts *types.ReplaceOptions) (chan *types.ReplaceWorkloadMessage, error) { logger := log.WithField("Calcium", "ReplaceWorkload").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } opts.Normalize() @@ -31,7 +31,7 @@ func (c *Calcium) ReplaceWorkload(ctx context.Context, opts *types.ReplaceOption Appname: opts.Name, Entrypoint: opts.Entrypoint.Name, Nodename: nodename, }) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } for _, workload := range workloads { diff --git a/cluster/calcium/resource.go b/cluster/calcium/resource.go index 1d8faa1dd..8e74667de 100644 --- a/cluster/calcium/resource.go +++ b/cluster/calcium/resource.go @@ -15,7 +15,7 @@ func (c *Calcium) PodResource(ctx context.Context, podname string) (chan *types. logger := log.WithField("Calcium", "PodResource").WithField("podname", podname) nodes, err := c.store.GetNodesByPod(ctx, &types.NodeFilter{Podname: podname}) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } ch := make(chan *types.NodeResource) @@ -31,7 +31,7 @@ func (c *Calcium) PodResource(ctx context.Context, podname string) (chan *types. defer wg.Done() nr, err := c.doGetNodeResource(ctx, node.Name, false, false) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) nr = &types.NodeResource{ Name: node.Name, Diffs: []string{err.Error()}, } @@ -48,7 +48,7 @@ func (c *Calcium) PodResource(ctx context.Context, podname string) (chan *types. func (c *Calcium) NodeResource(ctx context.Context, nodename string, fix bool) (*types.NodeResource, error) { logger := log.WithField("Calcium", "NodeResource").WithField("nodename", nodename).WithField("fix", fix) nr, err := c.doGetNodeResource(ctx, nodename, true, fix) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nr, err } diff --git a/cluster/calcium/send.go b/cluster/calcium/send.go index 4658a05d9..728442dec 100644 --- a/cluster/calcium/send.go +++ b/cluster/calcium/send.go @@ -13,7 +13,7 @@ import ( func (c *Calcium) Send(ctx context.Context, opts *types.SendOptions) (chan *types.SendMessage, error) { logger := log.WithField("Calcium", "Send").WithField("opts", opts) if err := opts.Validate(); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } ch := make(chan *types.SendMessage) @@ -30,12 +30,12 @@ func (c *Calcium) Send(ctx context.Context, opts *types.SendOptions) (chan *type if err := c.withWorkloadLocked(ctx, id, func(ctx context.Context, workload *types.Workload) error { for _, file := range opts.Files { err := c.doSendFileToWorkload(ctx, workload.Engine, workload.ID, file) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.SendMessage{ID: id, Path: file.Filename, Error: err} } return nil }); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) ch <- &types.SendMessage{ID: id, Error: err} } } diff --git a/cluster/calcium/status.go b/cluster/calcium/status.go index 328514625..06b8ddb88 100644 --- a/cluster/calcium/status.go +++ b/cluster/calcium/status.go @@ -20,11 +20,11 @@ func (c *Calcium) SetNodeStatus(ctx context.Context, nodename string, ttl int64) logger := log.WithField("Calcium", "SetNodeStatus").WithField("nodename", nodename).WithField("ttl", ttl) node, err := c.store.GetNode(ctx, nodename) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } err = c.store.SetNodeStatus(ctx, node, ttl) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } @@ -39,7 +39,7 @@ func (c *Calcium) GetWorkloadsStatus(ctx context.Context, ids []string) ([]*type for _, id := range ids { s, err := c.store.GetWorkloadStatus(ctx, id) if err != nil { - log.WithField("Calcium", "GetWorkloadStatus").WithField("ids", ids).Errorf(ctx, err, "") + log.WithField("Calcium", "GetWorkloadStatus").WithField("ids", ids).Error(ctx, err) return r, err } r = append(r, s) @@ -56,13 +56,13 @@ func (c *Calcium) SetWorkloadsStatus(ctx context.Context, statusMetas []*types.S if statusMeta.Appname == "" || statusMeta.Nodename == "" || statusMeta.Entrypoint == "" { workload, err := c.store.GetWorkload(ctx, statusMeta.ID) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } appname, entrypoint, _, err := utils.ParseWorkloadName(workload.Name) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } @@ -77,7 +77,7 @@ func (c *Calcium) SetWorkloadsStatus(ctx context.Context, statusMetas []*types.S } if err := c.store.SetWorkloadStatus(ctx, statusMeta, ttl); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return nil, err } r = append(r, statusMeta) diff --git a/cluster/calcium/wal.go b/cluster/calcium/wal.go index 5cef73ae9..e924ed9b2 100644 --- a/cluster/calcium/wal.go +++ b/cluster/calcium/wal.go @@ -172,11 +172,11 @@ func (h *CreateWorkloadHandler) Handle(ctx context.Context, raw interface{}) (er // workload meta doesn't exist node, err := h.calcium.GetNode(ctx, wrk.Nodename) if err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } if err = node.Engine.VirtualizationRemove(ctx, wrk.ID, true, true); err != nil && !errors.Is(err, types.ErrWorkloadNotExists) { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } @@ -312,7 +312,7 @@ func (h *ProcessingCreatedHandler) Handle(ctx context.Context, raw interface{}) defer cancel() if err = h.store.DeleteProcessing(ctx, processing); err != nil { - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return err } logger.Infof(ctx, "obsolete processing deleted") diff --git a/cluster/calcium/workload.go b/cluster/calcium/workload.go index 12554f2d2..5a6912ea0 100644 --- a/cluster/calcium/workload.go +++ b/cluster/calcium/workload.go @@ -18,14 +18,14 @@ func (c *Calcium) GetWorkload(ctx context.Context, id string) (workload *types.W return workload, types.ErrEmptyWorkloadID } workload, err = c.store.GetWorkload(ctx, id) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return workload, err } // GetWorkloads get workloads func (c *Calcium) GetWorkloads(ctx context.Context, ids []string) (workloads []*types.Workload, err error) { workloads, err = c.store.GetWorkloads(ctx, ids) - log.WithField("Calcium", "GetWorkloads").WithField("ids", ids).Errorf(ctx, err, "") + log.WithField("Calcium", "GetWorkloads").WithField("ids", ids).Error(ctx, err) return workloads, err } @@ -45,6 +45,6 @@ func (c *Calcium) ListNodeWorkloads(ctx context.Context, nodename string, labels return workloads, types.ErrEmptyNodeName } workloads, err = c.store.ListNodeWorkloads(ctx, nodename, labels) - logger.Errorf(ctx, err, "") + logger.Error(ctx, err) return workloads, err } diff --git a/core.go b/core.go index 6abf3c40d..61121da83 100644 --- a/core.go +++ b/core.go @@ -61,7 +61,7 @@ func serve(c *cli.Context) error { } cluster, err := calcium.New(c.Context, config, t) if err != nil { - log.Errorf(c.Context, err, "") + log.Error(c.Context, err) return err } defer cluster.Finalizer() @@ -71,7 +71,7 @@ func serve(c *cli.Context) error { vibranium := rpc.New(cluster, config, stop) s, err := net.Listen("tcp", config.Bind) if err != nil { - log.Errorf(c.Context, err, "") + log.Error(c.Context, err) return err } diff --git a/log/log.go b/log/log.go index fe44a65e3..e524b86d7 100644 --- a/log/log.go +++ b/log/log.go @@ -118,6 +118,11 @@ func (f Fields) Errorf(ctx context.Context, err error, format string, args ...in errorEvent(err).Fields(f.kv).Msgf(format, args...) } +// Error forwards to sentry +func (f Fields) Error(ctx context.Context, err error, args ...interface{}) { + f.Errorf(ctx, err, "%v", args...) +} + // for sentry func genSentryTracingInfo(ctx context.Context) (tracingInfo string) { if ctx == nil { diff --git a/types/errors.go b/types/errors.go index eaa6e7015..dd696b142 100644 --- a/types/errors.go +++ b/types/errors.go @@ -1,8 +1,9 @@ package types import ( - "errors" "fmt" + + "github.com/pkg/errors" ) // errors