Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/instance/configstore/store.go
5363 views
1
// Package configstore abstracts the concepts of where instance files get
2
// retrieved.
3
package configstore
4
5
import (
6
"context"
7
8
"github.com/grafana/agent/pkg/metrics/instance"
9
)
10
11
// Store is some interface to retrieving instance configurations.
12
type Store interface {
13
// List gets the list of config names.
14
List(ctx context.Context) ([]string, error)
15
16
// Get gets an individual config by name.
17
Get(ctx context.Context, key string) (instance.Config, error)
18
19
// Put applies a new instance Config to the store.
20
// If the config already exists, created will be false to indicate an
21
// update.
22
Put(ctx context.Context, c instance.Config) (created bool, err error)
23
24
// Delete deletes a config from the store.
25
Delete(ctx context.Context, key string) error
26
27
// All retrieves the entire list of instance configs currently
28
// in the store. A filtering "keep" function can be provided to ignore some
29
// configs, which can significantly speed up the operation in some cases.
30
All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)
31
32
// Watch watches for changed instance Configs.
33
// All callers of Watch receive the same Channel.
34
//
35
// It is not guaranteed that Watch will emit all store events, and Watch
36
// should only be used for best-effort quick convergence with the remote
37
// store. Watch should always be paired with polling All.
38
Watch() <-chan WatchEvent
39
40
// Close closes the store.
41
Close() error
42
}
43
44
// WatchEvent is returned by Watch. The Key is the name of the config that was
45
// added, updated, or deleted. If the Config was deleted, Config will be nil.
46
type WatchEvent struct {
47
Key string
48
Config *instance.Config
49
}
50
51