allow idempotence when adding a task to cgroup metrics collection

Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
Mike Brown 2018-10-17 16:55:22 -05:00
parent f1f8cb017e
commit 879b2ae291

View File

@ -20,7 +20,6 @@ package cgroups
import (
"context"
"errors"
"fmt"
"sync"
@ -33,13 +32,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
var (
// ErrAlreadyCollected is returned when a cgroups is already being monitored
ErrAlreadyCollected = errors.New("cgroup is already being collected")
// ErrCgroupNotExists is returns when a cgroup no longer exists
ErrCgroupNotExists = errors.New("cgroup does not exist in the collector")
)
// Trigger will be called when an event happens and provides the cgroup
// where the event originated from
type Trigger func(string, string, cgroups.Cgroup)
@ -141,7 +133,7 @@ func (c *collector) Add(t runtime.Task) error {
defer c.mu.Unlock()
id := taskID(t.ID(), t.Namespace())
if _, ok := c.tasks[id]; ok {
return ErrAlreadyCollected
return nil // requests to collect metrics should be idempotent
}
c.tasks[id] = t
return nil