metrics

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package metrics provides webhook health monitoring for chat apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorRecord

type ErrorRecord struct {
	Timestamp time.Time
	EventType EventType
	Error     string
	Platform  string
}

ErrorRecord records details of an error.

type EventType

type EventType string

EventType represents the type of webhook event being tracked.

const (
	EventWebhookReceived   EventType = "webhook_received"
	EventWebhookValidated  EventType = "webhook_validated"
	EventWebhookParseError EventType = "webhook_parse_error"
	EventMessageProcessed  EventType = "message_processed"
	EventResponseSent      EventType = "response_sent"
	EventResponseError     EventType = "response_error"
)

type MetricsKey

type MetricsKey struct {
	Platform string
	CredID   int64
}

MetricsKey identifies a metric entry (platform + credential ID).

type Registry

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

Registry holds metrics for all registered webhook endpoints.

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns the global metrics registry.

func (*Registry) Clear

func (r *Registry) Clear(platform string, credID int64)

Clear removes metrics for a specific key.

func (*Registry) GetAllMetrics

func (r *Registry) GetAllMetrics() map[MetricsKey]*WebhookMetricsSnapshot

GetAllMetrics returns snapshots of all metrics.

func (*Registry) GetMetrics

func (r *Registry) GetMetrics(platform string, credID int64) *WebhookMetricsSnapshot

GetMetrics returns a snapshot of metrics for a specific key.

func (*Registry) RecordEvent

func (r *Registry) RecordEvent(platform string, credID int64, eventType EventType, processDuration time.Duration, err error)

RecordEvent records a webhook event.

type WebhookMetrics

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

WebhookMetrics tracks delivery metrics for webhooks.

type WebhookMetricsSnapshot

type WebhookMetricsSnapshot struct {
	TotalReceived     int64
	TotalValidated    int64
	ParseErrors       int64
	MessagesProcessed int64
	ResponsesSent     int64
	ResponseErrors    int64
	LastReceived      time.Time
	LastValidated     time.Time
	LastError         time.Time
	AvgProcessTime    time.Duration
	RecentErrors      []ErrorRecord
}

WebhookMetricsSnapshot is a thread-safe snapshot of webhook metrics.

func (*WebhookMetricsSnapshot) ErrorRate

func (s *WebhookMetricsSnapshot) ErrorRate() float64

ErrorRate calculates the error rate (errors / processed).

func (*WebhookMetricsSnapshot) IsHealthy

func (s *WebhookMetricsSnapshot) IsHealthy() bool

IsHealthy checks if the webhook is healthy (received within last 5 minutes).

func (*WebhookMetricsSnapshot) SuccessRate

func (s *WebhookMetricsSnapshot) SuccessRate() float64

SuccessRate calculates the success rate (validated / received).

Jump to

Keyboard shortcuts

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