Documentation
¶
Index ¶
- func HTTPMetricsMiddleware(m Recorder) gin.HandlerFunc
- type CacheWrapper
- func (m *CacheWrapper) GetActiveTokensCount(ctx context.Context, category string, ttl time.Duration) (int64, error)
- func (m *CacheWrapper) GetPendingDeviceCodesCount(ctx context.Context, ttl time.Duration) (int64, error)
- func (m *CacheWrapper) GetTotalDeviceCodesCount(ctx context.Context, ttl time.Duration) (int64, error)
- type Metrics
- func GetMetrics() *Metricsdeprecated
- func (m *Metrics) RecordAuthAttempt(method string, success bool, duration time.Duration)
- func (m *Metrics) RecordDatabaseQueryError(operation string)
- func (m *Metrics) RecordExternalAPICall(provider string, duration time.Duration)
- func (m *Metrics) RecordLogin(authSource string, success bool)
- func (m *Metrics) RecordLogout(sessionDuration time.Duration)
- func (m *Metrics) RecordOAuthCallback(provider string, success bool)
- func (m *Metrics) RecordOAuthDeviceCodeAuthorized(authorizationTime time.Duration)
- func (m *Metrics) RecordOAuthDeviceCodeGenerated(success bool)
- func (m *Metrics) RecordOAuthDeviceCodeValidation(result string)
- func (m *Metrics) RecordSessionExpired(reason string, duration time.Duration)
- func (m *Metrics) RecordSessionInvalidated(reason string)
- func (m *Metrics) RecordTokenIssued(tokenType, grantType string, generationTime time.Duration, provider string)
- func (m *Metrics) RecordTokenRefresh(success bool)
- func (m *Metrics) RecordTokenRevoked(tokenType, reason string)
- func (m *Metrics) RecordTokenValidation(result string, duration time.Duration, provider string)
- func (m *Metrics) SetActiveDeviceCodesCount(total, pending int)
- func (m *Metrics) SetActiveSessionsCount(count int)
- func (m *Metrics) SetActiveTokensCount(tokenType string, count int)
- func (m *Metrics) String() string
- type NoopMetrics
- func (n *NoopMetrics) RecordAuthAttempt(method string, success bool, duration time.Duration)
- func (n *NoopMetrics) RecordDatabaseQueryError(operation string)
- func (n *NoopMetrics) RecordExternalAPICall(provider string, duration time.Duration)
- func (n *NoopMetrics) RecordLogin(authSource string, success bool)
- func (n *NoopMetrics) RecordLogout(sessionDuration time.Duration)
- func (n *NoopMetrics) RecordOAuthCallback(provider string, success bool)
- func (n *NoopMetrics) RecordOAuthDeviceCodeAuthorized(authorizationTime time.Duration)
- func (n *NoopMetrics) RecordOAuthDeviceCodeGenerated(success bool)
- func (n *NoopMetrics) RecordOAuthDeviceCodeValidation(result string)
- func (n *NoopMetrics) RecordSessionExpired(reason string, duration time.Duration)
- func (n *NoopMetrics) RecordSessionInvalidated(reason string)
- func (n *NoopMetrics) RecordTokenIssued(tokenType, grantType string, generationTime time.Duration, provider string)
- func (n *NoopMetrics) RecordTokenRefresh(success bool)
- func (n *NoopMetrics) RecordTokenRevoked(tokenType, reason string)
- func (n *NoopMetrics) RecordTokenValidation(result string, duration time.Duration, provider string)
- func (n *NoopMetrics) SetActiveDeviceCodesCount(total, pending int)
- func (n *NoopMetrics) SetActiveSessionsCount(count int)
- func (n *NoopMetrics) SetActiveTokensCount(tokenType string, count int)
- type Recorder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMetricsMiddleware ¶
func HTTPMetricsMiddleware(m Recorder) gin.HandlerFunc
HTTPMetricsMiddleware creates a Gin middleware that records HTTP metrics
Types ¶
type CacheWrapper ¶
type CacheWrapper struct {
// contains filtered or unexported fields
}
CacheWrapper provides a read-through cache for metrics data. It queries the database on cache miss and updates the cache for subsequent requests. Uses the cache's GetWithFetch method for optimal cache-aside pattern support.
func NewCacheWrapper ¶
func NewCacheWrapper(store *store.Store, cache cache.Cache) *CacheWrapper
NewCacheWrapper creates a new cache wrapper for metrics.
func (*CacheWrapper) GetActiveTokensCount ¶
func (m *CacheWrapper) GetActiveTokensCount( ctx context.Context, category string, ttl time.Duration, ) (int64, error)
GetActiveTokensCount retrieves the count of active tokens by category. Uses cache-aside pattern via GetWithFetch for optimal performance.
func (*CacheWrapper) GetPendingDeviceCodesCount ¶
func (m *CacheWrapper) GetPendingDeviceCodesCount( ctx context.Context, ttl time.Duration, ) (int64, error)
GetPendingDeviceCodesCount retrieves the count of pending (not yet authorized) device codes. Uses cache-aside pattern via GetWithFetch for optimal performance.
func (*CacheWrapper) GetTotalDeviceCodesCount ¶
func (m *CacheWrapper) GetTotalDeviceCodesCount( ctx context.Context, ttl time.Duration, ) (int64, error)
GetTotalDeviceCodesCount retrieves the count of total (non-expired) device codes. Uses cache-aside pattern via GetWithFetch for optimal performance.
type Metrics ¶
type Metrics struct {
// OAuth Device Flow Metrics
DeviceCodesTotal *prometheus.CounterVec
DeviceCodesAuthorizedTotal prometheus.Counter
DeviceCodeValidationTotal *prometheus.CounterVec
DeviceCodesActive prometheus.Gauge
DeviceCodesPendingAuthorization prometheus.Gauge
DeviceCodeAuthorizationDuration prometheus.Histogram
// Token Metrics
TokensIssuedTotal *prometheus.CounterVec
TokensRevokedTotal *prometheus.CounterVec
TokensRefreshedTotal *prometheus.CounterVec
TokenValidationTotal *prometheus.CounterVec
TokensActive *prometheus.GaugeVec
TokenGenerationDuration *prometheus.HistogramVec
TokenValidationDuration *prometheus.HistogramVec
// Authentication Metrics
AuthAttemptsTotal *prometheus.CounterVec
AuthLoginTotal *prometheus.CounterVec
AuthLogoutTotal prometheus.Counter
AuthOAuthCallbackTotal *prometheus.CounterVec
AuthLoginDuration *prometheus.HistogramVec
AuthExternalAPIDuration *prometheus.HistogramVec
// Session Metrics
SessionsActive prometheus.Gauge
SessionsCreatedTotal prometheus.Counter
SessionsExpiredTotal *prometheus.CounterVec
SessionsInvalidatedTotal *prometheus.CounterVec
SessionDuration prometheus.Histogram
// HTTP Request Metrics
HTTPRequestsTotal *prometheus.CounterVec
HTTPRequestDuration *prometheus.HistogramVec
HTTPRequestsInFlight prometheus.Gauge
// Database Query Metrics
DatabaseQueryErrorsTotal *prometheus.CounterVec
}
Metrics holds all Prometheus metrics for the application
func GetMetrics
deprecated
func GetMetrics() *Metrics
GetMetrics returns the global metrics instance
Deprecated: Use Init(true) instead
func (*Metrics) RecordAuthAttempt ¶
RecordAuthAttempt records authentication attempt
func (*Metrics) RecordDatabaseQueryError ¶
RecordDatabaseQueryError records a database query error during metric collection
func (*Metrics) RecordExternalAPICall ¶
RecordExternalAPICall records external API call duration
func (*Metrics) RecordLogin ¶
RecordLogin records login attempt
func (*Metrics) RecordLogout ¶
RecordLogout records logout
func (*Metrics) RecordOAuthCallback ¶
RecordOAuthCallback records OAuth callback
func (*Metrics) RecordOAuthDeviceCodeAuthorized ¶
RecordOAuthDeviceCodeAuthorized records device code authorization
func (*Metrics) RecordOAuthDeviceCodeGenerated ¶
RecordOAuthDeviceCodeGenerated records device code generation
func (*Metrics) RecordOAuthDeviceCodeValidation ¶
RecordOAuthDeviceCodeValidation records device code validation result
func (*Metrics) RecordSessionExpired ¶
RecordSessionExpired records session expiration
func (*Metrics) RecordSessionInvalidated ¶
RecordSessionInvalidated records session invalidation
func (*Metrics) RecordTokenIssued ¶
func (m *Metrics) RecordTokenIssued( tokenType, grantType string, generationTime time.Duration, provider string, )
RecordTokenIssued records token issuance
func (*Metrics) RecordTokenRefresh ¶
RecordTokenRefresh records token refresh attempt
func (*Metrics) RecordTokenRevoked ¶
RecordTokenRevoked records token revocation
func (*Metrics) RecordTokenValidation ¶
RecordTokenValidation records token validation
func (*Metrics) SetActiveDeviceCodesCount ¶
SetActiveDeviceCodesCount sets the current count of active device codes (for periodic updates)
func (*Metrics) SetActiveSessionsCount ¶
SetActiveSessionsCount sets the current count of active sessions (for periodic updates)
func (*Metrics) SetActiveTokensCount ¶
SetActiveTokensCount sets the current count of active tokens (for periodic updates)
type NoopMetrics ¶
type NoopMetrics struct{}
NoopMetrics is a no-operation implementation of Recorder All methods are empty and do nothing, providing zero overhead when metrics are disabled
func (*NoopMetrics) RecordAuthAttempt ¶
func (n *NoopMetrics) RecordAuthAttempt(method string, success bool, duration time.Duration)
Authentication - noop implementations
func (*NoopMetrics) RecordDatabaseQueryError ¶
func (n *NoopMetrics) RecordDatabaseQueryError(operation string)
Database Operations - noop implementations
func (*NoopMetrics) RecordExternalAPICall ¶
func (n *NoopMetrics) RecordExternalAPICall(provider string, duration time.Duration)
func (*NoopMetrics) RecordLogin ¶
func (n *NoopMetrics) RecordLogin(authSource string, success bool)
func (*NoopMetrics) RecordLogout ¶
func (n *NoopMetrics) RecordLogout(sessionDuration time.Duration)
func (*NoopMetrics) RecordOAuthCallback ¶
func (n *NoopMetrics) RecordOAuthCallback(provider string, success bool)
func (*NoopMetrics) RecordOAuthDeviceCodeAuthorized ¶
func (n *NoopMetrics) RecordOAuthDeviceCodeAuthorized(authorizationTime time.Duration)
func (*NoopMetrics) RecordOAuthDeviceCodeGenerated ¶
func (n *NoopMetrics) RecordOAuthDeviceCodeGenerated(success bool)
OAuth Device Flow - noop implementations
func (*NoopMetrics) RecordOAuthDeviceCodeValidation ¶
func (n *NoopMetrics) RecordOAuthDeviceCodeValidation(result string)
func (*NoopMetrics) RecordSessionExpired ¶
func (n *NoopMetrics) RecordSessionExpired(reason string, duration time.Duration)
Session Management - noop implementations
func (*NoopMetrics) RecordSessionInvalidated ¶
func (n *NoopMetrics) RecordSessionInvalidated(reason string)
func (*NoopMetrics) RecordTokenIssued ¶
func (n *NoopMetrics) RecordTokenIssued( tokenType, grantType string, generationTime time.Duration, provider string, )
Token Operations - noop implementations
func (*NoopMetrics) RecordTokenRefresh ¶
func (n *NoopMetrics) RecordTokenRefresh( success bool, )
func (*NoopMetrics) RecordTokenRevoked ¶
func (n *NoopMetrics) RecordTokenRevoked( tokenType, reason string, )
func (*NoopMetrics) RecordTokenValidation ¶
func (n *NoopMetrics) RecordTokenValidation( result string, duration time.Duration, provider string, )
func (*NoopMetrics) SetActiveDeviceCodesCount ¶
func (n *NoopMetrics) SetActiveDeviceCodesCount(total, pending int)
func (*NoopMetrics) SetActiveSessionsCount ¶
func (n *NoopMetrics) SetActiveSessionsCount(count int)
func (*NoopMetrics) SetActiveTokensCount ¶
func (n *NoopMetrics) SetActiveTokensCount(tokenType string, count int)
Gauge Setters - noop implementations
type Recorder ¶
type Recorder interface {
// OAuth Device Flow
RecordOAuthDeviceCodeGenerated(success bool)
RecordOAuthDeviceCodeAuthorized(authorizationTime time.Duration)
RecordOAuthDeviceCodeValidation(result string)
// Token Operations
RecordTokenIssued(tokenType, grantType string, generationTime time.Duration, provider string)
RecordTokenRevoked(tokenType, reason string)
RecordTokenRefresh(success bool)
RecordTokenValidation(result string, duration time.Duration, provider string)
// Authentication
RecordAuthAttempt(method string, success bool, duration time.Duration)
RecordLogin(authSource string, success bool)
RecordLogout(sessionDuration time.Duration)
RecordOAuthCallback(provider string, success bool)
RecordExternalAPICall(provider string, duration time.Duration)
// Session Management
RecordSessionExpired(reason string, duration time.Duration)
RecordSessionInvalidated(reason string)
// Gauge Setters (for periodic updates)
SetActiveTokensCount(tokenType string, count int)
SetActiveDeviceCodesCount(total, pending int)
SetActiveSessionsCount(count int)
// Database Operations
RecordDatabaseQueryError(operation string)
}
Recorder defines the interface for recording application metrics Implementations include Metrics (Prometheus-based) and NoopMetrics (no-op)
func Init ¶
Init initializes metrics based on enabled flag If enabled=true, returns Prometheus-based Metrics If enabled=false, returns NoopMetrics (zero overhead) Uses sync.Once to ensure Prometheus metrics are only registered once
func NewNoopMetrics ¶
func NewNoopMetrics() Recorder
NewNoopMetrics creates a new no-operation metrics recorder