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