-
Notifications
You must be signed in to change notification settings - Fork 480
/
integration.go
69 lines (59 loc) · 2.59 KB
/
integration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package eventhandler
import (
"github.com/go-kit/log"
"github.com/grafana/agent/pkg/integrations/v2"
)
// DefaultConfig sets defaults for Config
var DefaultConfig = Config{
SendTimeout: 60,
CachePath: "./.eventcache/eventhandler.cache",
LogsInstance: "default",
InformerResync: 120,
FlushInterval: 10,
}
// Config configures the eventhandler integration
type Config struct {
// Eventhandler hands watched events off to promtail using a promtail
// client channel. This parameter configures how long to wait (in seconds) on the channel
// before abandoning and moving on.
SendTimeout int `yaml:"send_timeout,omitempty"`
// Configures the path to a kubeconfig file. If not set, will fall back to using
// an in-cluster config. If this fails, will fall back to checking the user's home
// directory for a kubeconfig.
KubeconfigPath string `yaml:"kubeconfig_path,omitempty"`
// Path to a cache file that will store the last timestamp for a shipped event and events
// shipped for that timestamp. Used to prevent double-shipping on integration restart.
CachePath string `yaml:"cache_path,omitempty"`
// Name of logs subsystem instance to hand log entries off to.
LogsInstance string `yaml:"logs_instance,omitempty"`
// K8s informer resync interval (seconds). You should use defaults here unless you are
// familiar with K8s informers.
InformerResync int `yaml:"informer_resync,omitempty"`
// The integration will flush the last event shipped out to disk every flush_interval seconds.
FlushInterval int `yaml:"flush_interval,omitempty"`
// If you would like to limit events to a given namespace, use this parameter.
Namespace string `yaml:"namespace,omitempty"`
}
// UnmarshalYAML implements yaml.Unmarshaler for Config
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig
type plain Config
return unmarshal((*plain)(c))
}
// Name returns the name of the integration that this config represents
func (c *Config) Name() string { return "eventhandler" }
// ApplyDefaults applies runtime-specific defaults to c
func (c *Config) ApplyDefaults(globals integrations.Globals) error {
return nil
}
// Identifier uniquely identifies this instance of Config
func (c *Config) Identifier(globals integrations.Globals) (string, error) {
return globals.AgentIdentifier, nil
}
// NewIntegration converts this config into an instance of an integration.
func (c *Config) NewIntegration(l log.Logger, globals integrations.Globals) (integrations.Integration, error) {
return newEventHandler(l, globals, c)
}
func init() {
integrations.Register(&Config{}, integrations.TypeSingleton)
}