Skip to content

Commit 3bfecce

Browse files
Sriram Ganeshrgsriram
authored andcommitted
Made modification to last_index_request_timestamp similar to creation timestamp
Signed-off-by: Sriram Ganesh <[email protected]>
1 parent 3ed97fb commit 3bfecce

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/stats/IndexStatsIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,21 @@ public void testLastIndexRequestTimestamp() throws Exception {
297297
.setMapping("field", "type=text,fielddata=true")
298298
.get()
299299
);
300-
assertAcked(client().admin().indices().prepareCreate(index).setSettings(settingsBuilder()).get());
301-
ensureGreen(index);
300+
assertAcked(client().admin().indices().prepareCreate("test").setSettings(settingsBuilder()).get());
301+
ensureGreen();
302302

303303
// Index a document
304-
client().prepareIndex(index).setId("1").setSource("field", "value1").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
305-
IndicesStatsResponse statsResponse = client().admin().indices().prepareStats(index).get();
306-
IndexStats stats = statsResponse.getIndex(index);
304+
client().prepareIndex("test").setId("1").setSource("field", "value1").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
305+
IndicesStatsResponse statsResponse = client().admin().indices().prepareStats("test").get();
306+
IndexStats stats = statsResponse.getIndex("test");
307307
long ts1 = stats.getLastIndexRequestTimestamp();
308308
assertTrue("Timestamp should be set after first write", ts1 > 0);
309309

310310
// Wait and index another document
311311
Thread.sleep(1000);
312-
client().prepareIndex(index).setId("2").setSource("field", "value2").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
313-
statsResponse = client().admin().indices().prepareStats(index).get();
314-
long ts2 = statsResponse.getIndex(index).getLastIndexRequestTimestamp();
312+
client().prepareIndex("test").setId("2").setSource("field", "value2").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
313+
statsResponse = client().admin().indices().prepareStats("test").get();
314+
long ts2 = statsResponse.getIndex("test").getLastIndexRequestTimestamp();
315315
assertTrue("Timestamp should increase after another write", ts2 > ts1);
316316
}
317317

server/src/main/java/org/opensearch/action/admin/indices/stats/IndexStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.opensearch.common.annotation.PublicApi;
3636
import org.opensearch.core.xcontent.ToXContentFragment;
3737
import org.opensearch.core.xcontent.XContentBuilder;
38-
import java.io.IOException;
3938

39+
import java.io.IOException;
4040
import java.util.ArrayList;
4141
import java.util.HashMap;
4242
import java.util.Iterator;

server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ public class ShardStats implements Writeable, ToXContentFragment {
7171
@Nullable
7272
private PollingIngestStats pollingIngestStats;
7373

74+
/**
75+
* Gets the current retention lease stats.
76+
*
77+
* @return the current retention lease stats
78+
*/
79+
public RetentionLeaseStats getRetentionLeaseStats() {
80+
return retentionLeaseStats;
81+
}
82+
7483
private String dataPath;
7584
private String statePath;
7685
private boolean isCustomDataPath;

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,14 @@ protected Table getTableWithHeader(final RestRequest request, final PageToken pa
425425

426426
table.addCell("creation.date", "alias:cd;default:false;desc:index creation date (millisecond value)");
427427
table.addCell("creation.date.string", "alias:cds;default:false;desc:index creation date (as string)");
428-
table.addCell("last_index_request_timestamp", "alias:lirt;default:false;desc:timestamp of last index request processed (UTC ISO 8601 string)");
428+
table.addCell(
429+
"last_index_request_timestamp",
430+
"alias:lirt;default:false;desc:timestamp of last index request processed (ms since epoch)"
431+
);
432+
table.addCell(
433+
"last_index_request_timestamp.string",
434+
"alias:lirts;default:false;desc:timestamp of last index request processed (as string)"
435+
);
429436

430437
table.addCell("store.size", "sibling:pri;alias:ss,storeSize;text-align:right;desc:store size of primaries & replicas");
431438
table.addCell("pri.store.size", "text-align:right;desc:store size of primaries");
@@ -856,7 +863,12 @@ protected Table buildTable(
856863
ZonedDateTime creationTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetadata.getCreationDate()), ZoneOffset.UTC);
857864
table.addCell(STRICT_DATE_TIME_FORMATTER.format(creationTime));
858865
Long lastIndexRequestTs = (indexStats == null ? null : indexStats.getLastIndexRequestTimestamp());
859-
table.addCell((lastIndexRequestTs == null || lastIndexRequestTs <= 0) ? null : STRICT_DATE_TIME_FORMATTER.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastIndexRequestTs), ZoneOffset.UTC)));
866+
table.addCell(lastIndexRequestTs);
867+
table.addCell(
868+
(lastIndexRequestTs == null || lastIndexRequestTs <= 0)
869+
? null
870+
: STRICT_DATE_TIME_FORMATTER.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastIndexRequestTs), ZoneOffset.UTC))
871+
);
860872

861873
table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size());
862874
table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size());

0 commit comments

Comments
 (0)