Skip to content

Commit

Permalink
refactor(balance-worker): remove old metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Oct 25, 2024
1 parent c4a9091 commit 4906a47
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 51 deletions.
4 changes: 0 additions & 4 deletions openmeter/entitlement/balanceworker/entitlementhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ func (w *Worker) createSnapshotEvent(ctx context.Context, entitlementEntity *ent
),
)

w.metricRecalculationTimeOld.Record(ctx, time.Since(calculationStart).Milliseconds(), metric.WithAttributes(
attribute.String(metricAttributeKeyEntitltementType, string(entitlementEntity.EntitlementType)),
))

mappedValues, err := entitlementdriver.MapEntitlementValueToAPI(value)
if err != nil {
return nil, fmt.Errorf("failed to map entitlement value: %w", err)
Expand Down
34 changes: 0 additions & 34 deletions openmeter/entitlement/balanceworker/recalculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ const (
metricNameRecalculationTime = "openmeter.balance_worker.entitlement_recalculation_time_ms"
metricNameRecalculationJobCalculationTime = "openmeter.balance_worker.entitlement_recalculation_job_calculation_time_ms"

// TODO: remove old metrics once not used anymore
metricNameRecalculationTimeOld = "balance_worker.entitlement_recalculation_time_ms"
metricNameRecalculationJobCalculationTimeOld = "balance_worker.entitlement_recalculation_job_calculation_time_ms"

metricAttributeKeyEntitltementType = "entitlement_type"
)

Expand Down Expand Up @@ -107,30 +103,12 @@ func NewRecalculator(opts RecalculatorOptions) (*Recalculator, error) {
return nil, fmt.Errorf("failed to create recalculation time histogram: %w", err)
}

metricRecalculationTimeOld, err := opts.Meter.Int64Histogram(
metricNameRecalculationTimeOld,
metric.WithDescription("Entitlement recalculation time"),
)
if err != nil {
return nil, fmt.Errorf("failed to create recalculation time histogram: %w", err)
}

metricRecalculationJobRecalculationTimeOld, err := opts.Meter.Int64Histogram(
metricNameRecalculationJobCalculationTimeOld,
metric.WithDescription("Time takes to recalculate the entitlements including the necessary data fetches"),
)
if err != nil {
return nil, fmt.Errorf("failed to create recalculation time histogram: %w", err)
}

return &Recalculator{
opts: opts,
featureCache: featureCache,
subjectCache: subjectCache,
metricRecalculationTime: metricRecalculationTime,
metricRecalculationJobRecalculationTime: metricRecalculationJobRecalculationTime,
metricRecalculationTimeOld: metricRecalculationTimeOld,
metricRecalculationJobRecalculationTimeOld: metricRecalculationJobRecalculationTimeOld,
}, nil
}

Expand Down Expand Up @@ -169,12 +147,6 @@ func (r *Recalculator) processEntitlements(ctx context.Context, entitlements []e
attribute.String(metricAttributeKeyEntitltementType, string(ent.EntitlementType)),
),
)

r.metricRecalculationJobRecalculationTimeOld.Record(ctx,
time.Since(start).Milliseconds(),
metric.WithAttributes(
attribute.String(metricAttributeKeyEntitltementType, string(ent.EntitlementType)),
))
}

return errs
Expand Down Expand Up @@ -245,12 +217,6 @@ func (r *Recalculator) sendEntitlementUpdatedEvent(ctx context.Context, ent enti
),
)

r.metricRecalculationTimeOld.Record(ctx,
time.Since(calculatedAt).Milliseconds(),
metric.WithAttributes(
attribute.String(metricAttributeKeyEntitltementType, string(ent.EntitlementType)),
))

mappedValues, err := entitlementdriver.MapEntitlementValueToAPI(value)
if err != nil {
return fmt.Errorf("failed to map entitlement value: %w", err)
Expand Down
14 changes: 1 addition & 13 deletions openmeter/entitlement/balanceworker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ type Worker struct {
highWatermarkCache *lru.Cache[string, highWatermarkCacheEntry]

metricRecalculationTime metric.Int64Histogram

// TODO: remove old metrics once not used anymore
metricRecalculationTimeOld metric.Int64Histogram
}

func New(opts WorkerOptions) (*Worker, error) {
Expand All @@ -86,22 +83,13 @@ func New(opts WorkerOptions) (*Worker, error) {
return nil, fmt.Errorf("failed to create recalculation time histogram: %w", err)
}

metricRecalculationTimeOld, err := opts.Router.MetricMeter.Int64Histogram(
metricNameRecalculationTimeOld,
metric.WithDescription("Entitlement recalculation time"),
)
if err != nil {
return nil, fmt.Errorf("failed to create recalculation time histogram: %w", err)
}

worker := &Worker{
opts: opts,
entitlement: opts.Entitlement,
repo: opts.Repo,
highWatermarkCache: highWatermarkCache,

metricRecalculationTime: metricRecalculationTime,
metricRecalculationTimeOld: metricRecalculationTimeOld,
metricRecalculationTime: metricRecalculationTime,
}

router, err := router.NewDefaultRouter(opts.Router)
Expand Down

0 comments on commit 4906a47

Please sign in to comment.