Skip to content

Commit

Permalink
Refactor VMStats usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jellonek committed Aug 22, 2018
1 parent d7d432c commit 24c2601
Showing 1 changed file with 28 additions and 42 deletions.
70 changes: 28 additions & 42 deletions pkg/manager/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,7 @@ func (v *VirtletRuntimeService) ContainerStats(ctx context.Context, in *kubeapi.
return nil, err
}
return &kubeapi.ContainerStatsResponse{
Stats: &kubeapi.ContainerStats{
Attributes: &kubeapi.ContainerAttributes{
Id: in.ContainerId,
},
Cpu: &kubeapi.CpuUsage{
Timestamp: vs.Timestamp,
UsageCoreNanoSeconds: &kubeapi.UInt64Value{Value: vs.CpuUsage},
},
Memory: &kubeapi.MemoryUsage{
Timestamp: vs.Timestamp,
WorkingSetBytes: &kubeapi.UInt64Value{Value: vs.MemoryUsage},
},
WritableLayer: &kubeapi.FilesystemUsage{
Timestamp: vs.Timestamp,
FsId: &kubeapi.FilesystemIdentifier{
Mountpoint: vs.Mountpoint,
},
UsedBytes: &kubeapi.UInt64Value{Value: vs.FsBytes},
InodesUsed: &kubeapi.UInt64Value{Value: vs.FsInodes},
},
},
Stats: VMStatsToCRIContainerStats(vs),
}, nil
}

Expand All @@ -498,34 +478,40 @@ func (v *VirtletRuntimeService) ListContainerStats(ctx context.Context, in *kube
}
var stats []*kubeapi.ContainerStats
for _, vs := range vmstatsList {
stats = append(stats, &kubeapi.ContainerStats{
Attributes: &kubeapi.ContainerAttributes{
Id: vs.ContainerID,
},
Cpu: &kubeapi.CpuUsage{
Timestamp: vs.Timestamp,
UsageCoreNanoSeconds: &kubeapi.UInt64Value{Value: vs.CpuUsage},
},
Memory: &kubeapi.MemoryUsage{
Timestamp: vs.Timestamp,
WorkingSetBytes: &kubeapi.UInt64Value{Value: vs.MemoryUsage},
},
WritableLayer: &kubeapi.FilesystemUsage{
Timestamp: vs.Timestamp,
FsId: &kubeapi.FilesystemIdentifier{
Mountpoint: vs.Mountpoint,
},
UsedBytes: &kubeapi.UInt64Value{Value: vs.FsBytes},
InodesUsed: &kubeapi.UInt64Value{Value: vs.FsInodes},
},
})
stats = append(stats, VMStatsToCRIContainerStats(vs))
}

return &kubeapi.ListContainerStatsResponse{
Stats: stats,
}, nil
}

// VMStatsToCRIContainerStats converts internal representation of vm/container stats
// to corresponding kubeapi type object
func VMStatsToCRIContainerStats(vs types.VMStats) *kubeapi.ContainerStats {
return &kubeapi.ContainerStats{
Attributes: &kubeapi.ContainerAttributes{
Id: vs.ContainerID,
},
Cpu: &kubeapi.CpuUsage{
Timestamp: vs.Timestamp,
UsageCoreNanoSeconds: &kubeapi.UInt64Value{Value: vs.CpuUsage},
},
Memory: &kubeapi.MemoryUsage{
Timestamp: vs.Timestamp,
WorkingSetBytes: &kubeapi.UInt64Value{Value: vs.MemoryUsage},
},
WritableLayer: &kubeapi.FilesystemUsage{
Timestamp: vs.Timestamp,
FsId: &kubeapi.FilesystemIdentifier{
Mountpoint: vs.Mountpoint,
},
UsedBytes: &kubeapi.UInt64Value{Value: vs.FsBytes},
InodesUsed: &kubeapi.UInt64Value{Value: vs.FsInodes},
},
}
}

// ReopenContainerLog is a placeholder for an unimplemented CRI method.
func (v *VirtletRuntimeService) ReopenContainerLog(ctx context.Context, in *kubeapi.ReopenContainerLogRequest) (*kubeapi.ReopenContainerLogResponse, error) {
return &kubeapi.ReopenContainerLogResponse{}, nil
Expand Down

0 comments on commit 24c2601

Please sign in to comment.