Merge pull request #7601 from kzys/cgroups-upgrade
Upgrade github.com/containerd/cgroups from v1 to v3
This commit is contained in:
@@ -24,19 +24,14 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
|
||||
v1 "github.com/containerd/cgroups/stats/v1"
|
||||
v2 "github.com/containerd/cgroups/v2/stats"
|
||||
v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
|
||||
v2 "github.com/containerd/cgroups/v3/cgroup2/stats"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/protobuf/proto"
|
||||
"github.com/containerd/typeurl"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// metricsCommand is only added on Linux as github.com/containerd/cgroups
|
||||
// does not compile on darwin or windows
|
||||
Command.Subcommands = append(Command.Subcommands, metricsCommand)
|
||||
}
|
||||
|
||||
const (
|
||||
formatFlag = "format"
|
||||
formatTable = "table"
|
||||
@@ -103,14 +98,9 @@ var metricsCommand = cli.Command{
|
||||
} else if data2 != nil {
|
||||
printCgroup2MetricsTable(w, data2)
|
||||
} else {
|
||||
if windowsStats.GetLinux() != nil {
|
||||
printCgroupMetricsTable(w, windowsStats.GetLinux())
|
||||
} else if windowsStats.GetWindows() != nil {
|
||||
printWindowsContainerStatistics(w, windowsStats.GetWindows())
|
||||
}
|
||||
// Print VM stats if its isolated
|
||||
if windowsStats.VM != nil {
|
||||
printWindowsVMStatistics(w, windowsStats.VM)
|
||||
err := printWindowsStats(w, windowsStats)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot convert metrics data from windows.Statistics: %w", err)
|
||||
}
|
||||
}
|
||||
return w.Flush()
|
||||
@@ -166,6 +156,34 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) {
|
||||
}
|
||||
}
|
||||
|
||||
func printWindowsStats(w *tabwriter.Writer, windowsStats *wstats.Statistics) error {
|
||||
if windowsStats.GetLinux() != nil {
|
||||
var stats v1.Metrics
|
||||
|
||||
// It cannot be casted to v1.Metrics since windowsStats is still generated by gogo/protobuf.
|
||||
linux := windowsStats.GetLinux()
|
||||
|
||||
// But Marshal/Unmarshal works because the underlying protobuf message is compatible.
|
||||
data, err := linux.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = proto.Unmarshal(data, &stats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printCgroupMetricsTable(w, &stats)
|
||||
} else if windowsStats.GetWindows() != nil {
|
||||
printWindowsContainerStatistics(w, windowsStats.GetWindows())
|
||||
}
|
||||
// Print VM stats if its isolated
|
||||
if windowsStats.VM != nil {
|
||||
printWindowsVMStatistics(w, windowsStats.VM)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printWindowsContainerStatistics(w *tabwriter.Writer, stats *wstats.WindowsContainerStatistics) {
|
||||
fmt.Fprintf(w, "METRIC\tVALUE\t\n")
|
||||
fmt.Fprintf(w, "timestamp\t%s\t\n", stats.Timestamp)
|
||||
|
@@ -38,6 +38,7 @@ var Command = cli.Command{
|
||||
execCommand,
|
||||
listCommand,
|
||||
killCommand,
|
||||
metricsCommand,
|
||||
pauseCommand,
|
||||
psCommand,
|
||||
resumeCommand,
|
||||
|
Reference in New Issue
Block a user