From 1debb6b35a88ea34ffdebc64a5a67b19961c940d Mon Sep 17 00:00:00 2001 From: Shishir Mahajan Date: Wed, 17 Jun 2020 15:14:27 -0700 Subject: [PATCH] Make task stats interval configurable. --- containerd/driver.go | 13 +++++++++++++ example/agent.hcl | 1 + 2 files changed, 14 insertions(+) diff --git a/containerd/driver.go b/containerd/driver.go index 0aea040..a946f80 100644 --- a/containerd/driver.go +++ b/containerd/driver.go @@ -61,6 +61,7 @@ var ( hclspec.NewLiteral("true"), ), "containerd_runtime": hclspec.NewAttr("containerd_runtime", "string", true), + "stats_interval": hclspec.NewAttr("stats_interval", "string", false), }) // taskConfigSpec is the specification of the plugin's configuration for @@ -85,6 +86,7 @@ var ( type Config struct { Enabled bool `codec:"enabled"` ContainerdRuntime string `codec:"containerd_runtime"` + StatsInterval string `codec:"stats_interval"` } // TaskConfig contains configuration information for a task that runs with @@ -499,6 +501,17 @@ func (d *Driver) TaskStats(ctx context.Context, taskID string, interval time.Dur return nil, drivers.ErrTaskNotFound } + if d.config.StatsInterval != "" { + statsInterval, err := time.ParseDuration(d.config.StatsInterval) + if err != nil { + d.logger.Warn("Error parsing driver stats interval, fallback on default interval") + } else { + msg := fmt.Sprintf("Overriding client stats interval: %v with driver stats interval: %v", interval, d.config.StatsInterval) + d.logger.Debug(msg) + interval = statsInterval + } + } + return handle.stats(ctx, d.ctxContainerd, interval) } diff --git a/example/agent.hcl b/example/agent.hcl index 1d78d41..9eeda7f 100644 --- a/example/agent.hcl +++ b/example/agent.hcl @@ -4,5 +4,6 @@ plugin "containerd-driver" { config { enabled = true containerd_runtime = "io.containerd.runc.v2" + stats_interval = "5s" } }