Path: blob/main/component/otelcol/internal/scheduler/host.go
4096 views
package scheduler12import (3"github.com/go-kit/log"4"github.com/go-kit/log/level"56otelcomponent "go.opentelemetry.io/collector/component"7otelconfig "go.opentelemetry.io/collector/config"8)910// Host implements otelcomponent.Host for Grafana Agent Flow.11type Host struct {12log log.Logger1314extensions map[otelconfig.ComponentID]otelcomponent.Extension15exporters map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter16}1718// NewHost creates a new Host.19func NewHost(l log.Logger, opts ...HostOption) *Host {20h := &Host{log: l}21for _, opt := range opts {22opt(h)23}24return h25}2627// HostOption customizes behavior of the Host.28type HostOption func(*Host)2930// WithHostExtensions provides a custom set of extensions to the Host.31func WithHostExtensions(extensions map[otelconfig.ComponentID]otelcomponent.Extension) HostOption {32return func(h *Host) {33h.extensions = extensions34}35}3637// WithHostExporters provides a custom set of exporters to the Host.38func WithHostExporters(exporters map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter) HostOption {39return func(h *Host) {40h.exporters = exporters41}42}4344var _ otelcomponent.Host = (*Host)(nil)4546// ReportFatalError implements otelcomponent.Host.47func (h *Host) ReportFatalError(err error) {48level.Error(h.log).Log("msg", "fatal error running component", "err", err)49}5051// GetFactory implements otelcomponent.Host.52func (h *Host) GetFactory(kind otelcomponent.Kind, componentType otelconfig.Type) otelcomponent.Factory {53// GetFactory is used for components to create other components. It's not54// clear if we want to allow this right now, so it's disabled.55return nil56}5758// GetExtensions implements otelcomponent.Host.59func (h *Host) GetExtensions() map[otelconfig.ComponentID]otelcomponent.Extension {60return h.extensions61}6263// GetExporters implements otelcomponent.Host.64func (h *Host) GetExporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {65return h.exporters66}676869