Documentation
¶
Overview ¶
Package metrics holds configuration and middleware for prometheus style metrics
Index ¶
- Constants
- Variables
- func FinishFileUpload(status string, duration float64)
- func RecordAuthentication(authType string)
- func RecordEmailValidation(success bool, result string)
- func RecordFileBufferingStrategy(strategy string)
- func RecordGraphQLOperation(operation string, duration float64, complexity int, err error)
- func RecordGraphQLRejection(reason string)
- func RecordHandlerError(statusCode int)
- func RecordHandlerResult(requestType string, success bool)
- func RecordLogin(success bool)
- func RecordQueueTaskProcessed(taskName string, duration float64, err error)
- func RecordQueueTaskPushed(queueName, taskName string, err error)
- func RecordRegistration()
- func RecordRequestValidation(requestType string, success bool)
- func RecordStorageDelete(provider string)
- func RecordStorageDownload(provider string, bytes int64)
- func RecordStorageUpload(provider string, bytes int64)
- func RecordWorkerExecution(workerName string, err error)
- func StartFileUpload()
- type LabelValues
- func (l LabelValues) ForGraphQLOperation() []string
- func (l LabelValues) ForHandlerError() []string
- func (l LabelValues) ForHandlerResult() []string
- func (l LabelValues) ForLogin() []string
- func (l LabelValues) ForQueueTask() []string
- func (l LabelValues) ForQueueTaskProcessed() []string
- func (l LabelValues) ForRequestValidation() []string
- func (l LabelValues) ForWorker() []string
- type MetricNameBuilder
- type Metrics
Constants ¶
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 ¶
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", }) 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 = 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"}) GraphQLQueryRejected = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_graphql_query_rejected_total", Help: "The total number of GraphQL queries rejected", }, []string{"reason"}) 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 = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "openlane_file_uploads_in_flight", Help: "Current number of file uploads in progress", }) FileUploadsStarted = prometheus.NewCounter(prometheus.CounterOpts{ Name: "openlane_file_uploads_started_total", Help: "Total number of file uploads started", }) FileUploadsCompleted = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_file_uploads_completed_total", Help: "Total number of file uploads completed", }, []string{"status"}) 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 = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_file_buffering_strategy_total", Help: "Total number of files buffered by strategy (memory vs disk)", }, []string{"strategy"}) StorageProviderUploads = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_storage_provider_uploads_total", Help: "Total number of files uploaded per storage provider", }, []string{"provider"}) StorageProviderBytesUploaded = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_storage_provider_bytes_uploaded_total", Help: "Total bytes uploaded per storage provider", }, []string{"provider"}) StorageProviderDownloads = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_storage_provider_downloads_total", Help: "Total number of files downloaded per storage provider", }, []string{"provider"}) StorageProviderBytesDownloaded = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_storage_provider_bytes_downloaded_total", Help: "Total bytes downloaded per storage provider", }, []string{"provider"}) StorageProviderDeletes = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "openlane_storage_provider_deletes_total", Help: "Total number of files deleted per storage provider", }, []string{"provider"}) 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"}) 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, } QueueConsumerMetrics = []prometheus.Collector{ QueueTasksProcessedDuration, QueueTasksProcessed, QueueTasksProcessedErrors, } )
These variables are stubs for now ad will be added throughout the codebase
Functions ¶
func FinishFileUpload ¶ added in v0.38.1
FinishFileUpload records the completion of a file upload
func RecordAuthentication ¶ added in v0.40.1
func RecordAuthentication(authType string)
RecordAuthentication records an authentication attempt by type
func RecordEmailValidation ¶ added in v0.36.0
RecordEmailValidation records an email validation result
func RecordFileBufferingStrategy ¶ added in v0.38.1
func RecordFileBufferingStrategy(strategy string)
RecordFileBufferingStrategy records which buffering strategy was used
func RecordGraphQLOperation ¶ added in v0.25.0
RecordGraphQLOperation records a GraphQL operation with complexity
func RecordGraphQLRejection ¶ added in v0.40.1
func RecordGraphQLRejection(reason string)
RecordGraphQLRejection records a rejected GraphQL query
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
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
RecordQueueTaskProcessed records a task being processed
func RecordQueueTaskPushed ¶ added in v0.25.0
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
RecordRequestValidation records a request validation result
func RecordStorageDelete ¶ added in v0.38.1
func RecordStorageDelete(provider string)
RecordStorageDelete records a delete operation for a storage provider
func RecordStorageDownload ¶ added in v0.38.1
RecordStorageDownload records a download operation for a storage provider
func RecordStorageUpload ¶ added in v0.38.1
RecordStorageUpload records an upload operation for a storage provider
func RecordWorkerExecution ¶ added in v0.25.0
RecordWorkerExecution records a worker execution with appropriate labels
func StartFileUpload ¶ added in v0.38.1
func StartFileUpload()
StartFileUpload records the start of a file upload
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 (*Metrics) Register ¶
func (m *Metrics) Register(metrics []prometheus.Collector) error
Register registers metrics to the default registry