Skip to content

Commit

Permalink
Fix getTime field name to time in GetStats (#16894) (#17009)
Browse files Browse the repository at this point in the history
* Fix getTime field name to time in GetStats (#16894)

Signed-off-by: hye-on <ain0103@naver.com>

* Update PR number in changelog

Signed-off-by: hye-on <ain0103@naver.com>

* Deprecate getTime field and add time field in GetStats for backward compatibility

Signed-off-by: hye-on <ain0103@naver.com>

* Add forRemoval flag to getTime field for future removal

Signed-off-by: hye-on <ain0103@naver.com>

* Changed to use field instead of humanReadableField for GET_TIME in JSON response

Replaced the use of builder.humanReadableField for the GET_TIME field with builder.field(Fields.GET_TIME, Objects.toString(getTime())). This prevents the duplication of the time_in_millis field.

Signed-off-by: hye-on <ain0103@naver.com>

* Add test to validate getTime and time fields in _stats API response

getTime and time fields are verified to be included in the _stats API response and correctly aligned.

Signed-off-by: hye-on <ain0103@naver.com>

* Fix formatting in GetStats.java

Signed-off-by: hye-on <ain0103@naver.com>

* Rename test file to better reflect test purpose

Signed-off-by: hye-on <ain0103@naver.com>

* Test Add skip version for stats API human filter test under 2.19.99

Signed-off-by: hye-on <ain0103@naver.com>

* Remove unnecessary changelog entries

Signed-off-by: hye-on <ain0103@naver.com>

* Add a line for styling purposes

Signed-off-by: hye-on <ain0103@naver.com>

---------

Signed-off-by: hye-on <ain0103@naver.com>
  • Loading branch information
hye-on authored Jan 17, 2025
1 parent abb8112 commit fe1f0d8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Changes to support IP field in star tree indexing([#16641](https://github.com/opensearch-project/OpenSearch/pull/16641/))
- Support object fields in star-tree index([#16728](https://github.com/opensearch-project/OpenSearch/pull/16728/))
- Support searching from doc_value using termQueryCaseInsensitive/termQuery in flat_object/keyword field([#16974](https://github.com/opensearch-project/OpenSearch/pull/16974/))
- Added a new `time` field to replace the deprecated `getTime` field in `GetStats`. ([#17009](https://github.com/opensearch-project/OpenSearch/pull/17009))

### Dependencies
- Bump `com.google.cloud:google-cloud-core-http` from 2.23.0 to 2.47.0 ([#16504](https://github.com/opensearch-project/OpenSearch/pull/16504))
Expand Down Expand Up @@ -75,6 +76,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Deprecated
- Performing update operation with default pipeline or final pipeline is deprecated ([#16712](https://github.com/opensearch-project/OpenSearch/pull/16712))
- Marked `getTime` field as deprecated in favor of the new `time` field. ([#17009](https://github.com/opensearch-project/OpenSearch/pull/17009))

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
setup:
- do:
indices.create:
index: test1
body:
settings:
number_of_shards: 1
number_of_replicas: 0
wait_for_active_shards: all

- do:
index:
index: test1
id: 1
body: { "foo": "bar" }

- do:
indices.refresh:
index: test1

---
"Test _stats API includes both time and getTime metrics with human filter":
- skip:
version: " - 2.19.99"
reason: "this change is added in 3.0.0"

- do:
indices.stats:
metric: [ get ]
human: true

- is_true: _all.primaries.get.time
- is_true: _all.primaries.get.getTime
- match: { _all.primaries.get.time: "0s" }
- match: { _all.primaries.get.getTime: "0s" }
9 changes: 8 additions & 1 deletion server/src/main/java/org/opensearch/index/get/GetStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;

/**
* Stats for a search get
Expand Down Expand Up @@ -137,6 +138,7 @@ public long current() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.GET);
builder.field(Fields.TOTAL, getCount());
builder.field(Fields.GET_TIME, Objects.toString(getTime()));
builder.humanReadableField(Fields.TIME_IN_MILLIS, Fields.TIME, getTime());
builder.field(Fields.EXISTS_TOTAL, existsCount);
builder.humanReadableField(Fields.EXISTS_TIME_IN_MILLIS, Fields.EXISTS_TIME, getExistsTime());
Expand All @@ -155,7 +157,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
static final class Fields {
static final String GET = "get";
static final String TOTAL = "total";
static final String TIME = "getTime";
/**
* Deprecated field name for time. Use {@link #TIME} instead.
*/
@Deprecated(forRemoval = true)
static final String GET_TIME = "getTime";
static final String TIME = "time";
static final String TIME_IN_MILLIS = "time_in_millis";
static final String EXISTS_TOTAL = "exists_total";
static final String EXISTS_TIME = "exists_time";
Expand Down

0 comments on commit fe1f0d8

Please sign in to comment.