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
|
package agent
import (
"crypto/tls"
"fmt"
"net"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modagent"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modshared"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/observability"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/tlstool"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/agentcfg"
"go.uber.org/zap"
)
type Factory struct {
LogLevel zap.AtomicLevel
GrpcLogLevel zap.AtomicLevel
DefaultGrpcLogLevel agentcfg.LogLevelEnum
Gatherer prometheus.Gatherer
Registerer prometheus.Registerer
ListenNetwork string
ListenAddress string
CertFile string
KeyFile string
}
func (f *Factory) New(config *modagent.Config) (modagent.Module, error) {
tlsConfig, err := tlstool.MaybeDefaultServerTLSConfig(f.CertFile, f.KeyFile)
if err != nil {
return nil, err
}
var listener func() (net.Listener, error)
if tlsConfig != nil {
listener = func() (net.Listener, error) {
return tls.Listen(f.ListenNetwork, f.ListenAddress, tlsConfig) // nolint:gosec
}
} else {
listener = func() (net.Listener, error) {
return net.Listen(f.ListenNetwork, f.ListenAddress) // nolint:gosec
}
}
return &module{
log: config.Log,
logLevel: f.LogLevel,
grpcLogLevel: f.GrpcLogLevel,
defaultGrpcLogLevel: f.DefaultGrpcLogLevel,
api: config.Api,
gatherer: f.Gatherer,
registerer: f.Registerer,
listener: listener,
serverName: fmt.Sprintf("%s/%s/%s", config.AgentName, config.AgentMeta.Version, config.AgentMeta.CommitId),
}, nil
}
func (f *Factory) Name() string {
return observability.ModuleName
}
func (f *Factory) StartStopPhase() modshared.ModuleStartStopPhase {
return modshared.ModuleStartBeforeServers
}
|