metrics

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 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"

	// Authentication types
	AuthTypeJWT          = "jwt"
	AuthTypeJWTAnonymous = "jwt_anonymous"
	AuthTypePAT          = "pat"
	AuthTypeAPIToken     = "api_token"
)

Common label values to use across metrics

Variables

View Source
var (
	// WorkerExecutions records the total number of worker executions completed
	// this is currently not being recorded anywhere
	WorkerExecutions = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_worker_executions_total",
		Help: "The total number of worker executions completed",
	}, []string{"name"})

	// WorkerExecutionErrors records the total number of worker execution errors
	// this is currently not being recorded anywhere
	WorkerExecutionErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_worker_execution_errors_total",
		Help: "The total number of worker execution errors",
	}, []string{"name"})

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

	// RequestValidations records the total number of request validations by type and 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 records the total number of handler errors by function and status code
	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 records the total number of handler results by request type and success
	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 records the total number of user registrations
	Registrations = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "openlane_registrations_total",
		Help: "The total number of user registrations",
	})

	// EmailValidations records the number of email validations by success and result type
	EmailValidations = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_email_validations_total",
		Help: "The total number of email validations by success and result type",
	}, []string{"success", "result"})

	// QueueTasksPushed records the number of tasks pushed to the queue
	// this is currently not being recorded anywhere
	QueueTasksPushed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_pushed_total",
		Help: "The total number of tasks pushed to queue",
	}, []string{"queue", "task"})

	// QueueTasksPushFailures records the number of errors pushing a task to the queue
	// this is currently not being recorded anywhere
	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 records the number of tasks processed by the consumer
	// this is currently not being recorded anywhere
	QueueTasksProcessed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_queue_tasks_processed_total",
		Help: "The total number of tasks processed by the consumer",
	}, []string{"task"})

	// QueueTasksProcessedErrors records the number of errors encountered by the consumer
	// this is currently not being recorded anywhere
	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 records the duration of task processing in seconds
	// this is currently not being recorded anywhere
	QueueTasksProcessedDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name: "openlane_queue_tasks_process_duration_seconds",
		Help: "The duration of task processing in seconds",
	}, []string{"task"})

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

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

	// GraphQLQueryRejected records the number of rejected GraphQL queries by reason
	GraphQLQueryRejected = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_graphql_query_rejected_total",
		Help: "The total number of GraphQL queries rejected",
	}, []string{"reason"})

	// GraphQLQueryComplexity records the complexity of GraphQL queries by operation
	GraphQLQueryComplexity = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "openlane_graphql_query_complexity",
		Help:    "The complexity of GraphQL queries by operation",
		Buckets: []float64{5, 10, 25, 50, 100, 200, 500, 1000},
	}, []string{"operation"})

	// FileUploadsInFlight records the current number of file uploads in progress
	FileUploadsInFlight = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "openlane_file_uploads_in_flight",
		Help: "Current number of file uploads in progress",
	})

	// FileUploadsStarted records the number of file uploads started
	FileUploadsStarted = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "openlane_file_uploads_started_total",
		Help: "Total number of file uploads started",
	})

	// FileUploadsCompleted records the number of completed file uploads by status
	FileUploadsCompleted = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_file_uploads_completed_total",
		Help: "Total number of file uploads completed",
	}, []string{"status"})

	// FileUploadDuration records the duration of file uploads
	FileUploadDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "openlane_file_upload_duration_seconds",
		Help:    "Duration of file uploads in seconds",
		Buckets: []float64{0.1, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0, 120.0},
	}, []string{"status"})

	// FileBufferingStrategy tracks the number of files buffered by strategy (memory vs disk)
	// this is currently not being recorded anywhere
	FileBufferingStrategy = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_file_buffering_strategy_total",
		Help: "Total number of files buffered by strategy (memory vs disk)",
	}, []string{"strategy"})

	// StorageProviderUploads tracks the number of upload operations per storage provider
	StorageProviderUploads = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_storage_provider_uploads_total",
		Help: "Total number of files uploaded per storage provider",
	}, []string{"provider"})

	// StorageProviderBytesUploaded tracks the total bytes uploaded per storage provider
	StorageProviderBytesUploaded = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_storage_provider_bytes_uploaded_total",
		Help: "Total bytes uploaded per storage provider",
	}, []string{"provider"})

	// StorageProviderDownloads tracks the number of download operations per storage provider
	StorageProviderDownloads = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_storage_provider_downloads_total",
		Help: "Total number of files downloaded per storage provider",
	}, []string{"provider"})

	// StorageProviderBytesDownloaded tracks the total bytes downloaded per storage provider
	StorageProviderBytesDownloaded = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_storage_provider_bytes_downloaded_total",
		Help: "Total bytes downloaded per storage provider",
	}, []string{"provider"})

	// StorageProviderDeletes tracks the number of delete operations per storage provider
	StorageProviderDeletes = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_storage_provider_deletes_total",
		Help: "Total number of files deleted per storage provider",
	}, []string{"provider"})

	// AuthenticationAttempts tracks the number of authentication attempts by type
	AuthenticationAttempts = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_authentication_attempts_total",
		Help: "The total number of authentication attempts by type (jwt, jwt_anonymous, pat, api_token)",
	}, []string{"type"})

	// ActiveSubscriptions tracks the current number of active subscriptions
	// this should be the difference between opened and closed subscriptions
	ActiveSubscriptions = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "openlane_subscriptions_active",
		Help: "Current number of active subscriptions",
	})

	// SubscriptionOpen tracks the total number of subscriptions opened
	SubscriptionOpen = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "openlane_subscription_open_total",
		Help: "Total number of subscriptions opened",
	})

	// SubscriptionClose tracks the total number of subscriptions closed
	SubscriptionClose = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "openlane_subscription_close_total",
		Help: "Total number of subscriptions closed",
	})

	// SubscriptionLifetime records the lifetime of subscriptions in seconds
	SubscriptionLifetime = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "openlane_subscription_lifetime_seconds",
		Help:    "Lifetime of subscriptions in seconds",
		Buckets: prometheus.ExponentialBuckets(10, 2, 10),
	})

	// APIMetrics is the list of all API metrics collectors for the main server
	WorkflowOperationsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_workflow_operations_total",
		Help: "The total number of workflow operations by origin, trigger, and success",
	}, []string{"operation", "origin", "trigger", "success"})

	// WorkflowOperationDuration tracks how long a workflow took in seconds
	WorkflowOperationDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "openlane_workflow_operation_duration_seconds",
		Help:    "The duration of workflow operations in seconds",
		Buckets: prometheus.DefBuckets,
	}, []string{"operation", "origin", "trigger"})

	// WorkflowEmitErrorsTotal tracks the errors by topic for a workflow
	WorkflowEmitErrorsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_workflow_emit_errors_total",
		Help: "The total number of workflow emit errors by topic and origin",
	}, []string{"topic", "origin"})

	// IntegrationProviderInstalls tracks the number of install operations per integration provider
	IntegrationProviderInstalls = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_integration_provider_installs_total",
		Help: "Total number of installs per integration provider",
	}, []string{"provider"})

	// IntegrationProviderDisconnects tracks the number of disconnect operations per integration provider
	IntegrationProviderDisconnects = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "openlane_integration_provider_disconnect_total",
		Help: "Total number of disconnect per integration provider",
	}, []string{"provider"})

	APIMetrics = []prometheus.Collector{
		WorkerExecutions,
		WorkerExecutionErrors,
		Logins,
		Registrations,
		EmailValidations,
		QueueTasksPushed,
		QueueTasksPushFailures,
		GraphQLOperationTotal,
		GraphQLOperationDuration,
		GraphQLQueryRejected,
		GraphQLQueryComplexity,
		RequestValidations,
		HandlerErrors,
		HandlerResults,
		FileUploadsInFlight,
		FileUploadsStarted,
		FileUploadsCompleted,
		FileUploadDuration,
		FileBufferingStrategy,
		StorageProviderUploads,
		StorageProviderBytesUploaded,
		StorageProviderDownloads,
		StorageProviderBytesDownloaded,
		StorageProviderDeletes,
		AuthenticationAttempts,
		WorkflowOperationsTotal,
		WorkflowOperationDuration,
		WorkflowEmitErrorsTotal,
		IntegrationProviderInstalls,
		IntegrationProviderDisconnects,
	}

	// SubscriptionMetrics is the list of all metrics specific to graph subscriptions and websocket connections
	SubscriptionMetrics = []prometheus.Collector{
		ActiveSubscriptions,
		SubscriptionOpen,
		SubscriptionClose,
		SubscriptionLifetime,
	}

	// QueueConsumerMetrics is the list of all metrics for queue consumers
	// this is currently not registered and metrics are not collected
	QueueConsumerMetrics = []prometheus.Collector{
		QueueTasksProcessedDuration,
		QueueTasksProcessed,
		QueueTasksProcessedErrors,
	}
)

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

Functions

func FinishFileUpload

func FinishFileUpload(status string, duration float64)

FinishFileUpload records the completion of a file upload

func RecordAuthentication

func RecordAuthentication(authType string)

RecordAuthentication records an authentication attempt by type

func RecordEmailValidation

func RecordEmailValidation(success bool, result string)

RecordEmailValidation records an email validation result

func RecordFileBufferingStrategy

func RecordFileBufferingStrategy(strategy string)

RecordFileBufferingStrategy records which buffering strategy was used

func RecordGraphQLOperation

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

RecordGraphQLOperation records a GraphQL operation with complexity

func RecordGraphQLRejection

func RecordGraphQLRejection(reason string)

RecordGraphQLRejection records a rejected GraphQL query

func RecordHandlerError

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

func RecordHandlerResult(requestType string, success bool)

RecordHandlerResult records a handler result

func RecordIntegrationDisconnected

func RecordIntegrationDisconnected(definitionID string)

RecordIntegrationDisconnected records a disconnect operation for an integration provider

func RecordIntegrationInstalled

func RecordIntegrationInstalled(definitionID string)

RecordIntegrationInstalled records an installation operation for an integration provider

func RecordLogin

func RecordLogin(success bool)

RecordLogin records a login attempt

func RecordQueueTaskProcessed

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

RecordQueueTaskProcessed records a task being processed

func RecordQueueTaskPushed

func RecordQueueTaskPushed(queueName, taskName string, err error)

RecordQueueTaskPushed records a task being pushed to queue

func RecordRegistration

func RecordRegistration()

RecordRegistration records a registration attempt

func RecordRequestValidation

func RecordRequestValidation(requestType string, success bool)

RecordRequestValidation records a request validation result

func RecordStorageDelete

func RecordStorageDelete(provider string)

RecordStorageDelete records a delete operation for a storage provider

func RecordStorageDownload

func RecordStorageDownload(provider string, bytes int64)

RecordStorageDownload records a download operation for a storage provider

func RecordStorageUpload

func RecordStorageUpload(provider string, bytes int64)

RecordStorageUpload records an upload operation for a storage provider

func RecordSubscriptionClosed

func RecordSubscriptionClosed(lifetimeSeconds float64)

RecordSubscriptionClosed records when a subscription is closed

func RecordSubscriptionOpened

func RecordSubscriptionOpened()

RecordSubscriptionOpened records when a subscription is opened

func RecordWorkerExecution

func RecordWorkerExecution(workerName string, err error)

RecordWorkerExecution records a worker execution with appropriate labels

func RecordWorkflowEmitError

func RecordWorkflowEmitError(topic, origin string)

RecordWorkflowEmitError records a workflow emit error by topic and origin.

func RecordWorkflowOperation

func RecordWorkflowOperation(operation, origin, trigger string, duration time.Duration, err error)

RecordWorkflowOperation records a workflow operation duration and success status.

func StartFileUpload

func StartFileUpload()

StartFileUpload records the start of a file upload

Types

type LabelValues

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

func (l LabelValues) ForGraphQLOperation() []string

func (LabelValues) ForHandlerError

func (l LabelValues) ForHandlerError() []string

func (LabelValues) ForHandlerResult

func (l LabelValues) ForHandlerResult() []string

func (LabelValues) ForLogin

func (l LabelValues) ForLogin() []string

func (LabelValues) ForQueueTask

func (l LabelValues) ForQueueTask() []string

func (LabelValues) ForQueueTaskProcessed

func (l LabelValues) ForQueueTaskProcessed() []string

func (LabelValues) ForRequestValidation

func (l LabelValues) ForRequestValidation() []string

func (LabelValues) ForWorker

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

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

MetricNameBuilder helps construct consistent metric names

func NewMetricNameBuilder

func NewMetricNameBuilder() *MetricNameBuilder

NewMetricNameBuilder creates a new builder with default namespace

func (*MetricNameBuilder) Build

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

Build constructs the full metric name

func (*MetricNameBuilder) WithSubsystem

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