agentmodel

package
v0.1.40 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package agentmodel provides agent domain models.

Index

Constants

View Source
const (
	AgentPackageStatusEnumInstalled      = 0
	AgentPackageStatusEnumInstallPending = 1
	AgentPackageStatusEnumInstalling     = 2
	AgentPackageStatusEnumInstallFailed  = 3
	AgentPackageStatusEnumDownloading    = 4
)

AgentPackageStatusEnum values The AgentPackageStatusEnum enum is defined in the opamp protocol.

View Source
const DefaultConnectionStaleness = 90 * time.Second

DefaultConnectionStaleness is the default age above which an agent's last reported timestamp marks it as no-longer-connected. Set to 3× the typical OpAMP heartbeat interval (30s) so a single missed heartbeat does not flip the agent's connected state.

View Source
const (
	// DefaultNamespaceName is the name of the default namespace.
	DefaultNamespaceName = "default"
)
View Source
const (
	// OpAMPPollingInterval is a polling interval for OpAMP.
	// ref. https://github.com/minuk-dev/opampcommander/issues/8
	OpAMPPollingInterval = 30 * time.Second
)

Variables

View Source
var (
	// ErrUnsupportedRemoteConfigContentType is returned when the remote config content type is not supported.
	ErrUnsupportedRemoteConfigContentType = errors.New("unsupported remote config content type")
	// ErrUnsupportedAgentOperation is returned when the agent does not support the requested operation.
	ErrUnsupportedAgentOperation = errors.New("unsupported agent operation")
)

Functions

func ConvertConnIDToString

func ConvertConnIDToString(id any) string

ConvertConnIDToString converts the connection ID to a string. Uses %p for pointer-like types and %v fallback for value types (e.g. opamp-go httpConnection struct).

Types

type Agent

type Agent struct {
	Metadata AgentMetadata
	Spec     AgentSpec
	Status   AgentStatus
}

Agent is a domain model to control opamp agent by opampcommander.

func NewAgent

func NewAgent(instanceUID uuid.UUID, opts ...AgentOption) *Agent

NewAgent creates a new agent with the given instance UID. It initializes all fields with default values. You can optionally pass AgentOption functions to customize the agent.

func (*Agent) ApplyConnectionSettings

ApplyConnectionSettings applies connection settings to the agent from agent group.

func (*Agent) ApplyRemoteConfig

func (a *Agent) ApplyRemoteConfig(
	agentRemoteConfigName string,
	agentConfigFile AgentConfigFile,
) error

ApplyRemoteConfig applies a remote config to the agent.

func (*Agent) Clone

func (a *Agent) Clone() *Agent

Clone creates a deep copy of the Agent. This is useful for caching to prevent callers from mutating cached data.

func (*Agent) ConnectedServerID

func (a *Agent) ConnectedServerID() (string, error)

ConnectedServerID returns the server the agent is currently connected to.

func (*Agent) GetCondition

func (a *Agent) GetCondition(conditionType AgentConditionType) *AgentCondition

GetCondition returns the condition of the specified type.

func (*Agent) HasInstanceUID

func (a *Agent) HasInstanceUID() bool

HasInstanceUID checks if the agent has a valid instance UID.

func (*Agent) HasNewInstanceUID

func (a *Agent) HasNewInstanceUID() bool

HasNewInstanceUID checks if there is a new instance UID to inform the agent.

func (*Agent) HasNewPackages

func (a *Agent) HasNewPackages() bool

HasNewPackages checks if there are new packages available for the agent.

func (*Agent) HasPendingServerMessages

func (a *Agent) HasPendingServerMessages() bool

HasPendingServerMessages checks if there are any pending server messages for the agent.

func (*Agent) HasRemoteConfig

func (a *Agent) HasRemoteConfig() bool

HasRemoteConfig checks if the agent has remote configuration to apply.

func (*Agent) IsConditionTrue

func (a *Agent) IsConditionTrue(conditionType AgentConditionType) bool

IsConditionTrue checks if the specified condition type is true.

func (*Agent) IsConnected

func (a *Agent) IsConnected(_ context.Context) bool

IsConnected checks if the agent is currently connected.

func (*Agent) IsConnectedAt added in v0.1.40

func (a *Agent) IsConnectedAt(now time.Time, staleness time.Duration) bool

IsConnectedAt reports whether the agent is effectively connected at `now`, combining the explicit Status.Connected flag with heartbeat staleness.

The explicit flag captures genuine disconnect events (currently only fired on WebSocket close). The staleness check catches HTTP-polling agents that simply stop polling without any disconnect signal — their Status.Connected stays true after the last poll, but their LastReportedAt drifts past the staleness window.

func (*Agent) IsOpAMPConnectionSettingsSupported

func (a *Agent) IsOpAMPConnectionSettingsSupported() bool

IsOpAMPConnectionSettingsSupported checks if the agent supports OpAMP connection settings.

func (*Agent) IsOtherConnectionSettingsSupported

func (a *Agent) IsOtherConnectionSettingsSupported() bool

IsOtherConnectionSettingsSupported checks if the agent supports other connection settings.

func (*Agent) IsOwnLogsSupported

func (a *Agent) IsOwnLogsSupported() bool

IsOwnLogsSupported checks if the agent supports reporting its own logs.

func (*Agent) IsOwnMetricsSupported

func (a *Agent) IsOwnMetricsSupported() bool

IsOwnMetricsSupported checks if the agent supports reporting its own metrics.

func (*Agent) IsOwnTracesSupported

func (a *Agent) IsOwnTracesSupported() bool

IsOwnTracesSupported checks if the agent supports reporting its own traces.

func (*Agent) IsRemoteConfigSupported

func (a *Agent) IsRemoteConfigSupported() bool

IsRemoteConfigSupported checks if the agent supports remote configuration.

func (*Agent) IsRestartSupported

func (a *Agent) IsRestartSupported() bool

IsRestartSupported checks if the agent supports restart command.

func (*Agent) MarkConnected

func (a *Agent) MarkConnected(triggeredBy string)

MarkConnected marks the agent as connected and updates the connection condition.

func (*Agent) MarkDisconnected

func (a *Agent) MarkDisconnected(triggeredBy string)

MarkDisconnected marks the agent as disconnected and updates the connection condition.

func (*Agent) NeedFullStateCommand

func (a *Agent) NeedFullStateCommand() bool

NeedFullStateCommand checks if the agent needs to send a ReportFullState command.

func (*Agent) NewInstanceUID

func (a *Agent) NewInstanceUID() []byte

NewInstanceUID returns the new instance UID to inform the agent.

func (*Agent) RecordInstanceUIDConflict added in v0.1.40

func (a *Agent) RecordInstanceUIDConflict(
	now time.Time,
	oldInstanceUID, newInstanceUID uuid.UUID,
	conflictReason, triggeredBy string,
)

RecordInstanceUIDConflict audits an InstanceUIDConflict event on the agent, always replacing any prior conflict condition so the recorded message reflects the most recent occurrence (SetCondition would skip refreshes when the status is unchanged).

func (*Agent) RecordLastReported

func (a *Agent) RecordLastReported(by *Server, lastReportedAt time.Time, sequenceNum uint64)

RecordLastReported updates the last communicated time and server of the agent.

func (*Agent) ReportAvailableComponents

func (a *Agent) ReportAvailableComponents(availableComponents *AgentAvailableComponents) error

ReportAvailableComponents is a method to report the available components of the agent.

func (*Agent) ReportCapabilities

func (a *Agent) ReportCapabilities(capabilities *agent.Capabilities) error

ReportCapabilities is a method to report the capabilities of the agent.

func (*Agent) ReportComponentHealth

func (a *Agent) ReportComponentHealth(health *AgentComponentHealth) error

ReportComponentHealth is a method to report the component health of the agent.

func (*Agent) ReportConnectionSettingsStatus

func (a *Agent) ReportConnectionSettingsStatus(status *AgentConnectionSettingsStatus) error

ReportConnectionSettingsStatus is a method to report the connection settings status of the agent.

func (*Agent) ReportCustomCapabilities

func (a *Agent) ReportCustomCapabilities(capabilities *AgentCustomCapabilities) error

ReportCustomCapabilities is a method to report the custom capabilities of the agent.

func (*Agent) ReportDescription

func (a *Agent) ReportDescription(desc *agent.Description) error

ReportDescription is a method to report the description of the agent.

func (*Agent) ReportEffectiveConfig

func (a *Agent) ReportEffectiveConfig(config *AgentEffectiveConfig) error

ReportEffectiveConfig is a method to report the effective configuration of the agent.

func (*Agent) ReportPackageStatuses

func (a *Agent) ReportPackageStatuses(status *AgentPackageStatuses) error

ReportPackageStatuses is a method to report the package statuses of the agent.

func (*Agent) ReportRemoteConfigStatus

func (a *Agent) ReportRemoteConfigStatus(status *AgentRemoteConfigStatus) error

ReportRemoteConfigStatus is a method to report the remote configuration status of the agent.

func (*Agent) SetCondition

func (a *Agent) SetCondition(
	conditionType AgentConditionType,
	status AgentConditionStatus,
	triggeredBy, message string,
)

SetCondition sets or updates a condition in the agent's status.

func (*Agent) SetLogsConnectionSettings

func (a *Agent) SetLogsConnectionSettings(endpoint string, opts ...ConnectionOption) error

SetLogsConnectionSettings sets logs connection settings for the agent.

func (*Agent) SetMetricsConnectionSettings

func (a *Agent) SetMetricsConnectionSettings(endpoint string, opts ...ConnectionOption) error

SetMetricsConnectionSettings sets metrics connection settings for the agent.

func (*Agent) SetOpAMPConnectionSettings

func (a *Agent) SetOpAMPConnectionSettings(endpoint string, opts ...ConnectionOption) error

SetOpAMPConnectionSettings sets OpAMP connection settings for the agent.

func (*Agent) SetOtherConnectionSettings

func (a *Agent) SetOtherConnectionSettings(name, endpoint string, opts ...ConnectionOption) error

SetOtherConnectionSettings sets other connection settings for the agent.

func (*Agent) SetRestartRequired

func (a *Agent) SetRestartRequired(requiredAt time.Time) error

SetRestartRequired sets the restart required information for the agent.

func (*Agent) SetTracesConnectionSettings

func (a *Agent) SetTracesConnectionSettings(endpoint string, opts ...ConnectionOption) error

SetTracesConnectionSettings sets traces connection settings for the agent.

func (*Agent) ShouldBeRestarted

func (a *Agent) ShouldBeRestarted() bool

ShouldBeRestarted checks if the agent should be restarted to apply a command that requires a restart.

func (*Agent) UpdateLastCommunicationInfo

func (a *Agent) UpdateLastCommunicationInfo(now time.Time, connection *Connection)

UpdateLastCommunicationInfo updates the last communication info of the agent.

type AgentAvailableComponents

type AgentAvailableComponents struct {
	Components map[string]ComponentDetails
	Hash       []byte
}

AgentAvailableComponents is a map of available components.

type AgentCertificate

type AgentCertificate struct {
	Cert       []byte
	PrivateKey []byte
	CaCert     []byte
}

AgentCertificate represents a certificate used by an agent for secure communications.

type AgentComponentHealth

type AgentComponentHealth struct {
	// Set to true if the Agent is up and healthy.
	Healthy bool

	// Timestamp since the Agent is up
	StartTime time.Time

	// Human-readable error message if the Agent is in erroneous state. SHOULD be set when healthy==false.
	LastError string

	// Component status represented as a string.
	// The status values are defined by agent-specific semantics and not at the protocol level.
	Status string

	// The time when the component status was observed.
	StatusTime time.Time

	// A map to store more granular, sub-component health.
	// It can nest as deeply as needed to describe the underlying system.
	ComponentHealthMap map[string]AgentComponentHealth
}

AgentComponentHealth is a domain model to control opamp agent component health.

type AgentCondition

type AgentCondition struct {
	// Type is the type of the condition.
	Type AgentConditionType
	// LastTransitionTime is the last time the condition transitioned.
	LastTransitionTime time.Time
	// Status is the status of the condition.
	Status AgentConditionStatus
	// Reason is the identifier of the user or system that triggered the condition.
	Reason string
	// Message is a human readable message indicating details about the condition.
	Message string
}

AgentCondition represents a condition of an agent.

type AgentConditionStatus

type AgentConditionStatus string

AgentConditionStatus represents the status of an agent condition.

const (
	// AgentConditionStatusTrue represents a true condition status.
	AgentConditionStatusTrue AgentConditionStatus = "True"
	// AgentConditionStatusFalse represents a false condition status.
	AgentConditionStatusFalse AgentConditionStatus = "False"
	// AgentConditionStatusUnknown represents an unknown condition status.
	AgentConditionStatusUnknown AgentConditionStatus = "Unknown"
)

type AgentConditionType

type AgentConditionType string

AgentConditionType represents the type of an agent condition.

const (
	// AgentConditionTypeConnected represents the condition when the agent is connected.
	AgentConditionTypeConnected AgentConditionType = "Connected"
	// AgentConditionTypeHealthy represents the condition when the agent is healthy.
	AgentConditionTypeHealthy AgentConditionType = "Healthy"
	// AgentConditionTypeConfigured represents the condition when the agent has been configured.
	AgentConditionTypeConfigured AgentConditionType = "Configured"
	// AgentConditionTypeRegistered represents the condition when the agent has been registered.
	AgentConditionTypeRegistered AgentConditionType = "Registered"
	// AgentConditionTypeInstanceUIDConflict records that another agent attempted to use this
	// agent's instanceUID and was redirected to a freshly issued one.
	AgentConditionTypeInstanceUIDConflict AgentConditionType = "InstanceUIDConflict"
)

type AgentConfigFile

type AgentConfigFile struct {
	// The body field contains the raw bytes of the configuration file.
	// The content, format and encoding of the raw bytes is Agent type-specific and is outside the concerns of OpAMP
	// protocol.
	Body []byte

	// content_type is an optional field. It is a MIME Content-Type that describes what's contained in the body field,
	// for example "text/yaml". The content_type reported in the Effective Configuration in the Agent's status report may
	// be used for example by the Server to visualize the reported configuration nicely in a UI.
	ContentType string
}

AgentConfigFile is a configuration file.

type AgentConfigMap

type AgentConfigMap struct {
	// The config_map field of the AgentConfigSet message is a map of configuration files, where keys are file names.
	ConfigMap map[string]AgentConfigFile
}

AgentConfigMap is a map of configuration files.

type AgentConnectionSettingsStatus

type AgentConnectionSettingsStatus struct {
	LastConnectionSettingsHash []byte
	Status                     ConnectionSettingsStatus
	ErrorMessage               string
}

AgentConnectionSettingsStatus is the status of the connection settings.

type AgentCustomCapabilities

type AgentCustomCapabilities struct {
	Capabilities []string
}

AgentCustomCapabilities is a list of custom capabilities that the Agent supports.

type AgentEffectiveConfig

type AgentEffectiveConfig struct {
	ConfigMap AgentConfigMap
}

AgentEffectiveConfig is the effective configuration of the agent.

type AgentGroup

type AgentGroup struct {
	Metadata AgentGroupMetadata
	Spec     AgentGroupSpec
	Status   AgentGroupStatus
}

AgentGroup represents a group of agents with their associated metadata.

func NewAgentGroup

func NewAgentGroup(
	namespace string,
	name string,
	attributes Attributes,
	createdAt time.Time,
	createdBy string,
) *AgentGroup

NewAgentGroup creates a new instance of AgentGroup with the provided namespace, name, attributes, createdAt timestamp, and createdBy identifier.

func (*AgentGroup) GetCreatedAt

func (ag *AgentGroup) GetCreatedAt() *time.Time

GetCreatedAt returns the timestamp when the agent group was created.

func (*AgentGroup) GetCreatedBy

func (ag *AgentGroup) GetCreatedBy() string

GetCreatedBy returns the identifier of the user or system that created the agent group.

func (*AgentGroup) GetDeletedAt

func (ag *AgentGroup) GetDeletedAt() *time.Time

GetDeletedAt returns the timestamp when the agent group was deleted.

func (*AgentGroup) GetDeletedBy

func (ag *AgentGroup) GetDeletedBy() *string

GetDeletedBy returns the identifier of the user or system that deleted the agent group.

func (*AgentGroup) HasAgentConnectionConfig

func (ag *AgentGroup) HasAgentConnectionConfig() bool

HasAgentConnectionConfig returns true if the agent group has connection configuration.

func (*AgentGroup) IsDeleted

func (ag *AgentGroup) IsDeleted() bool

IsDeleted returns true if the agent group is marked as deleted.

func (*AgentGroup) MarkDeleted

func (ag *AgentGroup) MarkDeleted(deletedAt time.Time, deletedBy string)

MarkDeleted marks the agent group as deleted by setting deletedAt and adding a deleted condition.

type AgentGroupAgentRemoteConfig

type AgentGroupAgentRemoteConfig struct {
	// AgentRemoteConfigName is the name of a standalone remote configuration resource.
	AgentRemoteConfigName *string
	// AgentRemoteConfigSpec is the remote configuration to be applied to agents in this group.
	AgentRemoteConfigSpec *AgentRemoteConfigSpec

	// AgentRemoteConfigRef is a reference to a standalone remote configuration resource.
	AgentRemoteConfigRef *string
}

AgentGroupAgentRemoteConfig represents a remote configuration for agents in the group.

type AgentGroupConnectionConfig

type AgentGroupConnectionConfig struct {
	OpAMPConnection  *OpAMPConnectionSettings
	OwnMetrics       *TelemetryConnectionSettings
	OwnLogs          *TelemetryConnectionSettings
	OwnTraces        *TelemetryConnectionSettings
	OtherConnections map[string]OtherConnectionSettings
}

AgentGroupConnectionConfig represents connection settings for agents in the group.

type AgentGroupMetadata

type AgentGroupMetadata struct {
	// Namespace is the namespace of the agent group.
	// Together with Name, it forms the unique identity of the agent group.
	Namespace string
	// Name is the name of the agent group.
	Name string
	// Attributes is a map of attributes associated with the agent group.
	Attributes Attributes
	// CreatedAt is the timestamp when the agent group was created.
	CreatedAt time.Time
	// DeletedAt is the timestamp when the agent group was soft deleted.
	// If is zero, the agent group is not deleted.
	DeletedAt time.Time
}

AgentGroupMetadata represents metadata information for an agent group.

type AgentGroupSpec

type AgentGroupSpec struct {
	// Priority is the priority of the agent group.
	// When multiple agent groups match an agent, the one with the highest priority is applied.
	Priority int

	// Selector is a set of criteria used to select agents for the group.
	Selector AgentSelector

	// AgentRemoteConfig is a single remote configuration (for API compatibility).
	//
	// Deprecated: Use AgentRemoteConfigs for multiple configs.
	AgentRemoteConfig *AgentGroupAgentRemoteConfig

	// AgentRemoteConfigs is a list of remote configurations for the agent group.
	AgentRemoteConfigs []AgentGroupAgentRemoteConfig

	// AgentConnection settings for agents in this group.
	AgentConnectionConfig *AgentGroupConnectionConfig
}

AgentGroupSpec represents the specification of an agent group.

type AgentGroupStatus

type AgentGroupStatus struct {
	// NumAgents is the total number of agents in the agent group.
	// NumAgents = NumConnectedAgents + NumNotConnectedAgents
	NumAgents int

	// NumConnectedAgents is the number of connected agents in the agent group.
	// NumConnectedAgents = NumHealthyAgents + NumUnhealthyAgents
	NumConnectedAgents int

	// NumHealthyAgents is the number of healthy agents in the agent group.
	NumHealthyAgents int

	// NumUnhealthyAgents is the number of unhealthy agents in the agent group.
	NumUnhealthyAgents int

	// NumNotConnectedAgents is the number of not connected agents in the agent group.
	NumNotConnectedAgents int

	// Conditions is a list of conditions that apply to the agent group.
	Conditions []model.Condition
}

AgentGroupStatus represents the status of an agent group.

type AgentMetadata

type AgentMetadata struct {
	// InstanceUID is a unique identifier for the agent instance.
	// It is generated by the agent and should not change between restarts of the agent.
	InstanceUID uuid.UUID

	// Namespace is the namespace the agent belongs to.
	// Derived from the "service.namespace" identifying attribute.
	// Defaults to "default" if not specified.
	Namespace string

	// Description is a agent description defined in the opamp protocol.
	// It is set by the agent and should not change between restarts of the agent.
	// It can be changed by the agent at any time.
	Description agent.Description

	// Capabilities is a agent capabilities defined in the opamp protocol.
	Capabilities agent.Capabilities

	// CustomCapabilities is a list of custom capabilities that the Agent supports.
	CustomCapabilities AgentCustomCapabilities
}

AgentMetadata is a domain model to control opamp agent metadata.

func (*AgentMetadata) IsComplete

func (am *AgentMetadata) IsComplete() bool

IsComplete checks if all required metadata fields are populated. Returns true if the agent has reported its description and capabilities.

type AgentOpAMPConnectionSettings

type AgentOpAMPConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	Certificate         *AgentCertificate
}

AgentOpAMPConnectionSettings represents OpAMP connection settings for an agent.

type AgentOption

type AgentOption func(*Agent)

AgentOption is a function that configures an Agent.

func WithAvailableComponents

func WithAvailableComponents(availableComponents *AgentAvailableComponents) AgentOption

WithAvailableComponents sets the agent available components.

func WithCapabilities

func WithCapabilities(capabilities *agent.Capabilities) AgentOption

WithCapabilities sets the agent capabilities.

func WithComponentHealth

func WithComponentHealth(componentHealth *AgentComponentHealth) AgentOption

WithComponentHealth sets the agent component health.

func WithCustomCapabilities

func WithCustomCapabilities(customCapabilities *AgentCustomCapabilities) AgentOption

WithCustomCapabilities sets the agent custom capabilities.

func WithDescription

func WithDescription(description *agent.Description) AgentOption

WithDescription sets the agent description.

func WithEffectiveConfig

func WithEffectiveConfig(effectiveConfig *AgentEffectiveConfig) AgentOption

WithEffectiveConfig sets the agent effective config.

func WithPackageStatuses

func WithPackageStatuses(packageStatuses *AgentPackageStatuses) AgentOption

WithPackageStatuses sets the agent package statuses.

type AgentOtherConnectionSettings

type AgentOtherConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	Certificate         *AgentCertificate
}

AgentOtherConnectionSettings represents other connection settings for an agent.

type AgentPackage

type AgentPackage struct {
	Metadata AgentPackageMetadata
	Spec     AgentPackageSpec
	Status   AgentPackageStatus
}

AgentPackage represents an agent package resource.

func (*AgentPackage) MarkAsCreated

func (a *AgentPackage) MarkAsCreated(createdAt time.Time, createdBy string)

MarkAsCreated marks the agent package as created by setting the CreatedAt timestamp.

func (*AgentPackage) MarkAsDeleted

func (a *AgentPackage) MarkAsDeleted(deletedAt time.Time, deletedBy string)

MarkAsDeleted marks the agent package as deleted by setting the DeletedAt timestamp.

type AgentPackageMetadata

type AgentPackageMetadata struct {
	Name       string
	Namespace  string
	Attributes Attributes
	// CreatedAt is the timestamp when the agent package was created.
	CreatedAt time.Time
	// DeletedAt is the timestamp when the agent package was soft deleted.
	// If nil, the agent package is not deleted.
	DeletedAt *time.Time
}

AgentPackageMetadata represents the metadata of an agent package.

type AgentPackageSpec

type AgentPackageSpec struct {
	PackageType string
	Version     string
	DownloadURL string
	ContentHash []byte
	Signature   []byte
	Headers     map[string]string
	Hash        []byte
}

AgentPackageSpec represents the specification of an agent package.

type AgentPackageStatus

type AgentPackageStatus struct {
	Conditions []model.Condition
}

AgentPackageStatus represents the status of an agent package.

type AgentPackageStatusEntry

type AgentPackageStatusEntry struct {
	Name                 string
	AgentHasVersion      string
	AgentHasHash         []byte
	ServerOfferedVersion string
	Status               AgentPackageStatusEnum
	ErrorMessage         string
}

AgentPackageStatusEntry is the status of a package.

type AgentPackageStatusEnum

type AgentPackageStatusEnum int32

AgentPackageStatusEnum is an enum that represents the status of a package.

type AgentPackageStatuses

type AgentPackageStatuses struct {
	Packages                     map[string]AgentPackageStatusEntry
	ServerProvidedAllPackgesHash []byte
	ErrorMessage                 string
}

AgentPackageStatuses is a map of package statuses.

type AgentRemoteConfig

type AgentRemoteConfig struct {
	Metadata AgentRemoteConfigMetadata
	Spec     AgentRemoteConfigSpec
	Status   AgentRemoteConfigResourceStatus
}

AgentRemoteConfig represents a standalone remote configuration resource. This is different from AgentRemoteConfig in agentgroup.go which is embedded in AgentGroup.

func (*AgentRemoteConfig) IsDeleted

func (arc *AgentRemoteConfig) IsDeleted() bool

IsDeleted returns true if the agent remote config is marked as deleted.

func (*AgentRemoteConfig) MarkDeleted

func (arc *AgentRemoteConfig) MarkDeleted(deletedAt time.Time, deletedBy string)

MarkDeleted marks the agent remote config as deleted by adding a deleted condition.

type AgentRemoteConfigMetadata

type AgentRemoteConfigMetadata struct {
	Name       string
	Namespace  string
	Attributes Attributes
	CreatedAt  time.Time
	DeletedAt  *time.Time
}

AgentRemoteConfigMetadata contains metadata for the agent remote config resource.

type AgentRemoteConfigResourceStatus

type AgentRemoteConfigResourceStatus struct {
	Conditions []model.Condition
}

AgentRemoteConfigResourceStatus contains the status of the agent remote config resource.

type AgentRemoteConfigSpec

type AgentRemoteConfigSpec struct {
	// Value is the configuration content.
	Value []byte
	// ContentType is the MIME type of the configuration content.
	ContentType string
}

AgentRemoteConfigSpec contains the specification for the agent remote config resource.

type AgentRemoteConfigStatus

type AgentRemoteConfigStatus struct {
	LastRemoteConfigHash []byte
	Status               RemoteConfigStatus
	ErrorMessage         string
	LastUpdatedAt        time.Time
}

AgentRemoteConfigStatus is the status of the remote configuration.

type AgentRestartInfo

type AgentRestartInfo struct {
	// RequiredRestartedAt is the time when the agent is required to be
	// restarted to apply a command that requires a restart.
	RequiredRestartedAt time.Time
}

AgentRestartInfo is a domain model to control opamp agent restart information.

func (*AgentRestartInfo) ShouldBeRestarted

func (a *AgentRestartInfo) ShouldBeRestarted(agentStartTime time.Time) bool

ShouldBeRestarted checks if the agent should be restarted to apply a command that requires a restart.

type AgentSelector

type AgentSelector struct {
	// IdentifyingAttributes is a map of identifying attributes used to select agents.
	IdentifyingAttributes map[string]string
	// NonIdentifyingAttributes is a map of non-identifying attributes used to select agents.
	NonIdentifyingAttributes map[string]string
}

AgentSelector defines the criteria for selecting agent.

type AgentSpec

type AgentSpec struct {
	// NewInstanceUID is a new instance UID to inform the agent of its new identity.
	NewInstanceUID uuid.UUID

	// RestartInfo contains information about agent restart.
	RestartInfo *AgentRestartInfo

	// ConnectionInfo is the connection information for the agent.
	ConnectionInfo *ConnectionInfo

	// RemoteConfig is the remote configuration for the agent.
	RemoteConfig *AgentSpecRemoteConfig

	// PackagesAvailable is the packages available for the agent.
	PackagesAvailable *AgentSpecPackage
}

AgentSpec is a domain model to control opamp agent spec.

type AgentSpecPackage

type AgentSpecPackage struct {
	// Packages is a list of package names available for the agent.
	Packages []string
}

AgentSpecPackage represents the package specification for an agent.

func (*AgentSpecPackage) Hash

func (a *AgentSpecPackage) Hash() (vo.Hash, error)

Hash computes the hash of the agent spec packages.

type AgentSpecRemoteConfig

type AgentSpecRemoteConfig struct {
	ConfigMap AgentConfigMap
}

AgentSpecRemoteConfig represents the remote config specification for an agent.

type AgentStatus

type AgentStatus struct {
	RemoteConfigStatus       AgentRemoteConfigStatus
	ConnectionSettingsStatus AgentConnectionSettingsStatus
	EffectiveConfig          AgentEffectiveConfig
	PackageStatuses          AgentPackageStatuses
	ComponentHealth          AgentComponentHealth
	AvailableComponents      AgentAvailableComponents

	// Conditions is a list of conditions that apply to the agent.
	// WARNING: Do NOT use Conditions for MongoDB queries or aggregations.
	// The Conditions field can be null which causes MongoDB aggregation errors
	// (e.g., $anyElementTrue's argument must be an array, but is null).
	// Use the following indexed fields instead:
	// - Connected (bool): for connection status queries
	// - ComponentHealth.Healthy (bool): for health status queries
	Conditions []AgentCondition

	Connected      bool
	ConnectionType ConnectionType

	SequenceNum    uint64
	LastReportedAt time.Time
	// LastReportedTo is the ID of the server the agent last reported to.
	// When you want to get Server object, use `GetServerByID` function from ServerUsecase.
	LastReportedTo string
}

AgentStatus is a domain model to control opamp agent status.

type AgentTelemetryConnectionSettings

type AgentTelemetryConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	Certificate         *AgentCertificate
}

AgentTelemetryConnectionSettings represents telemetry connection settings for an agent.

type Attributes

type Attributes map[string]string

Attributes represents a map of attributes for the agent group.

func OfAttributes

func OfAttributes(attributes map[string]string) Attributes

OfAttributes creates an Attributes instance from a map of attributes.

type Certificate

type Certificate struct {
	Metadata CertificateMetadata
	Spec     CertificateSpec
	Status   CertificateStatus
}

Certificate represents a TLS certificate used for secure communications.

func (*Certificate) MarkAsDeleted

func (c *Certificate) MarkAsDeleted(deletedAt time.Time, deletedBy string)

MarkAsDeleted marks the certificate as deleted.

func (*Certificate) ToAgentCertificate

func (c *Certificate) ToAgentCertificate() *AgentCertificate

ToAgentCertificate converts the certificate to an AgentCertificate.

type CertificateMetadata

type CertificateMetadata struct {
	Name      string
	Namespace string
	// Attributes are optional key-value pairs for the certificate.
	Attributes Attributes
	// CreatedAt is the timestamp when the certificate was created.
	CreatedAt time.Time
	// DeletedAt is the timestamp when the certificate was soft deleted.
	// If zero, the certificate is not deleted.
	DeletedAt time.Time
}

CertificateMetadata represents metadata information for a certificate.

type CertificateSpec

type CertificateSpec struct {
	Cert       []byte
	PrivateKey []byte
	CaCert     []byte
}

CertificateSpec represents the specification of a certificate.

type CertificateStatus

type CertificateStatus struct {
	Conditions []model.Condition
}

CertificateStatus represents the status of a certificate.

type ComponentDetails

type ComponentDetails struct {
	Metadata        map[string]string
	SubComponentMap map[string]ComponentDetails
}

ComponentDetails is a details of a component.

type Connection

type Connection struct {
	// Key is the unique identifier for the connection.
	// It should be unique across all connections to use as a key in a map.
	// Normally, it is [types.Connection] by OpAMP.
	ID any

	// Type is the type of the connection.
	Type ConnectionType

	// UID is the unique identifier for the connection.
	// It is used to identify the connection in the database.
	UID uuid.UUID

	// InstanceUID is id of the agent.
	InstanceUID uuid.UUID

	// Namespace is the namespace the connection belongs to.
	// It is derived from the connected agent's namespace.
	Namespace string

	// LastCommunicatedAt is the last time the connection was communicated with.
	LastCommunicatedAt time.Time
}

Connection represents a connection to an agent. This is a pure domain model containing only metadata about the connection. The actual WebSocket connection object is managed separately by the WebSocketRegistry.

func NewConnection

func NewConnection(id any, typ ConnectionType) *Connection

NewConnection creates a new Connection instance with the given ID and type.

func (*Connection) IDString

func (conn *Connection) IDString() string

IDString returns a string value In some cases, a unique string id instead of any type.

func (*Connection) IsAlive

func (conn *Connection) IsAlive(now time.Time) bool

IsAlive returns true if the connection is alive.

func (*Connection) IsAnonymous

func (conn *Connection) IsAnonymous() bool

IsAnonymous returns true if the connection is anonymous.

func (*Connection) IsManaged

func (conn *Connection) IsManaged() bool

IsManaged returns true if the connection is managed.

func (*Connection) SetInstanceUID

func (conn *Connection) SetInstanceUID(instanceUID uuid.UUID)

SetInstanceUID sets the instance UID of the connection.

func (*Connection) SetNamespace

func (conn *Connection) SetNamespace(namespace string)

SetNamespace sets the namespace of the connection.

type ConnectionInfo

type ConnectionInfo struct {
	Hash vo.Hash
	// contains filtered or unexported fields
}

ConnectionInfo represents connection information for the agent.

func NewConnectionInfo

NewConnectionInfo creates a new ConnectionInfo with the given settings.

func (*ConnectionInfo) HasConnectionSettings

func (ci *ConnectionInfo) HasConnectionSettings() bool

HasConnectionSettings checks if there are any connection settings configured.

func (*ConnectionInfo) OpAMP

OpAMP returns the OpAMP connection settings.

func (*ConnectionInfo) OtherConnections

func (ci *ConnectionInfo) OtherConnections() map[string]AgentOtherConnectionSettings

OtherConnections returns the other connection settings.

func (*ConnectionInfo) OwnLogs

OwnLogs returns the own logs connection settings.

func (*ConnectionInfo) OwnMetrics

OwnMetrics returns the own metrics connection settings.

func (*ConnectionInfo) OwnTraces

OwnTraces returns the own traces connection settings.

func (*ConnectionInfo) SetOpAMP

func (ci *ConnectionInfo) SetOpAMP(settings AgentOpAMPConnectionSettings) error

SetOpAMP sets the OpAMP connection settings.

func (*ConnectionInfo) SetOtherConnection

func (ci *ConnectionInfo) SetOtherConnection(name string, settings AgentOtherConnectionSettings) error

SetOtherConnection sets the other connection settings.

func (*ConnectionInfo) SetOwnLogs

func (ci *ConnectionInfo) SetOwnLogs(settings AgentTelemetryConnectionSettings) error

SetOwnLogs sets the own logs connection settings.

func (*ConnectionInfo) SetOwnMetrics

func (ci *ConnectionInfo) SetOwnMetrics(settings AgentTelemetryConnectionSettings) error

SetOwnMetrics sets the own metrics connection settings.

func (*ConnectionInfo) SetOwnTraces

func (ci *ConnectionInfo) SetOwnTraces(settings AgentTelemetryConnectionSettings) error

SetOwnTraces sets the own traces connection settings.

type ConnectionOption

type ConnectionOption interface {
	// contains filtered or unexported methods
}

ConnectionOption is a function option for configuring connection settings.

func WithCertificate

func WithCertificate(certificate *AgentCertificate) ConnectionOption

WithCertificate sets the certificate for the connection.

func WithHeaders

func WithHeaders(headers map[string][]string) ConnectionOption

WithHeaders sets the headers for the connection.

type ConnectionOptionFunc

type ConnectionOptionFunc func(*connectionSettings)

ConnectionOptionFunc is a function that implements ConnectionOption.

type ConnectionSettingsStatus

type ConnectionSettingsStatus int32

ConnectionSettingsStatus represents the status of connection settings.

const (
	// ConnectionSettingsStatusUnset means status is not set.
	ConnectionSettingsStatusUnset ConnectionSettingsStatus = 0
	// ConnectionSettingsStatusApplied means connection settings have been applied.
	ConnectionSettingsStatusApplied ConnectionSettingsStatus = 1
	// ConnectionSettingsStatusApplying means connection settings are being applied.
	ConnectionSettingsStatusApplying ConnectionSettingsStatus = 2
	// ConnectionSettingsStatusFailed means applying connection settings failed.
	ConnectionSettingsStatusFailed ConnectionSettingsStatus = 3
)

type ConnectionType

type ConnectionType int

ConnectionType represents the type of the connection.

const (
	// ConnectionTypeUnknown is the unknown type.
	ConnectionTypeUnknown ConnectionType = iota
	// ConnectionTypeHTTP is the HTTP type.
	ConnectionTypeHTTP
	// ConnectionTypeWebSocket is the WebSocket type.
	ConnectionTypeWebSocket
)

func ConnectionTypeFromString

func ConnectionTypeFromString(s string) ConnectionType

ConnectionTypeFromString converts a string to a ConnectionType.

func (ConnectionType) String

func (ct ConnectionType) String() string

String returns the string representation of the ConnectionType.

type Host

type Host struct{}

Host is a value object that represents a host.

type Namespace

type Namespace struct {
	Metadata NamespaceMetadata
	Status   NamespaceStatus
}

Namespace represents a namespace resource that groups agent groups.

func NewNamespace

func NewNamespace(name string) *Namespace

NewNamespace creates a new Namespace with the given name.

func (*Namespace) IsDeleted

func (n *Namespace) IsDeleted() bool

IsDeleted returns true if the namespace is soft deleted.

func (*Namespace) MarkAsCreated

func (n *Namespace) MarkAsCreated(createdAt time.Time, createdBy string)

MarkAsCreated marks the namespace as created by setting the CreatedAt timestamp.

func (*Namespace) MarkAsDeleted

func (n *Namespace) MarkAsDeleted(deletedAt time.Time, deletedBy string)

MarkAsDeleted marks the namespace as deleted by setting the DeletedAt timestamp.

type NamespaceMetadata

type NamespaceMetadata struct {
	Name        string
	Labels      map[string]string
	Annotations map[string]string
	CreatedAt   time.Time
	DeletedAt   *time.Time
}

NamespaceMetadata represents the metadata of a namespace.

type NamespaceStatus

type NamespaceStatus struct {
	Conditions []model.Condition
}

NamespaceStatus represents the status of a namespace.

type OpAMPConnectionSettings

type OpAMPConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	CertificateName     *string
}

OpAMPConnectionSettings represents OpAMP connection settings.

type OtherConnectionSettings

type OtherConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	CertificateName     *string
}

OtherConnectionSettings represents other connection settings.

type RemoteConfigStatus

type RemoteConfigStatus int32

RemoteConfigStatus is generated from agentToServer of OpAMP.

const (
	// RemoteConfigStatusUnset means status is not set.
	RemoteConfigStatusUnset RemoteConfigStatus = 0
	// RemoteConfigStatusApplied means remote config has been applied.
	RemoteConfigStatusApplied RemoteConfigStatus = 1
	// RemoteConfigStatusApplying means remote config is being applied.
	RemoteConfigStatusApplying RemoteConfigStatus = 2
	// RemoteConfigStatusFailed means applying remote config failed.
	RemoteConfigStatusFailed RemoteConfigStatus = 3
)

RemoteConfigStatus constants.

func (RemoteConfigStatus) String

func (s RemoteConfigStatus) String() string

String returns the string representation of the status.

type Server

type Server struct {
	// ID is the unique identifier for the server.
	ID string
	// LastHeartbeatAt is the last time the server sent a heartbeat.
	LastHeartbeatAt time.Time
	// Conditions is a list of conditions that apply to the server.
	Conditions []model.Condition
}

Server represents a server that an agent communicates with. It contains the server's unique identifier and liveness information.

func (*Server) Clone

func (s *Server) Clone() *Server

Clone creates a deep copy of the Server.

func (*Server) GetCondition

func (s *Server) GetCondition(conditionType model.ConditionType) *model.Condition

GetCondition returns the condition of the specified type.

func (*Server) GetRegisteredAt

func (s *Server) GetRegisteredAt() *time.Time

GetRegisteredAt returns the time when the server was registered.

func (*Server) GetRegisteredBy

func (s *Server) GetRegisteredBy() string

GetRegisteredBy returns the reason/actor who registered the server.

func (*Server) IsAlive

func (s *Server) IsAlive(now time.Time, timeout time.Duration) bool

IsAlive returns true if the server is alive based on the heartbeat timeout. A server is considered alive if its last heartbeat was within the timeout period.

func (*Server) IsConditionTrue

func (s *Server) IsConditionTrue(conditionType model.ConditionType) bool

IsConditionTrue checks if the specified condition type is true.

func (*Server) MarkRegistered

func (s *Server) MarkRegistered(reason string)

MarkRegistered marks the server as registered.

func (*Server) SetCondition

func (s *Server) SetCondition(conditionType model.ConditionType, status model.ConditionStatus, reason, message string)

SetCondition sets or updates a condition in the server's status.

type TelemetryConnectionSettings

type TelemetryConnectionSettings struct {
	DestinationEndpoint string
	Headers             map[string][]string
	CertificateName     *string
}

TelemetryConnectionSettings represents telemetry connection settings.

Directories

Path Synopsis
Package agent provides domain models for the agent
Package agent provides domain models for the agent
Package serverevent defines server-to-server event models.
Package serverevent defines server-to-server event models.

Jump to

Keyboard shortcuts

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