From: Shengjing Zhu Date: Wed, 16 Sep 2020 15:15:44 +0800 Subject: disable windows support Forwarded: not-needed --- cmd/ctr/commands/tasks/metrics.go | 60 +---------------------- internal/cri/config/config.go | 3 -- internal/cri/server/container_stats_list.go | 61 ------------------------ internal/cri/server/container_stats_list_test.go | 10 ---- 4 files changed, 1 insertion(+), 133 deletions(-) diff --git a/cmd/ctr/commands/tasks/metrics.go b/cmd/ctr/commands/tasks/metrics.go index 7b15d1f..b1e49a6 100644 --- a/cmd/ctr/commands/tasks/metrics.go +++ b/cmd/ctr/commands/tasks/metrics.go @@ -23,7 +23,6 @@ import ( "os" "text/tabwriter" - wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats" v1 "github.com/containerd/cgroups/v3/cgroup1/stats" v2 "github.com/containerd/cgroups/v3/cgroup2/stats" "github.com/containerd/containerd/v2/cmd/ctr/commands" @@ -74,10 +73,8 @@ var metricsCommand = &cli.Command{ data = &v1.Metrics{} case typeurl.Is(metric.Data, (*v2.Metrics)(nil)): data = &v2.Metrics{} - case typeurl.Is(metric.Data, (*wstats.Statistics)(nil)): - data = &wstats.Statistics{} default: - return errors.New("cannot convert metric data to cgroups.Metrics or windows.Statistics") + return errors.New("cannot convert metric data to cgroups.Metrics") } if err := typeurl.UnmarshalTo(metric.Data, data); err != nil { return err @@ -93,8 +90,6 @@ var metricsCommand = &cli.Command{ printCgroupMetricsTable(w, v) case *v2.Metrics: printCgroup2MetricsTable(w, v) - case *wstats.Statistics: - printWindowsStats(w, v) } return w.Flush() case formatJSON: @@ -149,56 +144,3 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) { } } -func printWindowsStats(w *tabwriter.Writer, windowsStats *wstats.Statistics) { - if windowsStats.GetLinux() != nil { - stats := windowsStats.GetLinux() - 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) - } -} - -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) - fmt.Fprintf(w, "start_time\t%s\t\n", stats.ContainerStartTime) - fmt.Fprintf(w, "uptime_ns\t%d\t\n", stats.UptimeNS) - if stats.Processor != nil { - fmt.Fprintf(w, "cpu.total_runtime_ns\t%d\t\n", stats.Processor.TotalRuntimeNS) - fmt.Fprintf(w, "cpu.runtime_user_ns\t%d\t\n", stats.Processor.RuntimeUserNS) - fmt.Fprintf(w, "cpu.runtime_kernel_ns\t%d\t\n", stats.Processor.RuntimeKernelNS) - } - if stats.Memory != nil { - fmt.Fprintf(w, "memory.commit_bytes\t%d\t\n", stats.Memory.MemoryUsageCommitBytes) - fmt.Fprintf(w, "memory.commit_peak_bytes\t%d\t\n", stats.Memory.MemoryUsageCommitPeakBytes) - fmt.Fprintf(w, "memory.private_working_set_bytes\t%d\t\n", stats.Memory.MemoryUsagePrivateWorkingSetBytes) - } - if stats.Storage != nil { - fmt.Fprintf(w, "storage.read_count_normalized\t%d\t\n", stats.Storage.ReadCountNormalized) - fmt.Fprintf(w, "storage.read_size_bytes\t%d\t\n", stats.Storage.ReadSizeBytes) - fmt.Fprintf(w, "storage.write_count_normalized\t%d\t\n", stats.Storage.WriteCountNormalized) - fmt.Fprintf(w, "storage.write_size_bytes\t%d\t\n", stats.Storage.WriteSizeBytes) - } -} - -func printWindowsVMStatistics(w *tabwriter.Writer, stats *wstats.VirtualMachineStatistics) { - fmt.Fprintf(w, "METRIC\tVALUE\t\n") - if stats.Processor != nil { - fmt.Fprintf(w, "vm.cpu.total_runtime_ns\t%d\t\n", stats.Processor.TotalRuntimeNS) - } - if stats.Memory != nil { - fmt.Fprintf(w, "vm.memory.working_set_bytes\t%d\t\n", stats.Memory.WorkingSetBytes) - fmt.Fprintf(w, "vm.memory.virtual_node_count\t%d\t\n", stats.Memory.VirtualNodeCount) - fmt.Fprintf(w, "vm.memory.available\t%d\t\n", stats.Memory.VmMemory.AvailableMemory) - fmt.Fprintf(w, "vm.memory.available_buffer\t%d\t\n", stats.Memory.VmMemory.AvailableMemoryBuffer) - fmt.Fprintf(w, "vm.memory.reserved\t%d\t\n", stats.Memory.VmMemory.ReservedMemory) - fmt.Fprintf(w, "vm.memory.assigned\t%d\t\n", stats.Memory.VmMemory.AssignedMemory) - fmt.Fprintf(w, "vm.memory.slp_active\t%t\t\n", stats.Memory.VmMemory.SlpActive) - fmt.Fprintf(w, "vm.memory.balancing_enabled\t%t\t\n", stats.Memory.VmMemory.BalancingEnabled) - fmt.Fprintf(w, "vm.memory.dm_operation_in_progress\t%t\t\n", stats.Memory.VmMemory.DmOperationInProgress) - } -} diff --git a/internal/cri/config/config.go b/internal/cri/config/config.go index 6f8f2d1..058c8f1 100644 --- a/internal/cri/config/config.go +++ b/internal/cri/config/config.go @@ -30,7 +30,6 @@ import ( runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "k8s.io/kubelet/pkg/cri/streaming" - runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options" runcoptions "github.com/containerd/containerd/api/types/runc/options" runtimeoptions "github.com/containerd/containerd/api/types/runtimeoptions/v1" "github.com/containerd/containerd/v2/internal/cri/annotations" @@ -767,8 +766,6 @@ func getRuntimeOptionsType(t string) interface{} { switch t { case plugins.RuntimeRuncV2: return &runcoptions.Options{} - case plugins.RuntimeRunhcsV1: - return &runhcsoptions.Options{} default: return &runtimeoptions.Options{} } diff --git a/internal/cri/server/container_stats_list.go b/internal/cri/server/container_stats_list.go index 55ebead..afdb1a5 100644 --- a/internal/cri/server/container_stats_list.go +++ b/internal/cri/server/container_stats_list.go @@ -23,7 +23,6 @@ import ( "reflect" "time" - wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats" cg1 "github.com/containerd/cgroups/v3/cgroup1/stats" cg2 "github.com/containerd/cgroups/v3/cgroup2/stats" "github.com/containerd/log" @@ -102,10 +101,6 @@ func (c *criService) getMetricsHandler(ctx context.Context, sandboxID string) (m snapshotter := c.RuntimeSnapshotter(ctx, ociRuntime) switch p.OS { - case "windows": - return func(meta containerstore.Metadata, stats *types.Metric) (containerStats, error) { - return c.windowsContainerMetrics(meta, stats, snapshotter) - }, nil case "linux": return func(meta containerstore.Metadata, stats *types.Metric) (containerStats, error) { return c.linuxContainerMetrics(meta, stats, snapshotter) @@ -297,62 +292,6 @@ func matchLabelSelector(selector, labels map[string]string) bool { return true } -func (c *criService) windowsContainerMetrics( - meta containerstore.Metadata, - stats *types.Metric, - snapshotter string, -) (containerStats, error) { - var cs runtime.ContainerStats - var usedBytes, inodesUsed uint64 - sn, err := c.GetSnapshot(meta.ID, snapshotter) - // If snapshotstore doesn't have cached snapshot information - // set WritableLayer usage to zero - if err == nil { - usedBytes = sn.Size - inodesUsed = sn.Inodes - } - cs.WritableLayer = &runtime.FilesystemUsage{ - Timestamp: sn.Timestamp, - FsId: &runtime.FilesystemIdentifier{ - Mountpoint: c.imageFSPaths[snapshotter], - }, - UsedBytes: &runtime.UInt64Value{Value: usedBytes}, - InodesUsed: &runtime.UInt64Value{Value: inodesUsed}, - } - cs.Attributes = &runtime.ContainerAttributes{ - Id: meta.ID, - Metadata: meta.Config.GetMetadata(), - Labels: meta.Config.GetLabels(), - Annotations: meta.Config.GetAnnotations(), - } - - if stats != nil { - s, err := typeurl.UnmarshalAny(stats.Data) - if err != nil { - return containerStats{}, fmt.Errorf("failed to extract container metrics: %w", err) - } - wstats := s.(*wstats.Statistics).GetWindows() - if wstats == nil { - return containerStats{}, errors.New("windows stats is empty") - } - if wstats.Processor != nil { - cs.Cpu = &runtime.CpuUsage{ - Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(), - UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS}, - } - } - if wstats.Memory != nil { - cs.Memory = &runtime.MemoryUsage{ - Timestamp: (protobuf.FromTimestamp(wstats.Timestamp)).UnixNano(), - WorkingSetBytes: &runtime.UInt64Value{ - Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes, - }, - } - } - } - return containerStats{&cs, 0}, nil -} - func (c *criService) linuxContainerMetrics( meta containerstore.Metadata, stats *types.Metric, diff --git a/internal/cri/server/container_stats_list_test.go b/internal/cri/server/container_stats_list_test.go index 8d5d571..689f266 100644 --- a/internal/cri/server/container_stats_list_test.go +++ b/internal/cri/server/container_stats_list_test.go @@ -24,13 +24,11 @@ import ( "testing" "time" - wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats" v1 "github.com/containerd/cgroups/v3/cgroup1/stats" v2 "github.com/containerd/cgroups/v3/cgroup2/stats" "github.com/containerd/containerd/api/types" containerstore "github.com/containerd/containerd/v2/internal/cri/store/container" sandboxstore "github.com/containerd/containerd/v2/internal/cri/store/sandbox" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/platforms" "github.com/containerd/typeurl/v2" "github.com/stretchr/testify/assert" @@ -489,14 +487,6 @@ func platformBasedMetricsData(t *testing.T) *anypb.Any { p := platforms.DefaultSpec() switch p.OS { - case "windows": - data, err = typeurl.MarshalAnyToProto(&wstats.Statistics{Container: &wstats.Statistics_Windows{ - Windows: &wstats.WindowsContainerStatistics{ - Timestamp: protobuf.ToTimestamp(time.Now()), - Processor: &wstats.WindowsContainerProcessorStatistics{ - TotalRuntimeNS: 100, - }, - }}}) case "linux": data, err = typeurl.MarshalAnyToProto(&v2.Metrics{CPU: &v2.CPUStat{UsageUsec: 100}}) default: