Skip to content

Failed to decode data of type containerd.runhcs.stats.v1.Statistics from containerd runtime #2439

@LiuYangDevStack

Description

@LiuYangDevStack

Hi, guys.
I'm doing a test which calls grpc API defined in https://github.com/containerd/containerd/blob/main/api/services/tasks/v1/tasks.proto.

I successfully call the Metrics Function using c#.

The code snippet is:

        public async Task GetMetric(string containerId)
        {
            Metadata metadata = new()
            {
                { "containerd-namespace", "k8s.io" },
            };
            var req = new MetricsRequest() { };
            req.Filters.Add("id==" + containerId);
            var resp = await this.tasksClient.MetricsAsync(req, metadata);
            Console.WriteLine($"Metric Length: {resp.Metrics.Count}");
            foreach (var metric in resp.Metrics)
            {
                Console.WriteLine($"Metrics:Container ID: {metric.Id}");
                Console.WriteLine($"Metrics:  Timestamp: {metric.Timestamp.ToDateTime():O}");
                Console.WriteLine($"Metrics: {metric.Data.TypeUrl}");
                Console.WriteLine($"Metrics: Changed proto version");
                var stats = metric.Data.Unpack<Statistics>();
                Console.WriteLine($"stats total runtime ns: {stats.Windows.Processor.TotalRuntimeNs}");
                Console.WriteLine($"stats user runtime ns: {stats.Windows.Processor.RuntimeUserNs}");
                Console.WriteLine($"stats system runtime ns: {stats.Windows.Processor.RuntimeKernelNs}");
                Console.WriteLine($"stats memory: {stats.Windows.Memory.MemoryUsagePrivateWorkingSetBytes}");
            }
        }

The log shows that metric.Data type url is:

Image

It seems that the type is containerd.runhcs.stats.v1.Statistics.

I searched on the internet, this class definition is here:

https://github.com/microsoft/hcsshim/blob/main/cmd/containerd-shim-runhcs-v1/stats/stats.proto

Another related file referenced by stats.proto:

https://github.com/containerd/cgroups/blob/main/cgroup1/stats/metrics.proto

However, I got the error:

Exception when get metric for efdee1ad58fd765046c85dfaa018e95ea8f047e826ce923464dc43970d73e867, exception message Google.Protobuf.InvalidProtocolBufferException: Full type name for Statistics is containerd.runhcs.stats.v1.Statistics; Any message's type url is containerd.runhcs.stats.v1.Statistics
   at Google.Protobuf.WellKnownTypes.Any.Unpack[T]()
   ...

Does anyone know how to fix the issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions