service

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLogsResolveSearchScope indicates a failure while resolving scope/resource identifiers.
	ErrLogsResolveSearchScope = errors.New("logs search scope resolution failed")
	// ErrLogsRetrieval indicates a failure while retrieving logs from adapter or adaptor.
	ErrLogsRetrieval = errors.New("logs retrieval failed")
)
View Source
var (
	// ErrMetricsInvalidRequest indicates that the request contains invalid parameters
	// (e.g., unparseable time values). Maps to HTTP 400 Bad Request.
	ErrMetricsInvalidRequest = errors.New("invalid metrics request")
	// ErrMetricsResolveSearchScope indicates a failure while resolving scope/resource identifiers.
	ErrMetricsResolveSearchScope = errors.New("metrics search scope resolution failed")
	// ErrMetricsRetrieval indicates a failure while retrieving metrics from the backend.
	ErrMetricsRetrieval = errors.New("metrics retrieval failed")
)
View Source
var (
	// ErrRuntimeTopologyInvalidRequest indicates the request payload is
	// malformed or violates a precondition (e.g., unparseable time, missing
	// project). Maps to HTTP 400.
	ErrRuntimeTopologyInvalidRequest = errors.New("invalid runtime topology request")
	// ErrRuntimeTopologyResolveSearchScope indicates a failure while resolving
	// a name in searchScope to a UID. Typically a 5xx from the OpenChoreo API.
	ErrRuntimeTopologyResolveSearchScope = errors.New("runtime topology search scope resolution failed")
	// ErrRuntimeTopologyRetrieval indicates the underlying metrics backend
	// failed to return data.
	ErrRuntimeTopologyRetrieval = errors.New("runtime topology retrieval failed")
)

Sentinel errors for the runtime topology queries. The handler maps these to specific HTTP status codes / error codes.

View Source
var (
	ErrTracesResolveSearchScope = errors.New("traces search scope resolution failed")
	ErrTracesRetrieval          = errors.New("traces retrieval failed")
	ErrTracesInvalidRequest     = errors.New("invalid traces request")
)
View Source
var (
	ErrResourceNotFound = errors.New("resource not found")
	ErrScopeAuthFailed  = errors.New("observer scope resolution auth failed")
)
View Source
var ErrAlertRuleAlreadyExists = errors.New("alert rule already exists")

ErrAlertRuleAlreadyExists is returned when trying to create a rule that already exists.

View Source
var ErrAlertRuleNotFound = errors.New("alert rule not found")

ErrAlertRuleNotFound is returned when the requested alert rule does not exist in the backend.

View Source
var ErrAlertsResolveSearchScope = errors.New("alerts search scope resolution failed")
View Source
var ErrScopeNotFound = errors.New("search scope resource not found")
View Source
var ErrScopeResolutionFailed = errors.New("search scope resolution infrastructure error")
View Source
var (
	ErrSpanNotFound = adaptor.ErrSpanNotFound
)

Re-export adaptor errors for use in handlers

Functions

func DispatchAlertNotifications added in v1.0.0

func DispatchAlertNotifications(
	ctx context.Context,
	alertDetails *observertypes.AlertDetails,
	channels []string,
	getConfig NotificationChannelConfigGetter,
	logger *slog.Logger,
) error

DispatchAlertNotifications sends the alert to all channels and returns an aggregated error.

Types

type AlertIncidentService added in v1.0.0

type AlertIncidentService interface {
	AlertsQuerier
	IncidentsQuerier
	IncidentsUpdater
}

AlertIncidentService is a composite interface combining alert query, incident query, and incident update operations. The concrete *AlertService satisfies this interface. The individual sub-interfaces are kept for consumers that only need a subset.

func NewAlertIncidentServiceWithAuthz added in v1.0.0

func NewAlertIncidentServiceWithAuthz(s AlertIncidentService, pdp authzcore.PDP, logger *slog.Logger) AlertIncidentService

NewAlertIncidentServiceWithAuthz wraps the provided AlertIncidentService with authorization checks for QueryAlerts, QueryIncidents, and UpdateIncident.

type AlertOpenSearchClient added in v0.17.0

type AlertOpenSearchClient interface {
	SearchMonitorByName(ctx context.Context, name string) (id string, exists bool, err error)
	GetMonitorByID(ctx context.Context, monitorID string) (monitor map[string]interface{}, err error)
	CreateMonitor(ctx context.Context, monitor map[string]interface{}) (id string, lastUpdateTime int64, err error)
	UpdateMonitor(ctx context.Context, monitorID string, monitor map[string]interface{}) (lastUpdateTime int64, err error)
	DeleteMonitor(ctx context.Context, monitorID string) error
}

AlertOpenSearchClient defines the OpenSearch operations used by AlertService.

type AlertRuleService added in v1.1.0

type AlertRuleService interface {
	CreateAlertRule(ctx context.Context, req gen.AlertRuleRequest) (*gen.AlertingRuleSyncResponse, error)
	GetAlertRule(ctx context.Context, ruleName, sourceType string) (*gen.AlertRuleResponse, error)
	UpdateAlertRule(ctx context.Context, ruleName string, req gen.AlertRuleRequest) (*gen.AlertingRuleSyncResponse, error)
	DeleteAlertRule(ctx context.Context, ruleName, sourceType string) (*gen.AlertingRuleSyncResponse, error)
	HandleAlertWebhook(ctx context.Context, req gen.AlertWebhookRequest) (*gen.AlertWebhookResponse, error)
}

AlertRuleService is the interface for managing alert rules and processing incoming alert webhooks.

type AlertService added in v0.17.0

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

AlertService provides CRUD operations for alert rules, backing the v1alpha1 API.

func NewAlertService added in v0.17.0

func NewAlertService(
	osClient AlertOpenSearchClient,
	queryBuilder *opensearch.QueryBuilder,
	alertEntryStore alertentry.AlertEntryStore,
	incidentEntryStore incidententry.IncidentEntryStore,
	k8sClient client.Client,
	cfg *config.Config,
	logger *slog.Logger,
	rcaServiceURL string,
	aiRCAEnabled bool,
	resolver *ResourceUIDResolver,
	logsAdapter *LogsAdapter,
	metricsAdapterURL string,
	metricsAdapterClient *http.Client,
	finOpsAgentURL string,
	finOpsAgentEnabled bool,
) *AlertService

NewAlertService creates a new AlertService.

func (*AlertService) CreateAlertRule added in v0.17.0

CreateAlertRule creates a new alert rule in the observability backend. Returns an error wrapping ErrAlertRuleAlreadyExists if the rule already exists.

func (*AlertService) DeleteAlertRule added in v0.17.0

func (s *AlertService) DeleteAlertRule(ctx context.Context, ruleName, sourceType string) (*gen.AlertingRuleSyncResponse, error)

DeleteAlertRule deletes an alert rule from the observability backend. sourceType must be "log" or "metric". Returns ErrAlertRuleNotFound if the rule does not exist.

func (*AlertService) GetAlertRule added in v0.17.0

func (s *AlertService) GetAlertRule(ctx context.Context, ruleName, sourceType string) (*gen.AlertRuleResponse, error)

GetAlertRule fetches an alert rule from the observability backend. sourceType must be "log" or "metric". Returns an error wrapping ErrAlertRuleNotFound if the rule does not exist.

func (*AlertService) HandleAlertWebhook added in v0.17.0

func (s *AlertService) HandleAlertWebhook(ctx context.Context, req gen.AlertWebhookRequest) (*gen.AlertWebhookResponse, error)

HandleAlertWebhook processes an incoming alert webhook in the normalized v1alpha1 format. It fetches the ObservabilityAlertRule CR, enriches alert details, stores the alert entry, sends a notification, and optionally triggers AI RCA analysis.

func (*AlertService) QueryAlerts added in v1.0.0

func (*AlertService) QueryIncidents added in v1.0.0

func (*AlertService) UpdateAlertRule added in v0.17.0

func (s *AlertService) UpdateAlertRule(ctx context.Context, ruleName string, req gen.AlertRuleRequest) (*gen.AlertingRuleSyncResponse, error)

UpdateAlertRule updates an existing alert rule in the observability backend. Returns an error wrapping ErrAlertRuleNotFound if the rule does not exist.

func (*AlertService) UpdateIncident added in v1.0.0

type AlertsQuerier added in v1.0.0

type AlertsQuerier interface {
	QueryAlerts(ctx context.Context, req gen.AlertsQueryRequest) (*gen.AlertsQueryResponse, error)
}

AlertsQuerier is the interface for querying alerts.

type HealthChecker added in v1.1.0

type HealthChecker interface {
	Check(ctx context.Context) error
}

HealthChecker is the interface for checking service health.

type HealthService added in v0.17.0

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

HealthService provides health check functionality

func NewHealthService added in v0.17.0

func NewHealthService(logger *slog.Logger) (*HealthService, error)

NewHealthService creates a new HealthService instance

func (*HealthService) Check added in v0.17.0

func (s *HealthService) Check(ctx context.Context) error

Check performs a health check on the observer service

type IncidentsQuerier added in v1.0.0

type IncidentsQuerier interface {
	QueryIncidents(ctx context.Context, req gen.IncidentsQueryRequest) (*gen.IncidentsQueryResponse, error)
}

IncidentsQuerier is the interface for querying incidents.

type IncidentsUpdater added in v1.0.0

type IncidentsUpdater interface {
	UpdateIncident(ctx context.Context, incidentID string, req gen.IncidentPutRequest) (*gen.IncidentPutResponse, error)
}

IncidentsUpdater is the interface for updating incidents.

type LogsAdapter added in v0.17.0

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

func NewLogsAdapter added in v0.17.0

func NewLogsAdapter(config LogsAdapterConfig) (*LogsAdapter, error)

func (*LogsAdapter) GetComponentApplicationLogs added in v0.17.0

GetComponentApplicationLogs implements observability.LogsAdapter interface It makes an HTTP POST request to the logs API with component application logs parameters

func (*LogsAdapter) GetWorkflowLogs added in v0.17.0

GetWorkflowLogs implements observability.LogsAdapter interface It makes an HTTP POST request to the logs API with workflow logs parameters

type LogsAdapterConfig added in v0.17.0

type LogsAdapterConfig struct {
	BaseURL string
	Timeout time.Duration
}

type LogsQuerier added in v0.17.0

type LogsQuerier interface {
	QueryLogs(ctx context.Context, req *types.LogsQueryRequest) (*types.LogsQueryResponse, error)
}

LogsQuerier is the interface for querying logs.

func NewLogsServiceWithAuthz added in v0.17.0

func NewLogsServiceWithAuthz(s LogsQuerier, pdp authzcore.PDP, logger *slog.Logger) LogsQuerier

NewLogsServiceWithAuthz wraps the provided LogsQuerier with authorization checks.

type LogsService added in v0.17.0

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

LogsService provides logging functionality for the new API

func NewLogsService added in v0.17.0

func NewLogsService(
	logsAdapter observability.LogsAdapter,
	resolver *ResourceUIDResolver,
	cfg *config.Config,
	logger *slog.Logger,
) (*LogsService, error)

NewLogsService creates a new LogsService instance. It initializes its own DefaultLogsAdaptor internally for OpenSearch queries. The resolver is passed in as it's shared across multiple services.

func (*LogsService) QueryLogs added in v0.17.0

QueryLogs queries logs based on the provided request If experimental.use.logs.adapter is enabled, uses logs adapter Otherwise, falls back to the default adaptor

type MetricsAdapter added in v1.1.0

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

MetricsAdapter forwards metrics queries to an external metrics adapter service. It resolves human-readable names (project, component, environment) to UIDs before forwarding, so that the adapter receives the UIDs it expects for Prometheus label filtering. It implements the MetricsQuerier interface.

func NewMetricsAdapter added in v1.1.0

func NewMetricsAdapter(baseURL string, timeout time.Duration, resolver *ResourceUIDResolver, logger *slog.Logger) *MetricsAdapter

NewMetricsAdapter creates a new MetricsAdapter that forwards requests to the given base URL. The resolver is used to convert human-readable names to UIDs before forwarding.

func (*MetricsAdapter) QueryMetrics added in v1.1.0

func (a *MetricsAdapter) QueryMetrics(ctx context.Context, req *types.MetricsQueryRequest) (any, error)

QueryMetrics resolves search scope names to UIDs and forwards the metrics query request to the external adapter, returning the raw JSON response.

func (*MetricsAdapter) QueryRuntimeTopology added in v1.1.0

QueryRuntimeTopology resolves search scope names to UIDs and forwards the runtime topology query to the metrics-adapter's /api/v1alpha1/metrics/runtime-topology endpoint.

type MetricsQuerier added in v0.17.0

type MetricsQuerier interface {
	QueryMetrics(ctx context.Context, req *types.MetricsQueryRequest) (any, error)
	QueryRuntimeTopology(ctx context.Context, req *types.RuntimeTopologyRequest) (*types.RuntimeTopologyResponse, error)
}

MetricsQuerier is the interface for querying metrics and runtime topology.

func NewMetricsServiceWithAuthz added in v0.17.0

func NewMetricsServiceWithAuthz(s MetricsQuerier, pdp authzcore.PDP, logger *slog.Logger) MetricsQuerier

NewMetricsServiceWithAuthz wraps the provided MetricsQuerier with authorization checks.

type MetricsService added in v0.17.0

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

MetricsService provides metrics querying functionality for the new API

func NewMetricsService added in v0.17.0

func NewMetricsService(prometheusMetrics *prometheus.MetricsService, resolver *ResourceUIDResolver, logger *slog.Logger) (*MetricsService, error)

NewMetricsService creates a new MetricsService instance

func (*MetricsService) QueryMetrics added in v0.17.0

func (s *MetricsService) QueryMetrics(ctx context.Context, req *types.MetricsQueryRequest) (interface{}, error)

QueryMetrics queries metrics based on the provided request. The concrete return type is one of:

  • *types.ResourceMetricsQueryResponse (when req.Metric == "resource")
  • *types.HTTPMetricsQueryResponse (when req.Metric == "http")

type NotificationChannelConfigGetter added in v1.0.0

type NotificationChannelConfigGetter func(ctx context.Context, channelName string) (*notifications.NotificationChannelConfig, error)

NotificationChannelConfigGetter resolves a notification channel config by channel name.

type ResourceUIDResolver added in v0.17.0

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

ResourceUIDResolver provides methods to resolve resource names to UIDs by calling the openchoreo-api with OAuth2 client credentials authentication.

func NewResourceUIDResolver added in v0.17.0

func NewResourceUIDResolver(cfg *config.UIDResolverConfig, logger *slog.Logger) *ResourceUIDResolver

NewResourceUIDResolver creates a new ResourceUIDResolver instance

func (*ResourceUIDResolver) GetComponentUID added in v0.17.0

func (r *ResourceUIDResolver) GetComponentUID(
	ctx context.Context,
	namespaceName, projectName, componentName string,
) (string, error)

GetComponentUID resolves a component name to its UID within a namespace and project.

func (*ResourceUIDResolver) GetEnvironmentUID added in v0.17.0

func (r *ResourceUIDResolver) GetEnvironmentUID(ctx context.Context, namespaceName, environmentName string) (string, error)

GetEnvironmentUID resolves an environment name to its UID within a namespace.

func (*ResourceUIDResolver) GetNamespaceUID added in v0.17.0

func (r *ResourceUIDResolver) GetNamespaceUID(ctx context.Context, namespaceName string) (string, error)

GetNamespaceUID resolves a namespace name to its UID.

func (*ResourceUIDResolver) GetProjectUID added in v0.17.0

func (r *ResourceUIDResolver) GetProjectUID(ctx context.Context, namespaceName, projectName string) (string, error)

GetProjectUID resolves a project name to its UID within a namespace.

type TracesQuerier added in v0.17.0

type TracesQuerier interface {
	QueryTraces(ctx context.Context, req *types.TracesQueryRequest) (*types.TracesQueryResponse, error)
	QuerySpans(ctx context.Context, traceID string, req *types.TracesQueryRequest) (*types.SpansQueryResponse, error)
	GetSpanDetails(ctx context.Context, traceID string, spanID string) (*types.SpanInfo, error)
}

TracesQuerier is the interface for querying traces and spans.

func NewTracesServiceWithAuthz added in v0.17.0

func NewTracesServiceWithAuthz(s TracesQuerier, pdp authzcore.PDP, logger *slog.Logger) TracesQuerier

NewTracesServiceWithAuthz wraps the provided TracesQuerier with authorization checks.

type TracesService added in v0.17.0

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

func NewTracesService added in v0.17.0

func NewTracesService(
	tracingAdapter observability.TracingAdapter,
	resolver *ResourceUIDResolver,
	cfg *config.Config,
	logger *slog.Logger,
) (*TracesService, error)

func (*TracesService) GetSpanDetails added in v0.17.0

func (s *TracesService) GetSpanDetails(ctx context.Context, traceID string, spanID string) (*types.SpanInfo, error)

GetSpanDetails retrieves detailed information about a specific span

func (*TracesService) QuerySpans added in v0.17.0

QuerySpans queries spans within a specific trace

func (*TracesService) QueryTraces added in v0.17.0

type TracingAdapter added in v0.17.0

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

func NewTracingAdapter added in v0.17.0

func NewTracingAdapter(config TracingAdapterConfig) (*TracingAdapter, error)

func (*TracingAdapter) GetSpanDetails added in v1.0.0

func (t *TracingAdapter) GetSpanDetails(ctx context.Context, traceID string, spanID string) (*observability.SpanDetail, error)

GetSpanDetails implements observability.TracingAdapter interface

func (*TracingAdapter) GetSpans added in v1.0.0

GetSpans implements observability.TracingAdapter interface

func (*TracingAdapter) GetTraces added in v0.17.0

GetTraces implements observability.TracingAdapter interface

type TracingAdapterConfig added in v0.17.0

type TracingAdapterConfig struct {
	BaseURL string
	Timeout time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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