Skip to content

Commit

Permalink
fix: add more events
Browse files Browse the repository at this point in the history
Signed-off-by: zhangyue <zy675793960@yeah.net>
  • Loading branch information
zhangyue committed Jun 29, 2019
1 parent 7ff4bc0 commit 2ef0aea
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ func (mgr *ContainerManager) Restart(ctx context.Context, name string, timeout i
c.RestartCount++

logrus.Debugf("container %s restartCount is %d", c.ID, c.RestartCount)
mgr.LogContainerEvent(ctx, c, "restart")

return c.Write(mgr.Store)
}

Expand Down Expand Up @@ -1445,6 +1447,7 @@ func (mgr *ContainerManager) Top(ctx context.Context, name string, psArgs string
if err != nil {
return nil, errors.Wrapf(err, "failed parsePSOutput")
}
mgr.LogContainerEvent(ctx, c, "top")

return procList, nil
}
Expand All @@ -1463,6 +1466,7 @@ func (mgr *ContainerManager) Resize(ctx context.Context, name string, opts types
return fmt.Errorf("failed to resize container %s: container is not running", c.ID)
}

mgr.LogContainerEvent(ctx, c, "resize")
return mgr.Client.ResizeContainer(ctx, c.ID, opts)
}

Expand Down
1 change: 1 addition & 0 deletions daemon/mgr/container_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (mgr *ContainerManager) Commit(ctx context.Context, name string, options *t
// pouch can see the new image reference.
logrus.Warnf("failed to update image store: %s", err)
}
mgr.LogContainerEvent(ctx, c, "commit")

// return 12 bits image id as a result
imageID := imageDigest.Hex()
Expand Down
3 changes: 3 additions & 0 deletions daemon/mgr/container_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (mgr *ContainerManager) ArchivePath(ctx context.Context, name, path string)
c.Unlock()
return err
})
mgr.LogContainerEvent(ctx, c, "archive-path")

return content, stat, nil
}
Expand Down Expand Up @@ -224,6 +225,8 @@ func (mgr *ContainerManager) ExtractToDir(ctx context.Context, name, path string
NoOverwriteDirNonDir: noOverwriteDirNonDir,
}

mgr.LogContainerEvent(ctx, c, "extract-to-dir")

return chrootarchive.Untar(content, resolvedPath, opts)
}

Expand Down
3 changes: 2 additions & 1 deletion daemon/mgr/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (mgr *ContainerManager) CreateExec(ctx context.Context, name string, config
}

mgr.ExecProcesses.Put(execid, execConfig)

mgr.LogContainerEvent(ctx, c, "exec_create")
return execid, nil
}

Expand Down Expand Up @@ -164,6 +164,7 @@ func (mgr *ContainerManager) StartExec(ctx context.Context, execid string, cfg *
}); err != nil {
return err
}
mgr.LogContainerEvent(ctx, c, "exec_start")
return <-attachErrCh
}

Expand Down
7 changes: 4 additions & 3 deletions daemon/mgr/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (mgr *ImageManager) PushImage(ctx context.Context, name, tag string, authCo
} else {
ref = reference.WithTag(ref, tag)
}

mgr.LogImageEvent(ctx, ref.String(), ref.String(), "push")
return mgr.client.PushImage(ctx, ref.String(), authConfig, out)
}

Expand Down Expand Up @@ -458,7 +458,7 @@ func (mgr *ImageManager) RemoveImage(ctx context.Context, idOrRef string, force
// the searchable reference has different locator without force.
// It's different reference from locator aspect.
if !force && !uniqueLocatorReference(mgr.localStore.GetReferences(id)) {
return fmt.Errorf("Unable to remove the image %q (must force) - image has serveral references", idOrRef)
return fmt.Errorf("unable to remove the image %q (must force) - image has serveral references", idOrRef)
}

for _, ref := range mgr.localStore.GetPrimaryReferences(id) {
Expand All @@ -479,7 +479,7 @@ func (mgr *ImageManager) RemoveImage(ctx context.Context, idOrRef string, force
if err := mgr.localStore.RemoveReference(id, primaryRef); err != nil {
return err
}

mgr.LogImageEvent(ctx, namedRef.String(), namedRef.String(), "delete")
return mgr.client.RemoveImage(ctx, primaryRef.String())
}

Expand Down Expand Up @@ -530,6 +530,7 @@ func (mgr *ImageManager) AddTag(ctx context.Context, sourceImage string, targetT
Name: tagRef.String(),
Target: ctrdImg.Target(),
})
mgr.LogImageEvent(ctx, sourceImage, tagRef.String(), "tag")
return err
}

Expand Down
1 change: 1 addition & 0 deletions daemon/mgr/image_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ func (mgr *ImageManager) LoadImage(ctx context.Context, imageName string, tarstr
if merrs.Size() != 0 {
return fmt.Errorf("fails to load image: %v", merrs.Error())
}
mgr.LogImageEvent(ctx, imageName, imageName, "load")
return nil
}
1 change: 1 addition & 0 deletions daemon/mgr/image_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (mgr *ImageManager) SaveImage(ctx context.Context, idOrRef string) (io.Read
if err != nil {
return nil, err
}
mgr.LogImageEvent(ctx, idOrRef, ref.String(), "save")

return exportedStream, nil
}
3 changes: 2 additions & 1 deletion daemon/mgr/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (vm *VolumeManager) Attach(ctx context.Context, name string, options map[st
}
}

vm.LogVolumeEvent(ctx, name, "attach", map[string]string{"driver": v.Driver()})
return vm.core.AttachVolume(id, options)
}

Expand Down Expand Up @@ -220,6 +221,6 @@ func (vm *VolumeManager) Detach(ctx context.Context, name string, options map[st
}
}
}

vm.LogVolumeEvent(ctx, name, "detach", map[string]string{"driver": v.Driver()})
return vm.core.DetachVolume(id, options)
}

0 comments on commit 2ef0aea

Please sign in to comment.