aiven

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_SHARED_BUFFERS_PERCENTAGE = 20.0
	DEFAULT_PG_STAT_MONITOR_ENABLE    = false
)
View Source
const (
	DEFAULT_METRIC_RESOLUTION_SECONDS = 30
	DEFAULT_CONFIG_KEY                = "aiven"
)

Variables

I'm not confident this will always be the only set of names, nor am I confident they will always exist. ['cpu_usage', 'disk_usage', 'diskio_read', 'diskio_writes', 'load_average', 'mem_available', 'mem_usage', 'net_receive', 'net_send'] TODO(eddiebergman): I wasn't sure on the naming, as the units are missing from some of these metrics, and I tried to match pre-existing ones where possible.

Functions

func AivenCollectors

func AivenCollectors(adapter *AivenPostgreSQLAdapter) []agent.MetricCollector

AivenCollectors returns the metrics collectors for Aiven PostgreSQL

func AivenHardwareInfo

func AivenHardwareInfo(
	client *aivenclient.Client,
	projectName string,
	serviceName string,
	metricResolution time.Duration,
	config Config,
	State *State,
	logger *logrus.Logger,
) func(ctx context.Context, state *agent.MetricsState) error

AivenHardwareInfo collects hardware metrics for Aiven PostgreSQL

func DetectConfigFromConfigFile

func DetectConfigFromConfigFile() bool

func DetectConfigFromEnv

func DetectConfigFromEnv() bool

Types

type AivenPostgreSQLAdapter

type AivenPostgreSQLAdapter struct {
	agent.CommonAgent
	Config            Config
	Client            aivenclient.Client
	State             *State
	GuardrailSettings guardrails.Config
	PGDriver          *pgPool.Pool
	PGVersion         string
}

AivenPostgreSQLAdapter represents an adapter for connecting to Aiven PostgreSQL services

func CreateAivenPostgreSQLAdapter

func CreateAivenPostgreSQLAdapter() (*AivenPostgreSQLAdapter, error)

CreateAivenPostgreSQLAdapter creates a new Aiven PostgreSQL adapter

func (*AivenPostgreSQLAdapter) ApplyConfig

func (adapter *AivenPostgreSQLAdapter) ApplyConfig(proposedConfig *agent.ProposedConfigResponse) error

ApplyConfig applies configuration changes to the Aiven PostgreSQL service

func (*AivenPostgreSQLAdapter) GetActiveConfig

func (adapter *AivenPostgreSQLAdapter) GetActiveConfig() (agent.ConfigArraySchema, error)

GetActiveConfig returns the active configuration for the Aiven API as well as through PostgreSQL

func (*AivenPostgreSQLAdapter) GetSystemInfo

func (adapter *AivenPostgreSQLAdapter) GetSystemInfo() ([]metrics.FlatValue, error)

GetSystemInfo returns system information for the Aiven PostgreSQL service

func (*AivenPostgreSQLAdapter) Guardrails

func (adapter *AivenPostgreSQLAdapter) Guardrails() *guardrails.Signal

Guardrails implements resource usage guardrails Aiven only provides 30 second resolution data for hardware info, which we need for guardrails.

type Config

type Config struct {
	APIToken         string        `mapstructure:"AIVEN_API_TOKEN" validate:"required"`
	ProjectName      string        `mapstructure:"AIVEN_PROJECT_NAME" validate:"required"`
	ServiceName      string        `mapstructure:"AIVEN_SERVICE_NAME" validate:"required"`
	MetricResolution time.Duration `mapstructure:"metric_resolution_seconds" validate:"required"`
	// NOTE: If specified, we are able to use the
	// session refresh hack. Not documented.
	DatabaseName string `mapstructure:"database_name"`
}

func ConfigFromViper

func ConfigFromViper(key *string) (Config, error)

type FetchMetricJSONData

type FetchMetricJSONData struct {
	Data struct {
		Cols []Schema `json:"cols" validate:"required"`
		Rows [][]any  `json:"rows" validate:"required"` // 1st element is Schema, rest are values with length of Cols
	} `json:"data" validate:"required"`
	MaxTimestamp int64 `json:"max_timestamp" validate:"required"` // seconds since epoch
	TotalSeries  int64 `json:"total_series"`                      // How many rows there are I guess?
	Hints        struct {
		Title string `json:"title"`
	} `json:"hints"` // Additional metadata like title
}

type FetchMetricsJSONScheme

type FetchMetricsJSONScheme map[string]FetchMetricJSONData

type FetchedMetricsIn

type FetchedMetricsIn struct {
	ProjectName string
	ServiceName string
	Client      *aiven.Client
	Logger      *log.Logger
	Period      service.PeriodType
	Metrics     []MetricKnownName
}

type FetchedMetricsOut

type FetchedMetricsOut map[MetricKnownName]MaybeParsedMetric

func GetFetchedMetrics

func GetFetchedMetrics(
	ctx context.Context,
	in FetchedMetricsIn,
) (FetchedMetricsOut, error)

Fetches all metrics from Aiven and returns them as a map of metric name to ParsedMetric For any metrics that error, we log the error and return nil for that metric

type Hardware

type Hardware struct {
	TotalMemoryBytes int64
	NumCPUs          int
	LastChecked      time.Time
}

Aiven interfaces

type InitialServiceLevelParameters

type InitialServiceLevelParameters struct {
	InitialSharedBuffersPercentage float64
	InitialPGStatMonitorEnable     bool
}

type MaybeParsedMetric

type MaybeParsedMetric struct {
	ParsedMetric
	Error error
}

type MetricKnownName

type MetricKnownName string
const (
	CPU_USAGE_KEY      MetricKnownName = "cpu_usage"
	DISK_USAGE_KEY     MetricKnownName = "disk_usage"
	DISK_IO_READ_KEY   MetricKnownName = "diskio_read"
	DISK_IO_WRITES_KEY MetricKnownName = "diskio_writes"
	LOAD_AVERAGE_KEY   MetricKnownName = "load_average"
	MEM_AVAILABLE_KEY  MetricKnownName = "mem_available"
	MEM_USAGE_KEY      MetricKnownName = "mem_usage"
	NET_RECEIVE_KEY    MetricKnownName = "net_receive"
	NET_SEND_KEY       MetricKnownName = "net_send"
)

type ModifyLevel

type ModifyLevel string
const (
	ModifyServiceLevel ModifyLevel = "service_level"  // Can modify via service level config Aiven API
	ModifyUserPGConfig ModifyLevel = "user_pg_config" // Can modify via user config Aiven API, prefer over ModifyAlterDB, no restart
	// ModifyAlterDB      ModifyLevel = "alter_db"       // Can modify with ALTER DATABASE <dbname> SET <param> = <value>, requires restart
	NoModify ModifyLevel = "no_modify" // Can not modify at all
)

type ParsedMetric

type ParsedMetric struct {
	Name      MetricKnownName
	Value     any
	MetricDef metrics.MetricDef
	Timestamp time.Time
}

FetchedHardwareMetrics is a struct that contains the latest values for each metric and the maximum known timestamp. In theory the `MaximumKnownTimestamp` is the same for all metrics, but we store it separately for each metric as this is not gauranteed.

func (ParsedMetric) AsFlatValue added in v0.3.3

func (p ParsedMetric) AsFlatValue() (metrics.FlatValue, error)

type Schema

type Schema struct {
	Label string `json:"label" validate:"required"`
	Type  string `json:"type"` // "number" or "date", could be others
}

NOTE: The label is what's important, as we want to log the metrics of the master node.

[{'label': 'time', 'type': 'date'}, {'label': 'pg-1f3a86df-14 (standby)', 'type': 'number'}, {'label': 'pg-1f3a86df-15 (master)', 'type': 'number'}]

type State

type State struct {
	Hardware                       Hardware
	InitialSharedBuffersPercentage float64
	InitialWorkMem                 int64
	LastAppliedConfig              time.Time
	// HACK: Used to trigger restarts on ALTER DATABASE statements
	LastKnownPGStatMonitorEnable bool
	// Guardrails
	LastGuardrailCheck            time.Time
	LastMemoryAvailableTime       time.Time
	LastMemoryAvailablePercentage float64
	LastHardwareInfoTime          time.Time
}

Jump to

Keyboard shortcuts

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