Skip to content

Commit

Permalink
add option metric (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocthanh1389 authored Nov 5, 2024
1 parent 9ca69ce commit 42b43ce
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,40 @@ func init() {
m = kybermetric.Meter()
}

func RecordFloat64Histogram(ctx context.Context, name string, value float64) error {
func RecordFloat64Histogram(ctx context.Context, name string, value float64, options ...metric.RecordOption) error {
hist, err := m.Float64Histogram(name)
if err != nil {
return err
}
hist.Record(ctx, value)
hist.Record(ctx, value, options...)
return nil
}

func RecordFloat64Gause(ctx context.Context, name string, value float64) error {
_, err := m.Float64ObservableGauge(name,
metric.WithFloat64Callback(func(ctx context.Context, fo metric.Float64Observer) error {
fo.Observe(value)
return nil
}))
return err
}

func RecordCounter(ctx context.Context, name string, value int64) error {
func RecordCounter(ctx context.Context, name string, value int64, options ...metric.AddOption) error {
counter, err := m.Int64Counter(name)
if err != nil {
return err
}
counter.Add(ctx, value)
counter.Add(ctx, value, options...)
return nil
}

func RecordUpdownCounter(ctx context.Context, name string, value int64) error {
func RecordUpdownCounter(ctx context.Context, name string, value int64, options ...metric.AddOption) error {
counter, err := m.Int64UpDownCounter(name)
if err != nil {
return err
}
counter.Add(ctx, value)
counter.Add(ctx, value, options...)
return nil
}

func RecordInt64HistogramWithMetricOption(ctx context.Context, name string, value int64,
options ...metric.Int64HistogramOption,
) error {
hist, err := m.Int64Histogram(name, options...)
if err != nil {
return err
}
hist.Record(ctx, value)
return nil
}

0 comments on commit 42b43ce

Please sign in to comment.