client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client defines interfaces for external dependencies of the Effectiveness Monitor. These interfaces enable dependency injection and testability across all tiers.

Integration tests use httptest.NewServer mocks (per TESTING_GUIDELINES.md Section 4a). E2E tests use real Prometheus/AlertManager containers (per DD-TEST-001).

Business Requirements: - BR-EM-001: Health check via K8s readiness/liveness - BR-EM-002: Alert resolution check via AlertManager - BR-EM-003: Metric comparison via Prometheus - BR-EM-004: Spec hash comparison via K8s API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// Labels are the alert labels.
	Labels map[string]string
	// State is the alert state (active, suppressed, unprocessed).
	State string
	// StartsAt is when the alert started firing.
	StartsAt time.Time
	// EndsAt is when the alert stopped firing (zero if still active).
	EndsAt time.Time
}

Alert represents an alert from AlertManager.

type AlertFilters

type AlertFilters struct {
	// Matchers are label matchers to filter alerts (e.g., alertname=~"HighLatency").
	Matchers []string
}

AlertFilters defines criteria for querying alerts from AlertManager.

type AlertManagerClient

type AlertManagerClient interface {
	// GetAlerts retrieves active alerts matching the given filters.
	GetAlerts(ctx context.Context, filters AlertFilters) ([]Alert, error)

	// Ready checks if AlertManager is ready to accept queries.
	Ready(ctx context.Context) error
}

AlertManagerClient abstracts AlertManager API operations. Used for alert resolution scoring (BR-EM-002).

Integration tests: httptest.NewServer mock (test/infrastructure/alertmanager_mock.go) E2E tests: real AlertManager container (test/infrastructure/prometheus_alertmanager_e2e.go)

func NewAlertManagerHTTPClient

func NewAlertManagerHTTPClient(baseURL string, timeout time.Duration) AlertManagerClient

NewAlertManagerHTTPClient creates an AlertManagerClient that connects to an AlertManager HTTP API.

type DataStorageQuerier

type DataStorageQuerier interface {
	// QueryPreRemediationHash queries DS for the pre-remediation spec hash
	// associated with a given correlation ID. Returns empty string if not found.
	QueryPreRemediationHash(ctx context.Context, correlationID string) (string, error)

	// HasWorkflowStarted checks if a workflowexecution.workflow.started event
	// exists for the given correlation ID. Returns false if not found.
	// ADR-EM-001 Section 5: Used to detect the no_execution path.
	HasWorkflowStarted(ctx context.Context, correlationID string) (bool, error)
}

DataStorageQuerier abstracts queries to the DataStorage audit trail. Used by the EM to retrieve the pre-remediation spec hash from the remediation.workflow_created audit event (DD-EM-002) and to detect whether a workflow was ever started (ADR-EM-001 Section 5).

func NewDataStorageHTTPQuerier

func NewDataStorageHTTPQuerier(baseURL string) DataStorageQuerier

NewDataStorageHTTPQuerier creates a new DS querier with default timeout and ServiceAccount authentication (DD-AUTH-005).

func NewDataStorageHTTPQuerierWithTimeout

func NewDataStorageHTTPQuerierWithTimeout(baseURL string, timeout time.Duration) DataStorageQuerier

NewDataStorageHTTPQuerierWithTimeout creates a new DS querier with custom timeout and ServiceAccount authentication (DD-AUTH-005).

func NewDataStorageHTTPQuerierWithTransport

func NewDataStorageHTTPQuerierWithTransport(baseURL string, timeout time.Duration, transport http.RoundTripper) DataStorageQuerier

NewDataStorageHTTPQuerierWithTransport creates a DS querier with explicit transport. When transport is nil, ServiceAccount token auth is used automatically (same pattern as audit.NewOpenAPIClientAdapter -- DD-AUTH-005).

type PrometheusQuerier

type PrometheusQuerier interface {
	// Query executes an instant PromQL query and returns the result.
	Query(ctx context.Context, query string, ts time.Time) (*QueryResult, error)

	// QueryRange executes a range PromQL query and returns the result.
	QueryRange(ctx context.Context, query string, start, end time.Time, step time.Duration) (*QueryResult, error)

	// Ready checks if Prometheus is ready to accept queries.
	Ready(ctx context.Context) error
}

PrometheusQuerier abstracts Prometheus query operations. Used for metric comparison scoring (BR-EM-003).

Integration tests: httptest.NewServer mock (test/infrastructure/prometheus_mock.go) E2E tests: real Prometheus container (test/infrastructure/prometheus_alertmanager_e2e.go)

func NewPrometheusHTTPClient

func NewPrometheusHTTPClient(baseURL string, timeout time.Duration) PrometheusQuerier

NewPrometheusHTTPClient creates a PrometheusQuerier that connects to a Prometheus HTTP API.

type QueryResult

type QueryResult struct {
	// Samples contains the data points returned by the query.
	Samples []Sample
}

QueryResult represents the result of a Prometheus query.

type Sample

type Sample struct {
	// Metric is the metric name and labels.
	Metric map[string]string
	// Value is the sample value.
	Value float64
	// Timestamp is the sample timestamp.
	Timestamp time.Time
}

Sample represents a single data point from Prometheus.

Jump to

Keyboard shortcuts

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