Skip to content

[chore]: Implement timer duration bucket parsing in metrics Init #7950

@junaiddshaukat

Description

@junaiddshaukat

Requirement

Implement the TODO at internal/metrics/metrics.go:69 to parse timer duration buckets from struct tags.

Current behavior:
When defining a Timer metric with a buckets tag, the Init function returns an error:
Field [X]: Buckets are not currently initialized for timer metrics

Context:
The TimerOptions struct already has a Buckets []time.Duration field defined in internal/metrics/factory.go:29, but the parsing logic was never implemented.

Proposed solution:

  • Parse bucket strings using Go's time.ParseDuration() (supports formats like "100ms", "1.5s", "2m")
  • Store parsed durations in []time.Duration
  • Pass to factory.Timer(TimerOptions{...Buckets: buckets})

Example usage after implementation:
type Metrics struct {
RequestLatency metrics.Timer metric:"request_latency" buckets:"100ms,500ms,1s,5s"
}

This provides consistency with how Histogram buckets already work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgoPull requests that update go code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions