Sandbox: Add Metrics rpc for controller

As a follow up change to adding a SandboxMetrics rpc to the core
sandbox service, the controller needed a corresponding rpc for CRI
and others to eventually implement.

This leaves the CRI (non-shim mode) controller unimplemented just to
have a change with the API addition to start.

Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
Danny Canter
2023-06-13 00:24:09 -07:00
parent d56722ef2a
commit d278d37caa
9 changed files with 567 additions and 284 deletions

View File

@@ -22,6 +22,7 @@ import (
"time"
runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/events/exchange"
@@ -283,6 +284,19 @@ func (c *controllerLocal) Status(ctx context.Context, sandboxID string, verbose
}, nil
}
func (c *controllerLocal) Metrics(ctx context.Context, sandboxID string) (*types.Metric, error) {
sb, err := c.getSandbox(ctx, sandboxID)
if err != nil {
return nil, err
}
req := &runtimeAPI.SandboxMetricsRequest{SandboxID: sandboxID}
resp, err := sb.SandboxMetrics(ctx, req)
if err != nil {
return nil, err
}
return resp.Metrics, nil
}
func (c *controllerLocal) getSandbox(ctx context.Context, id string) (runtimeAPI.TTRPCSandboxService, error) {
shim, err := c.shims.Get(ctx, id)
if err != nil {