Update dependencies after protobuf update in hcsshim

Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
(cherry picked from commit d129b6f890bceb56b050bbb23ad330bb5699f78c)
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
This commit is contained in:
Kirtana Ashok 2023-08-08 14:58:07 -07:00
parent e7e5619fed
commit a645ff2e68
7 changed files with 17 additions and 27 deletions

View File

@ -27,7 +27,6 @@ import (
v1 "github.com/containerd/cgroups/v3/cgroup1/stats" v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
v2 "github.com/containerd/cgroups/v3/cgroup2/stats" v2 "github.com/containerd/cgroups/v3/cgroup2/stats"
"github.com/containerd/containerd/cmd/ctr/commands" "github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/protobuf/proto"
"github.com/containerd/typeurl/v2" "github.com/containerd/typeurl/v2"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -154,22 +153,8 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) {
func printWindowsStats(w *tabwriter.Writer, windowsStats *wstats.Statistics) error { func printWindowsStats(w *tabwriter.Writer, windowsStats *wstats.Statistics) error {
if windowsStats.GetLinux() != nil { if windowsStats.GetLinux() != nil {
var stats v1.Metrics stats := windowsStats.GetLinux()
printCgroupMetricsTable(w, stats)
// 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 { } else if windowsStats.GetWindows() != nil {
printWindowsContainerStatistics(w, windowsStats.GetWindows()) printWindowsContainerStatistics(w, windowsStats.GetWindows())
} }

View File

@ -303,13 +303,13 @@ func (c *criService) windowsContainerMetrics(
} }
if wstats.Processor != nil { if wstats.Processor != nil {
cs.Cpu = &runtime.CpuUsage{ cs.Cpu = &runtime.CpuUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS}, UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
} }
} }
if wstats.Memory != nil { if wstats.Memory != nil {
cs.Memory = &runtime.MemoryUsage{ cs.Memory = &runtime.MemoryUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
WorkingSetBytes: &runtime.UInt64Value{ WorkingSetBytes: &runtime.UInt64Value{
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes, Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
}, },

View File

@ -31,6 +31,7 @@ import (
containerstore "github.com/containerd/containerd/pkg/cri/store/container" containerstore "github.com/containerd/containerd/pkg/cri/store/container"
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
"github.com/containerd/containerd/pkg/cri/store/stats" "github.com/containerd/containerd/pkg/cri/store/stats"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/typeurl/v2" "github.com/containerd/typeurl/v2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
) )
@ -282,14 +283,14 @@ func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.Windo
} }
if wstats.Processor != nil { if wstats.Processor != nil {
cs.Cpu = &runtime.WindowsCpuUsage{ cs.Cpu = &runtime.WindowsCpuUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS}, UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
} }
} }
if wstats.Memory != nil { if wstats.Memory != nil {
cs.Memory = &runtime.WindowsMemoryUsage{ cs.Memory = &runtime.WindowsMemoryUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
WorkingSetBytes: &runtime.UInt64Value{ WorkingSetBytes: &runtime.UInt64Value{
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes, Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
}, },

View File

@ -24,6 +24,7 @@ import (
containerstore "github.com/containerd/containerd/pkg/cri/store/container" containerstore "github.com/containerd/containerd/pkg/cri/store/container"
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
"github.com/containerd/containerd/pkg/cri/store/stats" "github.com/containerd/containerd/pkg/cri/store/stats"
"github.com/containerd/containerd/protobuf"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
) )
@ -384,7 +385,7 @@ func sandboxPod(id string, timestamp time.Time, cachedCPU uint64) sandboxstore.S
func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows { func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows {
return &wstats.Statistics_Windows{ return &wstats.Statistics_Windows{
Windows: &wstats.WindowsContainerStatistics{ Windows: &wstats.WindowsContainerStatistics{
Timestamp: timestamp, Timestamp: protobuf.ToTimestamp(timestamp),
Processor: &wstats.WindowsContainerProcessorStatistics{ Processor: &wstats.WindowsContainerProcessorStatistics{
TotalRuntimeNS: cpu, TotalRuntimeNS: cpu,
}, },

View File

@ -22,6 +22,7 @@ import (
wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats" wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
"github.com/containerd/containerd/api/types" "github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/typeurl/v2" "github.com/containerd/typeurl/v2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -67,13 +68,13 @@ func (c *criService) containerMetrics(
} }
if wstats.Processor != nil { if wstats.Processor != nil {
cs.Cpu = &runtime.CpuUsage{ cs.Cpu = &runtime.CpuUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS}, UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
} }
} }
if wstats.Memory != nil { if wstats.Memory != nil {
cs.Memory = &runtime.MemoryUsage{ cs.Memory = &runtime.MemoryUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
WorkingSetBytes: &runtime.UInt64Value{ WorkingSetBytes: &runtime.UInt64Value{
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes, Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
}, },

View File

@ -31,6 +31,7 @@ import (
containerstore "github.com/containerd/containerd/pkg/cri/store/container" containerstore "github.com/containerd/containerd/pkg/cri/store/container"
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
"github.com/containerd/containerd/pkg/cri/store/stats" "github.com/containerd/containerd/pkg/cri/store/stats"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/typeurl/v2" "github.com/containerd/typeurl/v2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
) )
@ -282,14 +283,14 @@ func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.Windo
} }
if wstats.Processor != nil { if wstats.Processor != nil {
cs.Cpu = &runtime.WindowsCpuUsage{ cs.Cpu = &runtime.WindowsCpuUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS}, UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
} }
} }
if wstats.Memory != nil { if wstats.Memory != nil {
cs.Memory = &runtime.WindowsMemoryUsage{ cs.Memory = &runtime.WindowsMemoryUsage{
Timestamp: wstats.Timestamp.UnixNano(), Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
WorkingSetBytes: &runtime.UInt64Value{ WorkingSetBytes: &runtime.UInt64Value{
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes, Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
}, },

View File

@ -24,6 +24,7 @@ import (
containerstore "github.com/containerd/containerd/pkg/cri/store/container" containerstore "github.com/containerd/containerd/pkg/cri/store/container"
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
"github.com/containerd/containerd/pkg/cri/store/stats" "github.com/containerd/containerd/pkg/cri/store/stats"
"github.com/containerd/containerd/protobuf"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
) )
@ -384,7 +385,7 @@ func sandboxPod(id string, timestamp time.Time, cachedCPU uint64) sandboxstore.S
func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows { func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows {
return &wstats.Statistics_Windows{ return &wstats.Statistics_Windows{
Windows: &wstats.WindowsContainerStatistics{ Windows: &wstats.WindowsContainerStatistics{
Timestamp: timestamp, Timestamp: protobuf.ToTimestamp(timestamp),
Processor: &wstats.WindowsContainerProcessorStatistics{ Processor: &wstats.WindowsContainerProcessorStatistics{
TotalRuntimeNS: cpu, TotalRuntimeNS: cpu,
}, },