Skip to content

[Refactor] Use Builder pattern instead of constructors for Stats API classes #19225

@sandeshkr419

Description

@sandeshkr419

Is your feature request related to a problem? Please describe

As a follow-up on #18723, I noticed other stats related classes should also utilize Builder pattern to initialize stats objects.

For example IndexingStats currently has 2 constructors: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/shard/IndexingStats.java#L191-L246

Stats related classes are exposed as PublicApi, and stats are frequently (or maybe once in a while but need to be) incremented, which causes backward-compatibility to break. This makes it difficult to add new metrics and evolve the API without causing significant disruption for developers who have adopted it. Each new stat forces a major version bump and requires users to update their code, even if they don't need the new metric.

Using this issue to track all such metric/stats classes to adopt to builder pattern and mark the existing public constructors to be on deprecation path.

Reference from SearchStats: #18707

Describe the solution you'd like

  • List down all classes to be actioned from stats API / code dive deep
  • Create builder pattern for those classes
  • Mark existing constructors as deprecated

Related component

Other

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

IndexingIndexing, Bulk Indexing and anything related to indexingOtherSearchSearch query, autocomplete ...etcenhancementEnhancement or improvement to existing feature or requestgood first issueGood for newcomers

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions