metrics

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package metrics holds configuration and middleware for prometheus style metrics

Index

Constants

View Source
const (
	// Success values
	LabelSuccess = "true"
	LabelFailure = "false"

	// Common operations
	OperationCreate = "create"
	OperationRead   = "read"
	OperationUpdate = "update"
	OperationDelete = "delete"
	OperationList   = "list"

	// Queue names
	QueueEmail     = "email"
	QueueWebhook   = "webhook"
	QueueAnalytics = "analytics"

	// Task types
	TaskEmailWelcome      = "welcome_email"
	TaskEmailVerification = "verification_email"
	TaskEmailReset        = "reset_email"
	TaskWebhookDelivery   = "webhook_delivery"
)

Common label values to use across metrics

Variables

View Source
var (
	WorkerExecutions = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_worker_executions_total",
		Help: "The total number of worker executions completed",
	}, []string{"name"})

	WorkerExecutionErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_worker_execution_errors_total",
		Help: "The total number of worker execution errors",
	}, []string{"name"})

	Logins = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_logins_total",
		Help: "The total number of login attempts",
	}, []string{"success"})

	RequestValidations = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_request_validations_total",
		Help: "The total number of request validations by type and success",
	}, []string{"request", "success"})

	HandlerErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_handler_errors_total",
		Help: "The total number of handler errors by function and status code",
	}, []string{"function", "code"})

	HandlerResults = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_handler_results_total",
		Help: "The total number of handler results by request type and success",
	}, []string{"request", "success"})

	Registrations = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "openlane_registrations_total",
		Help: "The total number of user registrations",
	})

	QueueTasksPushed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_pushed_total",
		Help: "The total number of tasks pushed to queue",
	}, []string{"queue", "task"})

	QueueTasksPushFailures = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_push_failures_total",
		Help: "The total number of errors pushing a task to the queue",
	}, []string{"queue", "task"})

	QueueTasksProcessed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_processed_total",
		Help: "The total number of tasks processed by the consumer",
	}, []string{"task"})

	QueueTasksProcessedErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_process_errors_total",
		Help: "The total number of errors encountered by the consumer",
	}, []string{"task"})

	QueueTasksProcessedDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name: "openlane_queue_tasks_process_duration_seconds",
		Help: "The duration of task processing in seconds",
	}, []string{"task"})

	GraphQLOperationTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_graphql_operations_total",
		Help: "The total number of GraphQL operations processed",
	}, []string{"operation", "success"})

	GraphQLOperationDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "openlane_graphql_operation_duration_seconds",
		Help:    "The duration of GraphQL operations in seconds",
		Buckets: prometheus.DefBuckets,
	}, []string{"operation"})

	APIMetrics = []prometheus.Collector{
		WorkerExecutions,
		WorkerExecutionErrors,
		Logins,
		Registrations,
		QueueTasksPushed,
		QueueTasksPushFailures,
		GraphQLOperationTotal,
		GraphQLOperationDuration,
		RequestValidations,
		HandlerErrors,
		HandlerResults,
	}

	QueueConsumerMetrics = []prometheus.Collector{
		QueueTasksProcessedDuration,
		QueueTasksProcessed,
		QueueTasksProcessedErrors,
	}
)

These variables are stubs for now ad will be added throughout the codebase

Functions

func RecordGraphQLOperation added in v0.25.0

func RecordGraphQLOperation(operation string, duration float64, err error)

RecordGraphQLOperation records a GraphQL operation

func RecordHandlerError added in v0.25.0

func RecordHandlerError(statusCode int)

RecordHandlerError records a handler error using HTTP status code The function name is derived from http.StatusText() for consistency

func RecordHandlerResult added in v0.25.0

func RecordHandlerResult(requestType string, success bool)

RecordHandlerResult records a handler result

func RecordLogin added in v0.25.0

func RecordLogin(success bool)

RecordLogin records a login attempt

func RecordQueueTaskProcessed added in v0.25.0

func RecordQueueTaskProcessed(taskName string, duration float64, err error)

RecordQueueTaskProcessed records a task being processed

func RecordQueueTaskPushed added in v0.25.0

func RecordQueueTaskPushed(queueName, taskName string, err error)

RecordQueueTaskPushed records a task being pushed to queue

func RecordRegistration added in v0.34.5

func RecordRegistration()

RecordRegistration records a registration attempt

func RecordRequestValidation added in v0.25.0

func RecordRequestValidation(requestType string, success bool)

RecordRequestValidation records a request validation result

func RecordWorkerExecution added in v0.25.0

func RecordWorkerExecution(workerName string, err error)

RecordWorkerExecution records a worker execution with appropriate labels

Types

type LabelValues added in v0.25.0

type LabelValues struct {
	// Common labels
	Success   string
	Operation string
	Method    string
	Status    string

	// Service-specific labels
	WorkerName   string
	QueueName    string
	TaskName     string
	RequestType  string
	FunctionName string
	ErrorCode    string

	// Resource labels
	TableName   string
	CacheName   string
	ServiceName string
}

LabelValues provides a structured way to define metric labels This helps avoid typos and ensures consistency across the codebase

func (LabelValues) ForGraphQLOperation added in v0.25.0

func (l LabelValues) ForGraphQLOperation() []string

func (LabelValues) ForHandlerError added in v0.25.0

func (l LabelValues) ForHandlerError() []string

func (LabelValues) ForHandlerResult added in v0.25.0

func (l LabelValues) ForHandlerResult() []string

func (LabelValues) ForLogin added in v0.25.0

func (l LabelValues) ForLogin() []string

func (LabelValues) ForQueueTask added in v0.25.0

func (l LabelValues) ForQueueTask() []string

func (LabelValues) ForQueueTaskProcessed added in v0.25.0

func (l LabelValues) ForQueueTaskProcessed() []string

func (LabelValues) ForRequestValidation added in v0.25.0

func (l LabelValues) ForRequestValidation() []string

func (LabelValues) ForWorker added in v0.25.0

func (l LabelValues) ForWorker() []string

StandardLabels returns a slice of label values in the correct order for the given metric. This ensures consistency and reduces errors.

type MetricNameBuilder added in v0.25.0

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

MetricNameBuilder helps construct consistent metric names

func NewMetricNameBuilder added in v0.25.0

func NewMetricNameBuilder() *MetricNameBuilder

NewMetricNameBuilder creates a new builder with default namespace

func (*MetricNameBuilder) Build added in v0.25.0

func (b *MetricNameBuilder) Build(name string) string

Build constructs the full metric name

func (*MetricNameBuilder) WithSubsystem added in v0.25.0

func (b *MetricNameBuilder) WithSubsystem(subsystem string) *MetricNameBuilder

WithSubsystem sets the subsystem for the metric

type Metrics

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

Metrics struct holds a distinct echo instance to report system metrics

func New

func New(port string) *Metrics

New creates a new Metrics instance

func (*Metrics) Register

func (m *Metrics) Register(metrics []prometheus.Collector) error

Register registers metrics to the default registry

func (*Metrics) Start

func (m *Metrics) Start(ctx context.Context) error

Start starts the metrics server

func (*Metrics) Stop

func (m *Metrics) Stop(ctx context.Context) error

Stop stops the metrics server

Jump to

Keyboard shortcuts

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