Skip to content

Commit

Permalink
add option metric
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocthanh1389 committed Nov 5, 2024
1 parent 9ca69ce commit d3c9d57
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,49 @@ 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 {
func RecordFloat64Gause(ctx context.Context, name string, value float64, options ...metric.ObserveOption) error {
_, err := m.Float64ObservableGauge(name,
metric.WithFloat64Callback(func(ctx context.Context, fo metric.Float64Observer) error {
fo.Observe(value)
fo.Observe(value, options...)
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 d3c9d57

Please sign in to comment.