drivers: re-export ResourceUsage structs

Re-export the ResourceUsage structs in drivers package to avoid drivers
directly depending on the internal client/structs package directly.

I attempted moving the structs to drivers, but that caused some import
cycles that was a bit hard to disentagle.  Alternatively, I added an
alias here that's sufficient for our purposes of avoiding external
drivers depend on internal packages, while allowing us to restructure
packages in future without breaking source compatibility.
This commit is contained in:
Mahmood Ali 2019-01-07 10:01:46 -05:00 committed by Mahmood Ali
parent 916a40bb9e
commit 64f80343fc
19 changed files with 87 additions and 75 deletions

View File

@ -16,7 +16,6 @@ import (
"github.com/hashicorp/consul-template/signals"
hclog "github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/drivers/shared/eventer"
@ -1088,7 +1087,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return status, nil
}
func (d *Driver) TaskStats(taskID string) (*structs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
h, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -13,7 +13,6 @@ import (
docker "github.com/fsouza/go-dockerclient"
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/helper/stats"
"github.com/hashicorp/nomad/plugins/drivers"
@ -31,7 +30,7 @@ type taskHandle struct {
containerID string
containerImage string
resourceUsageLock sync.RWMutex
resourceUsage *cstructs.TaskResourceUsage
resourceUsage *drivers.TaskResourceUsage
doneCh chan bool
waitCh chan struct{}
removeContainerOnExit bool
@ -82,8 +81,8 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv
}
execResult := &drivers.ExecTaskResult{ExitResult: &drivers.ExitResult{}}
stdout, _ := circbuf.NewBuffer(int64(cstructs.CheckBufSize))
stderr, _ := circbuf.NewBuffer(int64(cstructs.CheckBufSize))
stdout, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))
stderr, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))
startOpts := docker.StartExecOptions{
Detach: false,
Tty: false,
@ -161,7 +160,7 @@ func (h *taskHandle) Kill(killTimeout time.Duration, signal os.Signal) error {
return nil
}
func (h *taskHandle) Stats() (*cstructs.TaskResourceUsage, error) {
func (h *taskHandle) Stats() (*drivers.TaskResourceUsage, error) {
h.resourceUsageLock.RLock()
defer h.resourceUsageLock.RUnlock()
var err error
@ -241,7 +240,7 @@ func (h *taskHandle) collectStats() {
select {
case s := <-statsCh:
if s != nil {
ms := &cstructs.MemoryStats{
ms := &drivers.MemoryStats{
RSS: s.MemoryStats.Stats.Rss,
Cache: s.MemoryStats.Stats.Cache,
Swap: s.MemoryStats.Stats.Swap,
@ -249,7 +248,7 @@ func (h *taskHandle) collectStats() {
Measured: DockerMeasuredMemStats,
}
cs := &cstructs.CpuStats{
cs := &drivers.CpuStats{
ThrottledPeriods: s.CPUStats.ThrottlingData.ThrottledPeriods,
ThrottledTime: s.CPUStats.ThrottlingData.ThrottledTime,
Measured: DockerMeasuredCpuStats,
@ -268,8 +267,8 @@ func (h *taskHandle) collectStats() {
cs.TotalTicks = (cs.Percent / 100) * stats.TotalTicksAvailable() / float64(numCores)
h.resourceUsageLock.Lock()
h.resourceUsage = &cstructs.TaskResourceUsage{
ResourceUsage: &cstructs.ResourceUsage{
h.resourceUsage = &drivers.TaskResourceUsage{
ResourceUsage: &drivers.ResourceUsage{
MemoryStats: ms,
CpuStats: cs,
},

View File

@ -12,7 +12,6 @@ import (
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/client/fingerprint"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/base"
@ -435,7 +434,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -13,7 +13,6 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/client/fingerprint"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/base"
@ -497,7 +496,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -10,7 +10,6 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/stats"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
@ -492,7 +491,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -11,7 +11,6 @@ import (
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/stats"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/plugins/drivers"
lxc "gopkg.in/lxc/go-lxc.v2"
)
@ -87,7 +86,7 @@ func (h *taskHandle) run() {
// TODO: detect if the task OOMed
}
func (h *taskHandle) stats() (*cstructs.TaskResourceUsage, error) {
func (h *taskHandle) stats() (*drivers.TaskResourceUsage, error) {
cpuStats, err := h.container.CPUStats()
if err != nil {
h.logger.Error("failed to get container cpu stats", "error", err)
@ -104,7 +103,7 @@ func (h *taskHandle) stats() (*cstructs.TaskResourceUsage, error) {
// Get the cpu stats
system := cpuStats["system"]
user := cpuStats["user"]
cs := &cstructs.CpuStats{
cs := &drivers.CpuStats{
SystemMode: h.systemCpuStats.Percent(float64(system)),
UserMode: h.systemCpuStats.Percent(float64(user)),
Percent: h.totalCpuStats.Percent(float64(total)),
@ -130,7 +129,7 @@ func (h *taskHandle) stats() (*cstructs.TaskResourceUsage, error) {
}
}
ms := &cstructs.MemoryStats{
ms := &drivers.MemoryStats{
RSS: memData["rss"],
Cache: memData["cache"],
Swap: memData["swap"],
@ -166,8 +165,8 @@ func (h *taskHandle) stats() (*cstructs.TaskResourceUsage, error) {
ms.KernelMaxUsage = val
}
taskResUsage := cstructs.TaskResourceUsage{
ResourceUsage: &cstructs.ResourceUsage{
taskResUsage := drivers.TaskResourceUsage{
ResourceUsage: &drivers.ResourceUsage{
CpuStats: cs,
MemoryStats: ms,
},

View File

@ -11,7 +11,6 @@ import (
"time"
hclog "github.com/hashicorp/go-hclog"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base"
@ -495,11 +494,11 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
panic("not implemented")
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
// Generate random value for the memory usage
s := &cstructs.TaskResourceUsage{
ResourceUsage: &cstructs.ResourceUsage{
MemoryStats: &cstructs.MemoryStats{
s := &drivers.TaskResourceUsage{
ResourceUsage: &drivers.ResourceUsage{
MemoryStats: &drivers.MemoryStats{
RSS: rand.Uint64(),
Measured: []string{"RSS"},
},

View File

@ -16,7 +16,6 @@ import (
"github.com/coreos/go-semver/semver"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/base"
@ -547,7 +546,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -13,7 +13,6 @@ import (
"github.com/hashicorp/consul-template/signals"
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/base"
@ -457,7 +456,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -26,7 +26,6 @@ import (
plugin "github.com/hashicorp/go-plugin"
version "github.com/hashicorp/go-version"
"github.com/hashicorp/nomad/client/config"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/executor"
@ -819,7 +818,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *Driver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound

View File

@ -9,7 +9,6 @@ import (
"github.com/LK4D4/joincontext"
"github.com/golang/protobuf/ptypes"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/executor/proto"
"github.com/hashicorp/nomad/plugins/drivers"
)
@ -100,7 +99,7 @@ func (c *grpcExecutorClient) Version() (*ExecutorVersion, error) {
return &ExecutorVersion{Version: resp.Version}, nil
}
func (c *grpcExecutorClient) Stats() (*cstructs.TaskResourceUsage, error) {
func (c *grpcExecutorClient) Stats() (*drivers.TaskResourceUsage, error) {
ctx := context.Background()
resp, err := c.client.Stats(ctx, &proto.StatsRequest{})
if err != nil {

View File

@ -22,7 +22,6 @@ import (
"github.com/hashicorp/nomad/client/stats"
"github.com/hashicorp/nomad/plugins/drivers"
cstructs "github.com/hashicorp/nomad/client/structs"
shelpers "github.com/hashicorp/nomad/helper/stats"
)
@ -68,7 +67,7 @@ type Executor interface {
Version() (*ExecutorVersion, error)
// Stats fetchs process usage stats for the executor and each pid if available
Stats() (*cstructs.TaskResourceUsage, error)
Stats() (*drivers.TaskResourceUsage, error)
// Signal sends the given signal to the user process
Signal(os.Signal) error
@ -332,7 +331,7 @@ func ExecScript(ctx context.Context, dir string, env []string, attrs *syscall.Sy
cmd.Env = env
// Capture output
buf, _ := circbuf.NewBuffer(int64(cstructs.CheckBufSize))
buf, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))
cmd.Stdout = buf
cmd.Stderr = buf
@ -507,7 +506,7 @@ func (e *UniversalExecutor) Signal(s os.Signal) error {
return nil
}
func (e *UniversalExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
func (e *UniversalExecutor) Stats() (*drivers.TaskResourceUsage, error) {
pidStats, err := e.pidCollector.pidStats()
if err != nil {
return nil, err

View File

@ -18,7 +18,6 @@ import (
hclog "github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/client/stats"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper/discover"
shelpers "github.com/hashicorp/nomad/helper/stats"
"github.com/hashicorp/nomad/helper/uuid"
@ -355,7 +354,7 @@ func (l *LibcontainerExecutor) Version() (*ExecutorVersion, error) {
}
// Stats returns the resource statistics for processes managed by the executor
func (l *LibcontainerExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
func (l *LibcontainerExecutor) Stats() (*drivers.TaskResourceUsage, error) {
lstats, err := l.container.Stats()
if err != nil {
return nil, err
@ -374,7 +373,7 @@ func (l *LibcontainerExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
maxUsage := stats.MemoryStats.Usage.MaxUsage
rss := stats.MemoryStats.Stats["rss"]
cache := stats.MemoryStats.Stats["cache"]
ms := &cstructs.MemoryStats{
ms := &drivers.MemoryStats{
RSS: rss,
Cache: cache,
Swap: swap.Usage,
@ -390,7 +389,7 @@ func (l *LibcontainerExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
kernelModeTime := float64(stats.CpuStats.CpuUsage.UsageInKernelmode)
totalPercent := l.totalCpuStats.Percent(totalProcessCPUUsage)
cs := &cstructs.CpuStats{
cs := &drivers.CpuStats{
SystemMode: l.systemCpuStats.Percent(kernelModeTime),
UserMode: l.userCpuStats.Percent(userModeTime),
Percent: totalPercent,
@ -399,8 +398,8 @@ func (l *LibcontainerExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
TotalTicks: l.systemCpuStats.TicksConsumed(totalPercent),
Measured: ExecutorCgroupMeasuredCpuStats,
}
taskResUsage := cstructs.TaskResourceUsage{
ResourceUsage: &cstructs.ResourceUsage{
taskResUsage := drivers.TaskResourceUsage{
ResourceUsage: &drivers.ResourceUsage{
MemoryStats: ms,
CpuStats: cs,
},
@ -420,7 +419,7 @@ func (l *LibcontainerExecutor) Signal(s os.Signal) error {
func (l *LibcontainerExecutor) Exec(deadline time.Time, cmd string, args []string) ([]byte, int, error) {
combined := append([]string{cmd}, args...)
// Capture output
buf, _ := circbuf.NewBuffer(int64(cstructs.CheckBufSize))
buf, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))
process := &libcontainer.Process{
Args: combined,

View File

@ -8,7 +8,7 @@ import (
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/stats"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/plugins/drivers"
ps "github.com/mitchellh/go-ps"
"github.com/shirou/gopsutil/process"
)
@ -131,8 +131,8 @@ func scanPids(parentPid int, allPids []ps.Process) (map[int]*nomadPid, error) {
}
// pidStats returns the resource usage stats per pid
func (c *pidCollector) pidStats() (map[string]*cstructs.ResourceUsage, error) {
stats := make(map[string]*cstructs.ResourceUsage)
func (c *pidCollector) pidStats() (map[string]*drivers.ResourceUsage, error) {
stats := make(map[string]*drivers.ResourceUsage)
c.pidLock.RLock()
pids := make(map[int]*nomadPid, len(c.pids))
for k, v := range c.pids {
@ -145,14 +145,14 @@ func (c *pidCollector) pidStats() (map[string]*cstructs.ResourceUsage, error) {
c.logger.Trace("unable to create new process", "pid", pid, "error", err)
continue
}
ms := &cstructs.MemoryStats{}
ms := &drivers.MemoryStats{}
if memInfo, err := p.MemoryInfo(); err == nil {
ms.RSS = memInfo.RSS
ms.Swap = memInfo.Swap
ms.Measured = ExecutorBasicMeasuredMemStats
}
cs := &cstructs.CpuStats{}
cs := &drivers.CpuStats{}
if cpuStats, err := p.Times(); err == nil {
cs.SystemMode = np.cpuStatsSys.Percent(cpuStats.System * float64(time.Second))
cs.UserMode = np.cpuStatsUser.Percent(cpuStats.User * float64(time.Second))
@ -161,7 +161,7 @@ func (c *pidCollector) pidStats() (map[string]*cstructs.ResourceUsage, error) {
// calculate cpu usage percent
cs.Percent = np.cpuStatsTotal.Percent(cpuStats.Total() * float64(time.Second))
}
stats[strconv.Itoa(pid)] = &cstructs.ResourceUsage{MemoryStats: ms, CpuStats: cs}
stats[strconv.Itoa(pid)] = &drivers.ResourceUsage{MemoryStats: ms, CpuStats: cs}
}
return stats, nil
@ -169,7 +169,7 @@ func (c *pidCollector) pidStats() (map[string]*cstructs.ResourceUsage, error) {
// aggregatedResourceUsage aggregates the resource usage of all the pids and
// returns a TaskResourceUsage data point
func aggregatedResourceUsage(systemCpuStats *stats.CpuStats, pidStats map[string]*cstructs.ResourceUsage) *cstructs.TaskResourceUsage {
func aggregatedResourceUsage(systemCpuStats *stats.CpuStats, pidStats map[string]*drivers.ResourceUsage) *drivers.TaskResourceUsage {
ts := time.Now().UTC().UnixNano()
var (
systemModeCPU, userModeCPU, percent float64
@ -185,7 +185,7 @@ func aggregatedResourceUsage(systemCpuStats *stats.CpuStats, pidStats map[string
totalSwap += pidStat.MemoryStats.Swap
}
totalCPU := &cstructs.CpuStats{
totalCPU := &drivers.CpuStats{
SystemMode: systemModeCPU,
UserMode: userModeCPU,
Percent: percent,
@ -193,17 +193,17 @@ func aggregatedResourceUsage(systemCpuStats *stats.CpuStats, pidStats map[string
TotalTicks: systemCpuStats.TicksConsumed(percent),
}
totalMemory := &cstructs.MemoryStats{
totalMemory := &drivers.MemoryStats{
RSS: totalRSS,
Swap: totalSwap,
Measured: ExecutorBasicMeasuredMemStats,
}
resourceUsage := cstructs.ResourceUsage{
resourceUsage := drivers.ResourceUsage{
MemoryStats: totalMemory,
CpuStats: totalCPU,
}
return &cstructs.TaskResourceUsage{
return &drivers.TaskResourceUsage{
ResourceUsage: &resourceUsage,
Timestamp: ts,
Pids: pidStats,

View File

@ -8,7 +8,6 @@ import (
"github.com/LK4D4/joincontext"
"github.com/golang/protobuf/ptypes"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers/proto"
@ -253,7 +252,7 @@ func (d *driverPluginClient) InspectTask(taskID string) (*TaskStatus, error) {
}
// TaskStats returns resource usage statistics for the task
func (d *driverPluginClient) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *driverPluginClient) TaskStats(taskID string) (*TaskResourceUsage, error) {
req := &proto.TaskStatsRequest{TaskId: taskID}
resp, err := d.client.TaskStats(d.doneCtx, req)

View File

@ -0,0 +1,29 @@
package drivers
import (
cstructs "github.com/hashicorp/nomad/client/structs"
)
// This files present an indirection layer to client structs used by drivers,
// and represent the public interface for drivers, as client interfaces are
// internal and subject to change.
// MemoryStats holds memory usage related stats
type MemoryStats = cstructs.MemoryStats
// CpuStats holds cpu usage related stats
type CpuStats = cstructs.CpuStats
// ResourceUsage holds information related to cpu and memory stats
type ResourceUsage = cstructs.ResourceUsage
// TaskResourceUsage holds aggregated resource usage of all processes in a Task
// and the resource usage of the individual pids
type TaskResourceUsage = cstructs.TaskResourceUsage
// CheckBufSize is the size of the buffer that is used for job output
const CheckBufSize = cstructs.CheckBufSize
// DriverStatsNotImplemented is the error to be returned if a driver doesn't
// implement stats.
var DriverStatsNotImplemented = cstructs.DriverStatsNotImplemented

View File

@ -11,7 +11,6 @@ import (
"time"
"github.com/hashicorp/nomad/client/allocdir"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base"
@ -40,7 +39,7 @@ type DriverPlugin interface {
StopTask(taskID string, timeout time.Duration, signal string) error
DestroyTask(taskID string, force bool) error
InspectTask(taskID string) (*TaskStatus, error)
TaskStats(taskID string) (*cstructs.TaskResourceUsage, error)
TaskStats(taskID string) (*TaskResourceUsage, error)
TaskEvents(context.Context) (<-chan *TaskEvent, error)
SignalTask(taskID string, signal string) error

View File

@ -13,7 +13,6 @@ import (
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/logmon"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
@ -199,7 +198,7 @@ type MockDriver struct {
StopTaskF func(string, time.Duration, string) error
DestroyTaskF func(string, bool) error
InspectTaskF func(string) (*drivers.TaskStatus, error)
TaskStatsF func(string) (*cstructs.TaskResourceUsage, error)
TaskStatsF func(string) (*drivers.TaskResourceUsage, error)
TaskEventsF func(context.Context) (<-chan *drivers.TaskEvent, error)
SignalTaskF func(string, string) error
ExecTaskF func(string, []string, time.Duration) (*drivers.ExecTaskResult, error)
@ -226,7 +225,7 @@ func (d *MockDriver) DestroyTask(taskID string, force bool) error {
func (d *MockDriver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return d.InspectTaskF(taskID)
}
func (d *MockDriver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
func (d *MockDriver) TaskStats(taskID string) (*drivers.TaskResourceUsage, error) {
return d.TaskStats(taskID)
}
func (d *MockDriver) TaskEvents(ctx context.Context) (<-chan *drivers.TaskEvent, error) {

View File

@ -4,7 +4,6 @@ import (
"time"
"github.com/golang/protobuf/ptypes"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/drivers/proto"
)
@ -381,7 +380,7 @@ func taskStatusFromProto(pb *proto.TaskStatus) (*TaskStatus, error) {
}, nil
}
func TaskStatsToProto(stats *cstructs.TaskResourceUsage) (*proto.TaskStats, error) {
func TaskStatsToProto(stats *TaskResourceUsage) (*proto.TaskStats, error) {
timestamp, err := ptypes.TimestampProto(time.Unix(0, stats.Timestamp))
if err != nil {
return nil, err
@ -399,18 +398,18 @@ func TaskStatsToProto(stats *cstructs.TaskResourceUsage) (*proto.TaskStats, erro
}, nil
}
func TaskStatsFromProto(pb *proto.TaskStats) (*cstructs.TaskResourceUsage, error) {
func TaskStatsFromProto(pb *proto.TaskStats) (*TaskResourceUsage, error) {
timestamp, err := ptypes.Timestamp(pb.Timestamp)
if err != nil {
return nil, err
}
pids := map[string]*cstructs.ResourceUsage{}
pids := map[string]*ResourceUsage{}
for pid, ru := range pb.ResourceUsageByPid {
pids[pid] = resourceUsageFromProto(ru)
}
stats := &cstructs.TaskResourceUsage{
stats := &TaskResourceUsage{
Timestamp: timestamp.Unix(),
ResourceUsage: resourceUsageFromProto(pb.AggResourceUsage),
Pids: pids,
@ -419,7 +418,7 @@ func TaskStatsFromProto(pb *proto.TaskStats) (*cstructs.TaskResourceUsage, error
return stats, nil
}
func resourceUsageToProto(ru *cstructs.ResourceUsage) *proto.TaskResourceUsage {
func resourceUsageToProto(ru *ResourceUsage) *proto.TaskResourceUsage {
cpu := &proto.CPUUsage{}
for _, field := range ru.CpuStats.Measured {
switch field {
@ -471,8 +470,8 @@ func resourceUsageToProto(ru *cstructs.ResourceUsage) *proto.TaskResourceUsage {
}
}
func resourceUsageFromProto(pb *proto.TaskResourceUsage) *cstructs.ResourceUsage {
cpu := cstructs.CpuStats{}
func resourceUsageFromProto(pb *proto.TaskResourceUsage) *ResourceUsage {
cpu := CpuStats{}
if pb.Cpu != nil {
for _, field := range pb.Cpu.MeasuredFields {
switch field {
@ -498,7 +497,7 @@ func resourceUsageFromProto(pb *proto.TaskResourceUsage) *cstructs.ResourceUsage
}
}
memory := cstructs.MemoryStats{}
memory := MemoryStats{}
if pb.Memory != nil {
for _, field := range pb.Memory.MeasuredFields {
switch field {
@ -521,7 +520,7 @@ func resourceUsageFromProto(pb *proto.TaskResourceUsage) *cstructs.ResourceUsage
}
}
return &cstructs.ResourceUsage{
return &ResourceUsage{
CpuStats: &cpu,
MemoryStats: &memory,
}