cloudwatch

package
v0.0.1-alpha.30 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package cloudwatch provides a basic emulation of Amazon CloudWatch (metrics + alarms).

Implemented operations: PutMetricAlarm, DescribeAlarms, DeleteAlarms, PutMetricData, GetMetricStatistics, GetMetricData, ListMetrics, ListTagsForResource, TagResource, UntagResource.

Enough for CDK stacks that reference AWS::CloudWatch::Alarm resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlarmHistoryItem

type AlarmHistoryItem struct {
	AlarmName       string    `json:"AlarmName"`
	AlarmType       string    `json:"AlarmType"`
	Timestamp       time.Time `json:"Timestamp"`
	HistoryItemType string    `json:"HistoryItemType"`
	HistorySummary  string    `json:"HistorySummary"`
	HistoryData     string    `json:"HistoryData"`
}

AlarmHistoryItem is one row of DescribeAlarmHistory.

type Dimension

type Dimension struct {
	Name  string `json:"Name"`
	Value string `json:"Value"`
}

Dimension is a name/value pair for metric filtering.

type Metric

type Metric struct {
	Namespace  string      `json:"Namespace"`
	MetricName string      `json:"MetricName"`
	Dimensions []Dimension `json:"Dimensions,omitempty"`
}

Metric represents a CloudWatch metric entry.

type MetricAlarm

type MetricAlarm struct {
	AlarmName                          string      `json:"AlarmName"`
	AlarmArn                           string      `json:"AlarmArn"`
	MetricName                         string      `json:"MetricName,omitempty"`
	Namespace                          string      `json:"Namespace,omitempty"`
	Statistic                          string      `json:"Statistic,omitempty"`
	ExtendedStatistic                  string      `json:"ExtendedStatistic,omitempty"`
	Dimensions                         []Dimension `json:"Dimensions,omitempty"`
	Unit                               string      `json:"Unit,omitempty"`
	Period                             int         `json:"Period,omitempty"`
	EvaluationPeriods                  int         `json:"EvaluationPeriods,omitempty"`
	DatapointsToAlarm                  int         `json:"DatapointsToAlarm,omitempty"`
	Threshold                          float64     `json:"Threshold,omitempty"`
	ComparisonOperator                 string      `json:"ComparisonOperator,omitempty"`
	ActionsEnabled                     bool        `json:"ActionsEnabled"`
	AlarmActions                       []string    `json:"AlarmActions,omitempty"`
	OKActions                          []string    `json:"OKActions,omitempty"`
	InsufficientDataActions            []string    `json:"InsufficientDataActions,omitempty"`
	StateValue                         string      `json:"StateValue"`
	StateReason                        string      `json:"StateReason"`
	StateReasonData                    string      `json:"StateReasonData,omitempty"`
	AlarmDescription                   string      `json:"AlarmDescription,omitempty"`
	TreatMissingData                   string      `json:"TreatMissingData,omitempty"`
	StateUpdatedTimestamp              string      `json:"StateUpdatedTimestamp,omitempty"`
	StateTransitionedTimestamp         string      `json:"StateTransitionedTimestamp,omitempty"`
	AlarmConfigurationUpdatedTimestamp string      `json:"AlarmConfigurationUpdatedTimestamp,omitempty"`

	// ManualStateHoldUntil is when a SetAlarmState override stops being
	// protected from the evaluator. Internal — see setAlarmStateHold.
	ManualStateHoldUntil string `json:"ManualStateHoldUntil,omitempty"`
}

MetricAlarm represents a CloudWatch alarm.

This is the persisted shape, not a wire shape — the Query and JSON responses are rendered from it separately. ManualStateHoldUntil in particular is Overcast's own bookkeeping and is never emitted.

type MetricDataPoint

type MetricDataPoint struct {
	Namespace   string      `json:"Namespace"`
	MetricName  string      `json:"MetricName"`
	Dimensions  []Dimension `json:"Dimensions,omitempty"`
	Timestamp   time.Time   `json:"Timestamp"`
	Unit        string      `json:"Unit,omitempty"`
	SampleCount float64     `json:"SampleCount"`
	Sum         float64     `json:"Sum"`
	Minimum     float64     `json:"Minimum"`
	Maximum     float64     `json:"Maximum"`
}

MetricDataPoint stores a single published datapoint.

type Service

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

Service implements router.Service and router.QueryDispatcher for CloudWatch.

func New

func New(cfg *config.Config, st state.Store, logger *zap.Logger, clk clock.Clock) *Service

New returns a configured CloudWatch Service.

It performs no store I/O: the alarm evaluator and the metric-data sweeper only register their tickers here, and neither touches the store until its first tick (AGENTS.md § startup budget).

func (*Service) Dispatch

func (s *Service) Dispatch(w http.ResponseWriter, r *http.Request)

Dispatch satisfies router.TargetDispatcher.

Like every other JSON-tier service, the operation name comes from codec.FromContext — populated by middleware.Protocol identifying the X-Amz-Target header before Dispatch ever runs. Dispatch no longer parses X-Amz-Target itself; the header-trimming fallback below only covers callers that invoke Dispatch without going through the router's middleware chain (e.g. a unit test constructing a bare request).

func (*Service) DispatchQuery

func (s *Service) DispatchQuery(w http.ResponseWriter, r *http.Request)

DispatchQuery satisfies router.QueryDispatcher.

func (*Service) InitAlarmActions

func (s *Service) InitAlarmActions(d *alarmaction.Dispatcher)

InitAlarmActions wires the dispatcher that delivers alarm state transitions to their action ARNs. Called once from router.New; a Service without it still evaluates alarms, it just has nowhere to send the transitions.

func (*Service) Name

func (s *Service) Name() string

func (*Service) OwnsVersion

func (s *Service) OwnsVersion(version string) bool

OwnsVersion satisfies router.QueryVersionOwner.

func (*Service) RegisterRoutes

func (s *Service) RegisterRoutes(_ chi.Router)

func (*Service) Stop

func (s *Service) Stop(ctx context.Context)

func (*Service) TargetPrefix

func (s *Service) TargetPrefix() string

TargetPrefix satisfies router.TargetDispatcher for AWS SDK JSON protocol.

Directories

Path Synopsis
Package logs: migration registration for the logs_events dedicated table (docs/plans/storage-plan.md Phase 2 item 2.3).
Package logs: migration registration for the logs_events dedicated table (docs/plans/storage-plan.md Phase 2 item 2.3).

Jump to

Keyboard shortcuts

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