2023-05-19 11:42:25 +02:00
|
|
|
package telemetry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/metric"
|
|
|
|
)
|
|
|
|
|
2023-11-16 18:21:52 +01:00
|
|
|
// StoreMetrics represents all metrics related to the Store
|
2023-05-19 11:42:25 +02:00
|
|
|
type StoreMetrics struct {
|
2024-05-27 08:39:18 +02:00
|
|
|
globalLockAcquisitionDurationMicro metric.Int64Histogram
|
|
|
|
globalLockAcquisitionDurationMs metric.Int64Histogram
|
|
|
|
persistenceDurationMicro metric.Int64Histogram
|
|
|
|
persistenceDurationMs metric.Int64Histogram
|
2023-09-28 08:54:49 +02:00
|
|
|
ctx context.Context
|
2023-05-19 11:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewStoreMetrics creates an instance of StoreMetrics
|
|
|
|
func NewStoreMetrics(ctx context.Context, meter metric.Meter) (*StoreMetrics, error) {
|
2024-05-27 08:39:18 +02:00
|
|
|
globalLockAcquisitionDurationMicro, err := meter.Int64Histogram("management.store.global.lock.acquisition.duration.micro",
|
|
|
|
metric.WithUnit("microseconds"))
|
2023-05-19 11:42:25 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-09-28 08:54:49 +02:00
|
|
|
|
2024-05-27 08:39:18 +02:00
|
|
|
globalLockAcquisitionDurationMs, err := meter.Int64Histogram("management.store.global.lock.acquisition.duration.ms")
|
2023-09-28 08:54:49 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-27 08:39:18 +02:00
|
|
|
persistenceDurationMicro, err := meter.Int64Histogram("management.store.persistence.duration.micro",
|
|
|
|
metric.WithUnit("microseconds"))
|
2023-05-19 11:42:25 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-27 08:39:18 +02:00
|
|
|
persistenceDurationMs, err := meter.Int64Histogram("management.store.persistence.duration.ms")
|
2023-09-28 08:54:49 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:42:25 +02:00
|
|
|
return &StoreMetrics{
|
2023-09-28 08:54:49 +02:00
|
|
|
globalLockAcquisitionDurationMicro: globalLockAcquisitionDurationMicro,
|
|
|
|
globalLockAcquisitionDurationMs: globalLockAcquisitionDurationMs,
|
|
|
|
persistenceDurationMicro: persistenceDurationMicro,
|
|
|
|
persistenceDurationMs: persistenceDurationMs,
|
|
|
|
ctx: ctx,
|
2023-05-19 11:42:25 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountGlobalLockAcquisitionDuration counts the duration of the global lock acquisition
|
|
|
|
func (metrics *StoreMetrics) CountGlobalLockAcquisitionDuration(duration time.Duration) {
|
2023-09-28 08:54:49 +02:00
|
|
|
metrics.globalLockAcquisitionDurationMicro.Record(metrics.ctx, duration.Microseconds())
|
|
|
|
metrics.globalLockAcquisitionDurationMs.Record(metrics.ctx, duration.Milliseconds())
|
2023-05-19 11:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CountPersistenceDuration counts the duration of a store persistence operation
|
|
|
|
func (metrics *StoreMetrics) CountPersistenceDuration(duration time.Duration) {
|
2023-09-28 08:54:49 +02:00
|
|
|
metrics.persistenceDurationMicro.Record(metrics.ctx, duration.Microseconds())
|
|
|
|
metrics.persistenceDurationMs.Record(metrics.ctx, duration.Milliseconds())
|
2023-05-19 11:42:25 +02:00
|
|
|
}
|