monitoring

package
v3.1.0-beta.51 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package monitoring contains backend reachability and protocol health-check logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveServiceName

func ResolveServiceName(tracingServiceName string, instanceName string, fallbackName string) string

ResolveServiceName determines the OpenTelemetry service name.

Priority:

  1. explicit tracing service name (if set and not an IP)
  2. configured instance name (if set and not an IP)
  3. hostname (if available and not an IP)
  4. fallbackName

Types

type AuthCapabilities

type AuthCapabilities struct {
	Mechanisms           map[HealthAuthMechanism]struct{}
	InitialResponses     map[HealthAuthMechanism]struct{}
	NativeMechanisms     map[HealthAuthMechanism]struct{}
	Raw                  []string
	Source               string
	SASLIR               bool
	SupportsCapabilities bool
	SupportsMechanisms   bool
}

AuthCapabilities is the protocol-neutral capability model consumed by AuthSelector.

func NewAuthCapabilities

func NewAuthCapabilities(source string) AuthCapabilities

NewAuthCapabilities creates an empty capability set for one protocol adapter.

func ParseIMAPAuthCapabilities

func ParseIMAPAuthCapabilities(lines []string) AuthCapabilities

ParseIMAPAuthCapabilities normalizes IMAP CAPABILITY authentication tokens.

func ParsePOP3AuthCapabilities

func ParsePOP3AuthCapabilities(lines []string) AuthCapabilities

ParsePOP3AuthCapabilities normalizes POP3 CAPA authentication tokens.

func ParseSMTPAuthCapabilities

func ParseSMTPAuthCapabilities(lines []string) AuthCapabilities

ParseSMTPAuthCapabilities normalizes SMTP and LMTP AUTH capability forms.

func ParseSieveAuthCapabilities

func ParseSieveAuthCapabilities(lines []string) AuthCapabilities

ParseSieveAuthCapabilities normalizes ManageSieve greeting and CAPABILITY auth tokens.

func (*AuthCapabilities) AddMechanism

func (c *AuthCapabilities) AddMechanism(mechanism HealthAuthMechanism, initialResponse bool, native bool)

AddMechanism records one executable mechanism and its protocol-specific execution traits.

func (*AuthCapabilities) HasMechanism

func (c *AuthCapabilities) HasMechanism(mechanism HealthAuthMechanism) bool

HasMechanism reports whether the adapter advertised one executable mechanism.

type AuthMechanismUnavailableError

type AuthMechanismUnavailableError struct {
	Protocol   string
	Host       string
	Configured HealthAuthMechanism
	Advertised []string
	Port       int
	SASLIR     bool
	Auto       bool
	Capability string
}

AuthMechanismUnavailableError reports that the selected target mechanism cannot be used.

func (*AuthMechanismUnavailableError) Error

Error formats the mechanism mismatch for callers while leaving sensitive payloads out.

type AuthSelection

type AuthSelection struct {
	Mechanism       HealthAuthMechanism
	InitialResponse bool
	Native          bool
}

AuthSelection is the selector result executed by a protocol session.

type AuthSelector

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

AuthSelector applies target configuration to protocol-neutral auth capabilities.

func NewAuthSelector

func NewAuthSelector(logger *slog.Logger, server *config.BackendServer, phase BackendCheckPhase) *AuthSelector

NewAuthSelector returns a selector for one backend target and health-check phase.

func (*AuthSelector) Select

func (s *AuthSelector) Select(capabilities AuthCapabilities) (AuthSelection, error)

Select validates the configured mechanism and returns the concrete exchange form to execute.

type BackendCheckPhase

type BackendCheckPhase string

BackendCheckPhase identifies which part of a backend health check is being executed.

const (
	// BackendCheckPhaseConnect verifies TCP, HAProxy-v2 preface, and TLS reachability only.
	BackendCheckPhaseConnect BackendCheckPhase = "connect"

	// BackendCheckPhaseDeep verifies the protocol-level deep check when enabled for a target.
	BackendCheckPhaseDeep BackendCheckPhase = "deep"
)

type ConnMonitor

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

ConnMonitor is a struct that implements monitoring of backend server connections by checking their availability.

func (*ConnMonitor) CheckBackendConnection

func (cm *ConnMonitor) CheckBackendConnection(server *config.BackendServer) error

CheckBackendConnection attempts to establish a connection to a backend server to verify its availability. It returns an error if the connection cannot be established, using the specified configuration parameters.

func (*ConnMonitor) CheckBackendConnectionPhase

func (cm *ConnMonitor) CheckBackendConnectionPhase(server *config.BackendServer, phase BackendCheckPhase) error

CheckBackendConnectionPhase checks one backend health-check phase.

type HealthAuthMechanism

type HealthAuthMechanism string

HealthAuthMechanism identifies one authentication mechanism executable by backend health checks.

const (
	// HealthAuthMechanismAuto requests automatic health-check mechanism selection.
	HealthAuthMechanismAuto HealthAuthMechanism = config.BackendAuthMechanismAuto
	// HealthAuthMechanismPlain selects SASL PLAIN.
	HealthAuthMechanismPlain HealthAuthMechanism = config.BackendAuthMechanismPlain
	// HealthAuthMechanismLogin selects SASL LOGIN.
	HealthAuthMechanismLogin HealthAuthMechanism = config.BackendAuthMechanismLogin
	// HealthAuthMechanismUserPass selects POP3 USER/PASS.
	HealthAuthMechanismUserPass HealthAuthMechanism = config.BackendAuthMechanismUserPass
	// HealthAuthMechanismBasic selects HTTP Basic authentication.
	HealthAuthMechanismBasic HealthAuthMechanism = config.BackendAuthMechanismBasic
)

type Monitor

type Monitor interface {
	// CheckBackendConnection checks the backend connection of a server based on the provided Host address, port number, whether the server runs with HAProxy V2 protocol, and whether TLS should be used. It returns an error if the connection fails.
	CheckBackendConnection(server *config.BackendServer) error

	// CheckBackendConnectionPhase checks one backend health-check phase.
	CheckBackendConnectionPhase(server *config.BackendServer, phase BackendCheckPhase) error
}

Monitor defines an interface for monitoring and checking backend server connections. It provides a method to verify connectivity using specified configurations.

func NewMonitor

func NewMonitor(cfg config.File, logger *slog.Logger) Monitor

NewMonitor returns a new instance of the Monitor interface. The returned Monitor is implemented by the ConnMonitor struct.

type Telemetry

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

Telemetry provides lifecycle management for OpenTelemetry tracing.

func GetTelemetry

func GetTelemetry() *Telemetry

GetTelemetry returns the Telemetry singleton.

func (*Telemetry) SetProvider

func (t *Telemetry) SetProvider(p TelemetryConfigProvider)

SetProvider allows injecting a custom configuration provider (primarily for tests). In production the default provider is used, which reads from the global config.

func (*Telemetry) Shutdown

func (t *Telemetry) Shutdown(ctx context.Context)

Shutdown flushes and closes the Telemetry provider.

func (*Telemetry) Start

func (t *Telemetry) Start(ctx context.Context, appVersion string)

Start initializes OpenTelemetry according to configuration. Safe to call multiple times.

type TelemetryConfigProvider

type TelemetryConfigProvider interface {
	GetTracing() *config.Tracing
	GetInstanceName() string
}

TelemetryConfigProvider abstracts access to configuration used by telemetry. This allows unit tests to inject a lightweight mock without depending on the full global config.File implementation.

Directories

Path Synopsis
Package trace provides trace functionality.
Package trace provides trace functionality.

Jump to

Keyboard shortcuts

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