Skip to content

Commit

Permalink
refactor logs
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Nov 29, 2018
1 parent 71c2cc6 commit b9eb2c4
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cluster/calcium/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (c *Calcium) doBuildImage(ctx context.Context, buildContext io.ReadCloser,
if err != nil {
log.Errorf("[BuildImage] Remove build image cache error: %s", err)
}
log.Debugf("[BuildImage] Clean cached image and release space %d", r.SpaceReclaimed)
log.Infof("[BuildImage] Clean cached image and release space %d", r.SpaceReclaimed)
}(tag)

ch <- &types.BuildImageMessage{Stream: fmt.Sprintf("finished %s\n", tag), Status: "finished", Progress: tag}
Expand Down
3 changes: 1 addition & 2 deletions cluster/calcium/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type
go func() {
defer close(ch)
wg := sync.WaitGroup{}
log.Debugf("[Copy] Copy %d containers files", len(opts.Targets))
log.Infof("[Copy] Copy %d containers files", len(opts.Targets))
// container one by one
for cid, paths := range opts.Targets {
wg.Add(1)
Expand All @@ -37,7 +37,6 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type
ch <- makeCopyMessage(cid, cluster.CopyFailed, "", path, err, nil)
return
}
log.Debugf("[Copy] Docker cp stat: %v", stat)
ch <- makeCopyMessage(cid, cluster.CopyOK, stat.Name, path, nil, resp)
}(path)
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *Calcium) doCreateContainerOnNode(ctx context.Context, nodeInfo types.No
log.Errorf("[doCreateContainerOnNode] Error when create and start a container, %v", ms[i].Error)
continue
}
log.Debugf("[doCreateContainerOnNode] create container success %s", ms[i].ContainerID)
log.Infof("[doCreateContainerOnNode] create container success %s", ms[i].ContainerID)
}

return ms
Expand Down
11 changes: 5 additions & 6 deletions cluster/calcium/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func distributionInspect(ctx context.Context, node *types.Node, image, auth stri

// Pull an image
func pullImage(ctx context.Context, node *types.Node, image, auth string) error {
log.Debugf("[pullImage] Pulling image %s", image)
log.Infof("[pullImage] Pulling image %s", image)
if image == "" {
return types.ErrNoImage
}
Expand All @@ -214,15 +214,15 @@ func pullImage(ctx context.Context, node *types.Node, image, auth string) error
return nil
}

log.Debug("[pullImage] Image not cached, pulling")
log.Info("[pullImage] Image not cached, pulling")
pullOptions := enginetypes.ImagePullOptions{All: false, RegistryAuth: auth}
outStream, err := node.Engine.ImagePull(ctx, image, pullOptions)
if err != nil {
log.Errorf("[pullImage] Error during pulling image %s: %v", image, err)
return err
}
ensureReaderClosed(outStream)
log.Debugf("[pullImage] Done pulling image %s", image)
log.Infof("[pullImage] Done pulling image %s", image)
return nil
}

Expand Down Expand Up @@ -312,15 +312,14 @@ func cleanImageOnNode(ctx context.Context, node *types.Node, image string, count
}

images = images[count:]
log.Debugf("[cleanImageOnNode] Delete Images: %v", images)

for _, image := range images {
log.Debugf("[cleanImageOnNode] Delete Images: %s", image.RepoTags)
_, err := node.Engine.ImageRemove(ctx, image.ID, enginetypes.ImageRemoveOptions{
Force: false,
PruneChildren: true,
})
if err != nil {
log.Errorf("[cleanImageOnNode] Node %s ImageRemove error: %s, imageID: %s", node.Name, err, image.ID)
log.Errorf("[cleanImageOnNode] Node %s ImageRemove error: %s, imageID: %s", node.Name, err, image.RepoTags)
}
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion cluster/calcium/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
"github.com/sanity-io/litter"
log "github.com/sirupsen/logrus"
)

Expand All @@ -31,7 +32,7 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, std

// 创建容器, 有问题就
// 不能让 CTX 作祟
log.Debugf("[RunAndWait] Args: %v", opts)
log.Debugf("[RunAndWait] Args: %s", litter.Sdump(opts))
createChan, err := c.CreateContainer(context.Background(), opts)
if err != nil {
close(ch)
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *Calcium) ListPodNodes(ctx context.Context, podname string, all bool) ([
var nodes []*types.Node
candidates, err := c.store.GetNodesByPod(ctx, podname)
if err != nil {
log.Debugf("[ListPodNodes] Error during ListPodNodes from %s: %v", podname, err)
log.Errorf("[ListPodNodes] Error during ListPodNodes from %s: %v", podname, err)
return nodes, err
}
for _, candidate := range candidates {
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (c *Calcium) ReplaceContainer(ctx context.Context, opts *types.ReplaceOptio

}
if opts.Podname != "" && container.Podname != opts.Podname {
log.Debugf("[ReplaceContainer] Skip not in pod container %s", container.ID)
log.Warnf("[ReplaceContainer] Skip not in pod container %s", container.ID)
c.doUnlock(containerLock, container.ID)
continue
}

log.Debugf("[ReplaceContainer] Replace old container %s", container.ID)
log.Infof("[ReplaceContainer] Replace old container %s", container.ID)
wg.Add(1)

go func(replaceOpts types.ReplaceOptions, container *types.Container, containerJSON enginetypes.ContainerJSON, containerLock lock.DistributedLock, index int) {
Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (c *Calcium) doAllocResource(ctx context.Context, opts *types.DeployOptions

switch podType {
case scheduler.MEMORY_PRIOR:
log.Debugf("[allocResource] Input opts.CPUQuota: %f", opts.CPUQuota)
nodesInfo, total, err = c.scheduler.SelectMemoryNodes(nodesInfo, opts.CPUQuota, opts.Memory) // 还是以 Bytes 作单位, 不转换了
case scheduler.CPU_PRIOR:
nodesInfo, nodeCPUPlans, total, err = c.scheduler.SelectCPUNodes(nodesInfo, opts.CPUQuota, opts.Memory)
Expand Down
4 changes: 2 additions & 2 deletions network/calico/titanium.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (t *Titanium) ConnectToNetwork(ctx context.Context, containerID, networkID,
config.IPAMConfig.IPv4Address = ip.String()
}

log.Debugf("[ConnectToNetwork] Connect %v to %v with IP %v", containerID, networkID, ipv4)
log.Infof("[ConnectToNetwork] Connect %v to %v with IP %v", containerID, networkID, ipv4)
return engine.NetworkConnect(ctx, networkID, containerID, config)
}

Expand All @@ -59,7 +59,7 @@ func (t *Titanium) DisconnectFromNetwork(ctx context.Context, containerID, netwo
fmt.Sprintf("Not actually a `engineapi.Client` for value engine in context"))
}

log.Debugf("[DisconnectFromNetwork] Disconnect %v from %v", containerID, networkID)
log.Infof("[DisconnectFromNetwork] Disconnect %v from %v", containerID, networkID)
return engine.NetworkDisconnect(ctx, networkID, containerID, false)
}

Expand Down
3 changes: 0 additions & 3 deletions scheduler/complex/potassium.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64,
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
log.Debugf("[SelectMemoryNodes] %d nodes has enough cpus", nodesInfoLength)

// 计算是否有足够的内存满足需求
sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].MemCap < nodesInfo[j].MemCap })
Expand All @@ -64,7 +63,6 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64,
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
log.Debugf("[SelectMemoryNodes] %d nodes has enough memory", nodesInfoLength)

// 这里 memCap 一定是大于 memory 的所以不用判断 cap 内容
volTotal := 0
Expand All @@ -73,7 +71,6 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64,
volTotal += capacity
nodesInfo[i].Capacity = capacity
}
log.Debugf("[SelectMemoryNodes] Node info: %v", nodesInfo)
return nodesInfo, volTotal, nil
}

Expand Down
12 changes: 4 additions & 8 deletions source/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (g *GitScm) SourceCode(repository, path, revision string, submodule bool) e
if err := repo.CheckoutTree(tree, &git.CheckoutOpts{Strategy: git.CheckoutSafe}); err != nil {
return err
}
log.Debugf("[SourceCode] Fetch repo %s", repository)
log.Debugf("[SourceCode] Checkout to commit %v", commit.Id())
log.Infof("[SourceCode] Fetch repo %s", repository)
log.Infof("[SourceCode] Checkout to commit %v", commit.Id())

// Prepare submodules
if submodule {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (g *GitScm) Artifact(artifact, path string) error {
req.Header.Add(k, v)
}

log.Debugf("[Artifact] Downloading artifacts from %q", artifact)
log.Infof("[Artifact] Downloading artifacts from %q", artifact)
resp, err := g.Do(req)
if err != nil {
return err
Expand All @@ -125,15 +125,11 @@ func (g *GitScm) Artifact(artifact, path string) error {
if resp.StatusCode != 200 {
return fmt.Errorf("Download artifact error %q, code %d", artifact, resp.StatusCode)
}
log.Debugf("[Artifact] Download artifacts from %q finished", artifact)

// extract files from zipfile
log.Debugf("[Artifact] Extracting files from %q", artifact)
if err := unzipFile(resp.Body, path); err != nil {
return err
}
log.Debugf("[Artifact] Extraction from %q done", artifact)

return nil
}

Expand Down Expand Up @@ -200,5 +196,5 @@ func gitcheck(repository, pubkey, prikey string) error {
}
return nil
}
return fmt.Errorf("No Support")
return types.ErrNotSupport
}
1 change: 0 additions & 1 deletion store/etcdv3/mercury.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func (m *Mercury) Watch(ctx context.Context, key string, opts ...clientv3.OpOpti

func (m *Mercury) parseKey(key string) string {
key = filepath.Join(m.config.Etcd.Prefix, key)
//log.Debugf("[parseKey] ops on %s", key)
return key
}

Expand Down
6 changes: 4 additions & 2 deletions store/etcdv3/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"strings"

"github.com/sanity-io/litter"

"github.com/projecteru2/core/store"

"github.com/coreos/etcd/clientv3"
Expand Down Expand Up @@ -159,7 +161,7 @@ func (m *Mercury) UpdateNode(ctx context.Context, node *types.Node) error {
}

value := string(bytes)
log.Debugf("[UpdateNode] new node info: %s", value)
log.Debugf("[UpdateNode] New node info: %s", litter.Sdump(node))
_, err = m.Put(ctx, key, value)
return err
}
Expand Down Expand Up @@ -298,7 +300,7 @@ func (m *Mercury) doDeleteNode(ctx context.Context, podname, nodename, endpoint

m.BatchDelete(ctx, keys)
_cache.Delete(nodename)
log.Debugf("[doDeleteNode] Node (%s, %s, %s) deleted", podname, nodename, endpoint)
log.Infof("[doDeleteNode] Node (%s, %s, %s) deleted", podname, nodename, endpoint)
}

func (m *Mercury) doGetNode(ctx context.Context, podname, nodename string) (*types.Node, error) {
Expand Down
2 changes: 2 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
ErrNoETCD = errors.New("ETCD must be set")
ErrKeyNotExists = errors.New("Key not exists")
ErrKeyExists = errors.New("Key exists")

ErrNotSupport = errors.New("Not Support")
)

// NewDetailedErr returns an error with details
Expand Down

0 comments on commit b9eb2c4

Please sign in to comment.