mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
chore: update dependencies (#5401)
* chore(backend): update dependencies * chore(pipeline): update golangci-lint
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,8 +23,8 @@ type Metrics interface {
|
||||
GetMetricsProvider() metric.MeterProvider
|
||||
RegisterCounter(name, description string) error
|
||||
AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error
|
||||
RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error
|
||||
RegisterValueObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error
|
||||
RegisterUpDownSumObserver(name, description string, callbackFunc instrument.Int64Callback) error
|
||||
RegisterValueObserver(name, description string, callbackFunc instrument.Int64Callback) error
|
||||
}
|
||||
|
||||
var M Metrics
|
||||
@@ -56,14 +57,14 @@ func AddCount(ctx context.Context, name string, value int64, labels map[string]a
|
||||
return M.AddCount(ctx, name, value, labels)
|
||||
}
|
||||
|
||||
func RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error {
|
||||
func RegisterUpDownSumObserver(name, description string, callbackFunc instrument.Int64Callback) error {
|
||||
if M == nil {
|
||||
return nil
|
||||
}
|
||||
return M.RegisterUpDownSumObserver(name, description, callbackFunc)
|
||||
}
|
||||
|
||||
func RegisterValueObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error {
|
||||
func RegisterValueObserver(name, description string, callbackFunc instrument.Int64Callback) error {
|
||||
if M == nil {
|
||||
return nil
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/prometheus"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
|
||||
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
sdk_metric "go.opentelemetry.io/otel/sdk/metric"
|
||||
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/metrics"
|
||||
@@ -31,39 +30,35 @@ func NewMetrics(meterName string) (metrics.Metrics, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exporter, err := prometheus.New(
|
||||
prometheus.Config{},
|
||||
controller.New(
|
||||
processor.NewFactory(
|
||||
selector.NewWithHistogramDistribution(),
|
||||
aggregation.CumulativeTemporalitySelector(),
|
||||
processor.WithMemory(true),
|
||||
),
|
||||
controller.WithResource(resource),
|
||||
),
|
||||
)
|
||||
exporter, err := prometheus.New()
|
||||
if err != nil {
|
||||
return &Metrics{}, err
|
||||
}
|
||||
return &Metrics{
|
||||
Exporter: exporter,
|
||||
Meter: exporter.MeterProvider().Meter(meterName),
|
||||
Meter: sdk_metric.NewMeterProvider(
|
||||
sdk_metric.WithReader(exporter),
|
||||
sdk_metric.WithResource(resource),
|
||||
).Meter(meterName),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *Metrics) GetExporter() http.Handler {
|
||||
return m.Exporter
|
||||
return promhttp.Handler()
|
||||
}
|
||||
|
||||
func (m *Metrics) GetMetricsProvider() metric.MeterProvider {
|
||||
return m.Exporter.MeterProvider()
|
||||
return sdk_metric.NewMeterProvider(sdk_metric.WithReader(m.Exporter))
|
||||
}
|
||||
|
||||
func (m *Metrics) RegisterCounter(name, description string) error {
|
||||
if _, exists := m.Counters.Load(name); exists {
|
||||
return nil
|
||||
}
|
||||
counter := metric.Must(m.Meter).NewInt64Counter(name, metric.WithDescription(description))
|
||||
counter, err := m.Meter.Int64Counter(name, instrument.WithDescription(description))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Counters.Store(name, counter)
|
||||
return nil
|
||||
}
|
||||
@@ -73,29 +68,35 @@ func (m *Metrics) AddCount(ctx context.Context, name string, value int64, labels
|
||||
if !exists {
|
||||
return caos_errs.ThrowNotFound(nil, "METER-4u8fs", "Errors.Metrics.Counter.NotFound")
|
||||
}
|
||||
counter.(metric.Int64Counter).Add(ctx, value, MapToKeyValue(labels)...)
|
||||
counter.(instrument.Int64Counter).Add(ctx, value, MapToKeyValue(labels)...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Metrics) RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error {
|
||||
func (m *Metrics) RegisterUpDownSumObserver(name, description string, callbackFunc instrument.Int64Callback) error {
|
||||
if _, exists := m.UpDownSumObserver.Load(name); exists {
|
||||
return nil
|
||||
}
|
||||
sumObserver := metric.Must(m.Meter).NewInt64UpDownCounterObserver(
|
||||
name, callbackFunc, metric.WithDescription(description))
|
||||
|
||||
m.UpDownSumObserver.Store(name, sumObserver)
|
||||
counter, err := m.Meter.Int64ObservableUpDownCounter(name, instrument.WithInt64Callback(callbackFunc), instrument.WithDescription(description))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.UpDownSumObserver.Store(name, counter)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Metrics) RegisterValueObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error {
|
||||
func (m *Metrics) RegisterValueObserver(name, description string, callbackFunc instrument.Int64Callback) error {
|
||||
if _, exists := m.UpDownSumObserver.Load(name); exists {
|
||||
return nil
|
||||
}
|
||||
sumObserver := metric.Must(m.Meter).NewInt64GaugeObserver(
|
||||
name, callbackFunc, metric.WithDescription(description))
|
||||
|
||||
m.UpDownSumObserver.Store(name, sumObserver)
|
||||
gauge, err := m.Meter.Int64ObservableGauge(name, instrument.WithInt64Callback(callbackFunc), instrument.WithDescription(description))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.UpDownSumObserver.Store(name, gauge)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user