agent

package
v18.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentName                         = "gitlab-agent"
	DefaultAPIListenNetwork           = "tcp"
	DefaultPrivateAPIListenNetwork    = "tcp"
	DefaultPrivateAPIListenAddress    = ":8081"
	DefaultObservabilityListenNetwork = "tcp"
	DefaultObservabilityListenAddress = ":8080"
)

Variables

This section is empty.

Functions

func AddCommonFlagsToCommand

func AddCommonFlagsToCommand(c *cobra.Command, o *Options)

func CollectExtraTelemetryData

func CollectExtraTelemetryData(environ []string) map[string]string

Types

type AgentAPI

type AgentAPI struct {
	ModuleName        string
	AgentKey          *syncz.ValueHolder[api.AgentKey]
	GitLabExternalURL *syncz.ValueHolder[url.URL]
	Client            gitlab_access_rpc.GitlabAccessClient
}

AgentAPI is an implementation of modagent.API.

func (*AgentAPI) GetAgentKey

func (a *AgentAPI) GetAgentKey(ctx context.Context) (api.AgentKey, error)

func (*AgentAPI) GetGitLabExternalURL

func (a *AgentAPI) GetGitLabExternalURL(ctx context.Context) (url.URL, error)

func (*AgentAPI) HandleProcessingError

func (a *AgentAPI) HandleProcessingError(ctx context.Context, log *slog.Logger, msg string, err error, fields ...fieldz.Field)

func (*AgentAPI) MakeGitLabRequest

func (a *AgentAPI) MakeGitLabRequest(ctx context.Context, path string, opts ...modagent.GitLabRequestOption) (*modagent.GitLabResponse, error)

func (*AgentAPI) TryGetAgentKey

func (a *AgentAPI) TryGetAgentKey() (api.AgentKey, bool)

type AgentSharedAPI

type AgentSharedAPI struct {
}

func (*AgentSharedAPI) HandleProcessingError

func (a *AgentSharedAPI) HandleProcessingError(ctx context.Context, log *slog.Logger, msg string, err error, fields ...fieldz.Field)

type CancelRunWhenLeaderFunc

type CancelRunWhenLeaderFunc func()

type ConfigurationWatcher

type ConfigurationWatcher[CD any] interface {
	Watch(context.Context, func(context.Context, CD))
}

ConfigurationWatcher provides a mechanism to receive new configuration objects.

type FactoriesLayer

type FactoriesLayer[CF, CM any] struct {
	Log       *slog.Logger
	Config    func(name string) CF
	LR        LeaderRunnerInterface[CM]
	MR        ModuleRunnerInterface[CM]
	Factories []modagent.Factory[CF, CM]
}

func (*FactoriesLayer[CF, CM]) ToStageFuncs

func (l *FactoriesLayer[CF, CM]) ToStageFuncs() ([]stager.StageFunc, error)

type InMemAPIServer

type InMemAPIServer struct {
	Server        *grpc.Server
	InMemConn     *grpc.ClientConn
	InMemListener net.Listener
}

InMemAPIServer represents agentk API that kas can talk to when running in agentk->kas tunnel mode.

func (*InMemAPIServer) Close

func (s *InMemAPIServer) Close() error

func (*InMemAPIServer) Start

func (s *InMemAPIServer) Start(stage stager.Stage)

type LeaderElector

type LeaderElector interface {
	Run(ctx context.Context, onStartedLeading, onStoppedLeading func())
}

type LeaderModule

type LeaderModule struct {
	// contains filtered or unexported fields
}

type LeaderRunner

type LeaderRunner[CM any] struct {
	// contains filtered or unexported fields
}

func NewLeaderRunner

func NewLeaderRunner[CM any](leaderElector LeaderElector) *LeaderRunner[CM]

func (*LeaderRunner[CM]) Run

func (r *LeaderRunner[CM]) Run(ctx context.Context)

Run starts the leader election process and starts and stops the modules depending on if it is the leader or not.

func (*LeaderRunner[CM]) RunWhenLeader

func (r *LeaderRunner[CM]) RunWhenLeader(ctx context.Context, startFn ModuleStartFunc, stopFn ModuleStopFunc) (CancelRunWhenLeaderFunc, error)

RunWhenLeader registers a module start and stop function with the leader runner. The function that is returned must be used to unregister the leader module.

func (*LeaderRunner[CM]) WrapModule

func (r *LeaderRunner[CM]) WrapModule(m modagent.Module[CM]) modagent.Module[CM]

type LeaderRunnerInterface

type LeaderRunnerInterface[CM any] interface {
	WrapModule(modagent.Module[CM]) modagent.Module[CM]
}

type ListenAPIServer

type ListenAPIServer struct {
	Log                          *slog.Logger
	ListenNetwork, ListenAddress string
	CertFile, KeyFile            string

	AuxCancel context.CancelFunc
	Server    *grpc.Server
}

ListenAPIServer represents agentk API that kas can talk to. It can be either: - in-memory. This is the case when agentk connects to kas. - exposed on an address. This is the case when kas connects to agentk.

func NewListenAPIServer

func NewListenAPIServer(log *slog.Logger, ot *ObsTools, factory modshared.RPCAPIFactory,
	listenNetwork, listenAddress, certFile, keyFile,
	jwtSecretFile, jwtIssuer, jwtAudience,
	mtlsClientCAFile string, mtlsEnabled bool,
	v protovalidate.Validator) (*ListenAPIServer, error)

func (*ListenAPIServer) Start

func (s *ListenAPIServer) Start(stage stager.Stage)

type ModuleRunner

type ModuleRunner[CD, CM any] struct {
	Log         *slog.Logger
	Watcher     ConfigurationWatcher[CD]
	Data2Config func(CD) (CM, []any) // second return value is extra attributes for the logger
	// contains filtered or unexported fields
}

func (*ModuleRunner[CD, CM]) RegisterModules

func (r *ModuleRunner[CD, CM]) RegisterModules(modules ...modagent.Module[CM]) []stager.StageFunc

RegisterModules registers modules with the runner. It returns staged functions to run modules.

func (*ModuleRunner[CD, CM]) RunConfigurationRefresh

func (r *ModuleRunner[CD, CM]) RunConfigurationRefresh(ctx context.Context) error

type ModuleRunnerInterface

type ModuleRunnerInterface[CM any] interface {
	RegisterModules(...modagent.Module[CM]) []stager.StageFunc
}

type ModuleStartFunc

type ModuleStartFunc func()

type ModuleStopFunc

type ModuleStopFunc func() ModuleStopWaitFunc

type ModuleStopWaitFunc

type ModuleStopWaitFunc func(context.Context) error

type Options

type Options struct {
	Log               *slog.Logger
	LogLevel          *slog.LevelVar
	GRPCHandler       slog.Handler
	GRPCLogLevel      *slog.LevelVar
	Validator         protovalidate.Validator
	AgentKey          *syncz.ValueHolder[api.AgentKey]
	GitLabExternalURL *syncz.ValueHolder[url.URL]

	KASAddress       string
	KASCACertFile    string
	KASHeaders       []string
	KASSkipTLSVerify bool
	KASTLSServerName string

	ObservabilityListenNetwork string
	ObservabilityListenAddress string
	ObservabilityCertFile      string
	ObservabilityKeyFile       string

	TokenFile  string
	AgentToken api.AgentToken
}

func (*Options) Complete

func (o *Options) Complete(envVarAgentToken, defaultLogLevel, defaultGRPCLogLevel string) error

func (*Options) ConstructKASConnection

func (o *Options) ConstructKASConnection(ot *ObsTools, userAgent string, agentType api.AgentType) (*grpc.ClientConn, error)

func (*Options) ConstructObservabilityTools

func (o *Options) ConstructObservabilityTools() (*ObsTools, func() error, error)

func (*Options) NewRPCAPIFactory

func (o *Options) NewRPCAPIFactory() modshared.RPCAPIFactory

type PrivateAPIServer

type PrivateAPIServer struct {
	Log            *slog.Logger
	ListenNetwork  string
	ListenAddress  string
	OwnURL         grpctool.URLTarget
	OwnURLScheme   string
	OwnURLPort     string
	Server         grpctool.GRPCServer
	ListenServer   *grpc.Server
	InMemServer    *grpc.Server
	InMemListener  net.Listener
	AgentPool      grpctool.PoolInterface[grpctool.URLTarget]
	AgentPoolClose func()
	AuxCancel      context.CancelFunc
}

func NewPrivateAPIServer

func NewPrivateAPIServer(log *slog.Logger, ot *ObsTools, errRep errz.ErrReporter, factory modshared.RPCAPIFactory,
	v protovalidate.Validator,
	userAgent, listenNetwork, listenAddress, certFile, keyFile, caCertFile, jwtAuthFile string) (*PrivateAPIServer, error)

func (*PrivateAPIServer) Close

func (s *PrivateAPIServer) Close() error

func (*PrivateAPIServer) Start

func (s *PrivateAPIServer) Start(stage stager.Stage)

type Runner

type Runner interface {
	// RunWhenLeader registers the given start and stop functions for this module with the leader runner.
	// When the leader runner is elected as the leader it will execute the start function and
	// when the leader runner lost the leadership it will execute the stop function.
	// The start function must be able to be triggered multiple times (with intermediate stop executions)
	// without having to rely on a new agent configuration.
	// The function that is returned must be used to unregister the module
	// from the leader runner in case a shutdown is initiated or a previously registered start function
	// became invalid, for example because a new agent configuration turned out to be invalid.
	RunWhenLeader(ctx context.Context, startFn ModuleStartFunc, stopFunc ModuleStopFunc) (CancelRunWhenLeaderFunc, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL