cloud

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 46 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cloud collects from public clouds: an AWS CloudWatch GetMetricData poller, the AWS Resource Groups Tagging API as inventory, and an Azure Event Hubs consumer (Kafka endpoint).

Credentials never travel through remote config. AWS uses the SDK's standard chain (environment, shared credentials file, instance role); Azure's connection string is in the local file or an environment variable. Neither is logged, exported or put into a label or an error.

shortcut: GCP and Azure API pollers are known gap G-21; GCP arrives by Pub/Sub push, Azure by Event Hubs.

Index

Constants

This section is empty.

Variables

View Source
var EndpointKeys = []string{"endpoint", "login_endpoint"}

EndpointKeys are the config keys that say where a credential is sent.

View Source
var ErrBadLiveQuery = errors.New("bad query")

ErrBadLiveQuery marks a request the caller can fix, as opposed to a provider failure.

Functions

func EmitEntities

func EmitEntities(out sink.Sink, es []Entity, at time.Time)

EmitEntities writes one `cloud.resource.info` gauge per entity.

func EmitInventory

func EmitInventory(out sink.Sink, rs []Tagged, at time.Time)

EmitInventory writes one `cloud.resource.info` gauge (value 1) per resource, carrying the entity resource the worker turns into an infra_entities row (kind cloud, keyed by cloud.resource_id). The agent host's own host.* is blanked: a cloud resource does not run on it. Tags become cloud.tag.<key> properties; keys are prefixed, so no tag can name a resource attribute.

func MergeCredential

func MergeCredential(cfg, sec map[string]any)

MergeCredential adds an opened credential to a tenant row's config. An endpoint counts only from inside the credential, where the API seals it: it can only change along with the credential, so editing a row cannot send a stored credential to another host.

func ParseARN

func ParseARN(arn string) (service, region, account string, ok bool)

ParseARN splits arn:partition:service:region:account:resource (resource keeps its colons).

func Process

func Process(out sink.Sink, msg []byte, now time.Time)

Process turns one Event Hubs message ({"records": [...]} of diagnostic logs or metrics) into samples and log records. Each Azure resource id becomes a cloud entity through the resource.

func ProcessWith

func ProcessWith(out sink.Sink, ship func(map[string]string, []*tracepb.Span), msg []byte, now time.Time)

ProcessWith is Process; with ship set, Application Insights request and dependency rows are shipped as spans instead of logs.

func ResourceID

func ResourceID(arn string) string

ResourceID is the part of an ARN a CloudWatch dimension carries: what follows the last ':' or '/' of the resource part (function:orders -> orders, instance/i-0abc -> i-0abc).

func RunAWS

func RunAWS(ctx context.Context, raw json.RawMessage, out sink.Sink) error

RunAWS polls CloudWatch and walks the tagged-resource inventory until ctx ends.

func RunDBDiscovery

func RunDBDiscovery(ctx context.Context, raw json.RawMessage, out sink.Sink) error

RunDBDiscovery refreshes every 10 minutes until ctx ends.

func RunEventHub

func RunEventHub(ctx context.Context, raw json.RawMessage, out sink.Sink) error

RunEventHub consumes until ctx ends.

func RunPulls

func RunPulls(ctx context.Context, raw json.RawMessage, out sink.Sink) error

RunPulls starts every configured pull and blocks until ctx ends. A bad entry is reported and skipped so one typo does not stop the others.

func RunPullsIn

func RunPullsIn(ctx context.Context, raw json.RawMessage, stateDir string, out sink.Sink) error

RunPullsIn is RunPulls for a BYOC agent: when out keeps no positions itself, App Insights positions are kept in stateDir (empty: in memory only).

func RunStepFunctions

func RunStepFunctions(ctx context.Context, raw json.RawMessage, out sink.Sink, ship func(map[string]string, []*tracepb.Span)) error

RunStepFunctions polls until ctx ends. It does nothing unless the local config sets enabled: true and a region.

Types

type AWSConfig

type AWSConfig struct {
	Enabled  *bool  `json:"enabled"`
	Interval string `json:"interval"` // poll interval, default = period_s, floor 60s
	Region   string `json:"region"`
	Profile  string `json:"profile"`  // shared-config profile; empty = default chain
	Endpoint string `json:"endpoint"` // override (VPC endpoint, test double)
	// Namespaces to poll, e.g. ["AWS/Lambda", "AWS/EC2"], or ["auto"] for every AWS/* namespace with
	// recent metrics. Empty = no metric polling.
	Namespaces []string `json:"namespaces"`
	// Presets add named namespace sets: "data_streams" = AWS/Kinesis, AWS/SQS and AWS/SNS (queue
	// depth and age, iterator age, throughput and failures, for the data streams view).
	Presets    []string `json:"presets"`
	MaxMetrics int      `json:"max_metrics"` // per namespace, default 100
	// Stats to request per metric (default ["Average"]). Each stat doubles the metrics billed.
	Stats []string `json:"stats"`
	// PeriodS is the GetMetricData period: 300 (default, standard resolution) or 60.
	PeriodS int `json:"period_s"`
	// Inventory turns on the Resource Groups Tagging API walk (entities of kind cloud).
	Inventory         *bool  `json:"inventory"`
	InventoryInterval string `json:"inventory_interval"` // default 5m, floor 1m
	// TagFilters polls only metrics of resources carrying every listed tag (key -> allowed values;
	// an empty list means the key must exist). CloudWatch metrics have no tags, so the tagged
	// resource ids come from the Resource Groups Tagging API and are matched against dimension values.
	TagFilters map[string][]string `json:"tag_filters"`
	// RoleARN is assumed on top of the default chain (cross-account access); ExternalID guards it.
	RoleARN    string `json:"role_arn"`
	ExternalID string `json:"external_id"`
}

AWSConfig is the module's local configuration.

type DBConfig

type DBConfig struct {
	AWS      *rdsConfig      `json:"aws"`
	Azure    *azureDBConfig  `json:"azure"`
	GCP      *cloudSQLConfig `json:"gcp"`
	Interval string          `json:"interval"` // default 10m, floor 1m
}

DBConfig lists the providers to discover. Credentials live in the sealed local agent config.

type DBDiscovery

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

DBDiscovery remembers the last good answer per provider: a failed refresh keeps it.

func NewDBDiscovery

func NewDBDiscovery(cfg DBConfig) *DBDiscovery

NewDBDiscovery returns a discoverer for cfg.

func (*DBDiscovery) Discover

func (d *DBDiscovery) Discover(ctx context.Context) []Entity

Discover refreshes every configured provider and returns all known databases.

type Entity

type Entity struct{ Attrs map[string]string }

Entity is one discovered database: resource attributes, tags as cloud.tag.<key>.

func DiscoverDatabases

func DiscoverDatabases(ctx context.Context, cfg DBConfig) []Entity

DiscoverDatabases does one discovery pass with no memory of earlier passes.

type EventHubConfig

type EventHubConfig struct {
	Enabled *bool `json:"enabled"`
	// ConnectionString or ConnectionStringEnv holds the namespace connection string. It is a
	// secret: it is never logged, exported or placed in an error.
	ConnectionString    string   `json:"connection_string"`
	ConnectionStringEnv string   `json:"connection_string_env"`
	Brokers             []string `json:"brokers"` // default <namespace>.servicebus.windows.net:9093
	Topics              []string `json:"topics"`  // event hub names
	Group               string   `json:"group"`   // consumer group, default wt-agent
	// Plaintext disables TLS and SASL; for a local Kafka stand-in only.
	Plaintext bool `json:"plaintext"`
	// StartAtEarliest makes a group with no committed offset read from the start of retention
	// instead of from now. Off by default: days of history would flood the export buffer.
	StartAtEarliest bool `json:"start_at_earliest"`
}

EventHubConfig reads Azure diagnostic logs and metrics from an Event Hubs namespace through its Kafka-compatible endpoint (port 9093, SASL PLAIN, user "$ConnectionString").

type LivePoint

type LivePoint struct {
	T time.Time `json:"t"`
	V float64   `json:"v"`
}

LivePoint is one value of a series.

type LiveQuery

type LiveQuery struct {
	Metrics    []string `json:"metrics"`    // azure, gcp
	Resources  []string `json:"resources"`  // azure
	ZoneIDs    []string `json:"zone_ids"`   // cloudflare
	Namespaces []string `json:"namespaces"` // aws
	Metric     string   `json:"metric"`     // aws: one metric name
	Stat       string   `json:"stat"`       // aws: Average (default), Sum, Minimum, Maximum, SampleCount
}

LiveQuery narrows a row. An empty list means the row's whole list.

type LiveSeries

type LiveSeries struct {
	Name   string            `json:"name"`
	Attrs  map[string]string `json:"attrs"`
	Points []LivePoint       `json:"points"`
}

LiveSeries is one provider time series.

func Query

func Query(ctx context.Context, provider string, cfg map[string]any, q LiveQuery, from, to time.Time) ([]LiveSeries, error)

Query answers q for one cloud pull. cfg comes from MergeCredential.

type PullSpec

type PullSpec struct {
	Provider  string          `json:"provider"` // aws, gcp, azure, cloudflare
	IntervalS int             `json:"interval_s"`
	Config    json.RawMessage `json:"config"`
	// PublicOnly marks a tenant's row: every call goes through tenantClient. An agent's own config
	// may reach private endpoints, a tenant's may not.
	PublicOnly bool `json:"public_only,omitempty"`
}

PullSpec is one entry of the module's "pulls" list.

type SFNConfig

type SFNConfig struct {
	Enabled       *bool    `json:"enabled"`
	Interval      string   `json:"interval"` // default 60s, at least 30s
	Region        string   `json:"region"`
	StateMachines []string `json:"state_machines"` // ARNs; empty: every STANDARD machine
	MaxExecutions int      `json:"max_executions"` // per machine and round, default 50
}

SFNConfig is the aws_stepfunctions module's config (agent file only).

type Tagged

type Tagged struct {
	ARN  string
	Tags map[string]string
}

Tagged is one resource from the Resource Groups Tagging API.

Jump to

Keyboard shortcuts

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