Path: blob/main/pkg/integrations/v2/eventhandler/integration.go
5304 views
package eventhandler12import (3"github.com/go-kit/log"4"github.com/grafana/agent/pkg/integrations/v2"5"github.com/prometheus/prometheus/model/labels"6)78// DefaultConfig sets defaults for Config9var DefaultConfig = Config{10SendTimeout: 60,11CachePath: "./.eventcache/eventhandler.cache",12LogsInstance: "default",13InformerResync: 120,14FlushInterval: 10,15}1617// Config configures the eventhandler integration18type Config struct {19// Eventhandler hands watched events off to promtail using a promtail20// client channel. This parameter configures how long to wait (in seconds) on the channel21// before abandoning and moving on.22SendTimeout int `yaml:"send_timeout,omitempty"`23// Configures the path to a kubeconfig file. If not set, will fall back to using24// an in-cluster config. If this fails, will fall back to checking the user's home25// directory for a kubeconfig.26KubeconfigPath string `yaml:"kubeconfig_path,omitempty"`27// Path to a cache file that will store the last timestamp for a shipped event and events28// shipped for that timestamp. Used to prevent double-shipping on integration restart.29CachePath string `yaml:"cache_path,omitempty"`30// Name of logs subsystem instance to hand log entries off to.31LogsInstance string `yaml:"logs_instance,omitempty"`32// K8s informer resync interval (seconds). You should use defaults here unless you are33// familiar with K8s informers.34InformerResync int `yaml:"informer_resync,omitempty"`35// The integration will flush the last event shipped out to disk every flush_interval seconds.36FlushInterval int `yaml:"flush_interval,omitempty"`37// If you would like to limit events to a given namespace, use this parameter.38Namespace string `yaml:"namespace,omitempty"`39// Extra labels to append to log lines40ExtraLabels labels.Labels `yaml:"extra_labels,omitempty"`41InstanceKey *string `yaml:"instance,omitempty"`42}4344// UnmarshalYAML implements yaml.Unmarshaler for Config45func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {46*c = DefaultConfig4748type plain Config49return unmarshal((*plain)(c))50}5152// Name returns the name of the integration that this config represents53func (c *Config) Name() string { return "eventhandler" }5455// ApplyDefaults applies runtime-specific defaults to c56func (c *Config) ApplyDefaults(globals integrations.Globals) error {57return nil58}5960// Identifier uniquely identifies this instance of Config61func (c *Config) Identifier(globals integrations.Globals) (string, error) {62if c.InstanceKey != nil {63return *c.InstanceKey, nil64}65return c.Name(), nil66}6768// NewIntegration converts this config into an instance of an integration.69func (c *Config) NewIntegration(l log.Logger, globals integrations.Globals) (integrations.Integration, error) {70return newEventHandler(l, globals, c)71}7273func init() {74integrations.Register(&Config{}, integrations.TypeSingleton)75}767778