Skip to content

Commit d129b6f

Browse files
committed
Update dependencies after protobuf update in hcsshim
Signed-off-by: Kirtana Ashok <[email protected]>
1 parent 67ca9cc commit d129b6f

7 files changed

Lines changed: 17 additions & 27 deletions

File tree

cmd/ctr/commands/tasks/metrics.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
2828
v2 "github.com/containerd/cgroups/v3/cgroup2/stats"
2929
"github.com/containerd/containerd/cmd/ctr/commands"
30-
"github.com/containerd/containerd/protobuf/proto"
3130
"github.com/containerd/typeurl/v2"
3231
"github.com/urfave/cli"
3332
)
@@ -154,22 +153,8 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) {
154153

155154
func printWindowsStats(w *tabwriter.Writer, windowsStats *wstats.Statistics) error {
156155
if windowsStats.GetLinux() != nil {
157-
var stats v1.Metrics
158-
159-
// It cannot be casted to v1.Metrics since windowsStats is still generated by gogo/protobuf.
160-
linux := windowsStats.GetLinux()
161-
162-
// But Marshal/Unmarshal works because the underlying protobuf message is compatible.
163-
data, err := linux.Marshal()
164-
if err != nil {
165-
return err
166-
}
167-
err = proto.Unmarshal(data, &stats)
168-
if err != nil {
169-
return err
170-
}
171-
172-
printCgroupMetricsTable(w, &stats)
156+
stats := windowsStats.GetLinux()
157+
printCgroupMetricsTable(w, stats)
173158
} else if windowsStats.GetWindows() != nil {
174159
printWindowsContainerStatistics(w, windowsStats.GetWindows())
175160
}

pkg/cri/sbserver/container_stats_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,13 @@ func (c *criService) windowsContainerMetrics(
294294
}
295295
if wstats.Processor != nil {
296296
cs.Cpu = &runtime.CpuUsage{
297-
Timestamp: wstats.Timestamp.UnixNano(),
297+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
298298
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
299299
}
300300
}
301301
if wstats.Memory != nil {
302302
cs.Memory = &runtime.MemoryUsage{
303-
Timestamp: wstats.Timestamp.UnixNano(),
303+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
304304
WorkingSetBytes: &runtime.UInt64Value{
305305
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
306306
},

pkg/cri/sbserver/sandbox_stats_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
3131
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
3232
"github.com/containerd/containerd/pkg/cri/store/stats"
33+
"github.com/containerd/containerd/protobuf"
3334
"github.com/containerd/typeurl/v2"
3435
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
3536
)
@@ -281,14 +282,14 @@ func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.Windo
281282
}
282283
if wstats.Processor != nil {
283284
cs.Cpu = &runtime.WindowsCpuUsage{
284-
Timestamp: wstats.Timestamp.UnixNano(),
285+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
285286
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
286287
}
287288
}
288289

289290
if wstats.Memory != nil {
290291
cs.Memory = &runtime.WindowsMemoryUsage{
291-
Timestamp: wstats.Timestamp.UnixNano(),
292+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
292293
WorkingSetBytes: &runtime.UInt64Value{
293294
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
294295
},

pkg/cri/sbserver/sandbox_stats_windows_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
2525
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
2626
"github.com/containerd/containerd/pkg/cri/store/stats"
27+
"github.com/containerd/containerd/protobuf"
2728
"github.com/stretchr/testify/assert"
2829
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2930
)
@@ -338,7 +339,7 @@ func sandboxPod(id string, timestamp time.Time, cachedCPU uint64) sandboxstore.S
338339
func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows {
339340
return &wstats.Statistics_Windows{
340341
Windows: &wstats.WindowsContainerStatistics{
341-
Timestamp: timestamp,
342+
Timestamp: protobuf.ToTimestamp(timestamp),
342343
Processor: &wstats.WindowsContainerProcessorStatistics{
343344
TotalRuntimeNS: cpu,
344345
},

pkg/cri/server/container_stats_list_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
2424
"github.com/containerd/containerd/api/types"
25+
"github.com/containerd/containerd/protobuf"
2526
"github.com/containerd/typeurl/v2"
2627
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2728

@@ -67,13 +68,13 @@ func (c *criService) containerMetrics(
6768
}
6869
if wstats.Processor != nil {
6970
cs.Cpu = &runtime.CpuUsage{
70-
Timestamp: wstats.Timestamp.UnixNano(),
71+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
7172
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
7273
}
7374
}
7475
if wstats.Memory != nil {
7576
cs.Memory = &runtime.MemoryUsage{
76-
Timestamp: wstats.Timestamp.UnixNano(),
77+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
7778
WorkingSetBytes: &runtime.UInt64Value{
7879
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
7980
},

pkg/cri/server/sandbox_stats_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
3131
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
3232
"github.com/containerd/containerd/pkg/cri/store/stats"
33+
"github.com/containerd/containerd/protobuf"
3334
"github.com/containerd/typeurl/v2"
3435
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
3536
)
@@ -279,14 +280,14 @@ func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.Windo
279280
}
280281
if wstats.Processor != nil {
281282
cs.Cpu = &runtime.WindowsCpuUsage{
282-
Timestamp: wstats.Timestamp.UnixNano(),
283+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
283284
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
284285
}
285286
}
286287

287288
if wstats.Memory != nil {
288289
cs.Memory = &runtime.WindowsMemoryUsage{
289-
Timestamp: wstats.Timestamp.UnixNano(),
290+
Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(),
290291
WorkingSetBytes: &runtime.UInt64Value{
291292
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
292293
},

pkg/cri/server/sandbox_stats_windows_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
2525
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
2626
"github.com/containerd/containerd/pkg/cri/store/stats"
27+
"github.com/containerd/containerd/protobuf"
2728
"github.com/stretchr/testify/assert"
2829
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2930
)
@@ -338,7 +339,7 @@ func sandboxPod(id string, timestamp time.Time, cachedCPU uint64) sandboxstore.S
338339
func windowsStat(timestamp time.Time, cpu uint64, memory uint64) *wstats.Statistics_Windows {
339340
return &wstats.Statistics_Windows{
340341
Windows: &wstats.WindowsContainerStatistics{
341-
Timestamp: timestamp,
342+
Timestamp: protobuf.ToTimestamp(timestamp),
342343
Processor: &wstats.WindowsContainerProcessorStatistics{
343344
TotalRuntimeNS: cpu,
344345
},

0 commit comments

Comments
 (0)