Skip to content

Commit d632268

Browse files
Fix getTime field name to time in GetStats (#16894) (#17009) (#17047)
* Fix getTime field name to time in GetStats (#16894) * Update PR number in changelog * Deprecate getTime field and add time field in GetStats for backward compatibility * Add forRemoval flag to getTime field for future removal * 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. * 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. * Fix formatting in GetStats.java * Rename test file to better reflect test purpose * Test Add skip version for stats API human filter test under 2.19.99 * Remove unnecessary changelog entries * Add a line for styling purposes --------- (cherry picked from commit fe1f0d8) Signed-off-by: hye-on <ain0103@naver.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent fe02847 commit d632268

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2323
- Add search replica stats to segment replication stats API ([#16678](https://github.com/opensearch-project/OpenSearch/pull/16678))
2424
- Introduce framework for auxiliary transports and an experimental gRPC transport plugin ([#16534](https://github.com/opensearch-project/OpenSearch/pull/16534))
2525
- Support searching from doc_value using termQueryCaseInsensitive/termQuery in flat_object/keyword field([#16974](https://github.com/opensearch-project/OpenSearch/pull/16974/))
26+
- Added a new `time` field to replace the deprecated `getTime` field in `GetStats`. ([#17009](https://github.com/opensearch-project/OpenSearch/pull/17009))
2627

2728
### Dependencies
2829
- 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))
@@ -69,6 +70,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6970

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

7375
### Removed
7476

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
setup:
3+
- do:
4+
indices.create:
5+
index: test1
6+
body:
7+
settings:
8+
number_of_shards: 1
9+
number_of_replicas: 0
10+
wait_for_active_shards: all
11+
12+
- do:
13+
index:
14+
index: test1
15+
id: 1
16+
body: { "foo": "bar" }
17+
18+
- do:
19+
indices.refresh:
20+
index: test1
21+
22+
---
23+
"Test _stats API includes both time and getTime metrics with human filter":
24+
- skip:
25+
version: " - 2.19.99"
26+
reason: "this change is added in 3.0.0"
27+
28+
- do:
29+
indices.stats:
30+
metric: [ get ]
31+
human: true
32+
33+
- is_true: _all.primaries.get.time
34+
- is_true: _all.primaries.get.getTime
35+
- match: { _all.primaries.get.time: "0s" }
36+
- match: { _all.primaries.get.getTime: "0s" }

server/src/main/java/org/opensearch/index/get/GetStats.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.core.xcontent.XContentBuilder;
4242

4343
import java.io.IOException;
44+
import java.util.Objects;
4445

4546
/**
4647
* Stats for a search get
@@ -137,6 +138,7 @@ public long current() {
137138
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
138139
builder.startObject(Fields.GET);
139140
builder.field(Fields.TOTAL, getCount());
141+
builder.field(Fields.GET_TIME, Objects.toString(getTime()));
140142
builder.humanReadableField(Fields.TIME_IN_MILLIS, Fields.TIME, getTime());
141143
builder.field(Fields.EXISTS_TOTAL, existsCount);
142144
builder.humanReadableField(Fields.EXISTS_TIME_IN_MILLIS, Fields.EXISTS_TIME, getExistsTime());
@@ -155,7 +157,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
155157
static final class Fields {
156158
static final String GET = "get";
157159
static final String TOTAL = "total";
158-
static final String TIME = "getTime";
160+
/**
161+
* Deprecated field name for time. Use {@link #TIME} instead.
162+
*/
163+
@Deprecated(forRemoval = true)
164+
static final String GET_TIME = "getTime";
165+
static final String TIME = "time";
159166
static final String TIME_IN_MILLIS = "time_in_millis";
160167
static final String EXISTS_TOTAL = "exists_total";
161168
static final String EXISTS_TIME = "exists_time";

0 commit comments

Comments
 (0)