diff --git a/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java b/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java index a957552528831..6ac84479dc6e8 100644 --- a/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java +++ b/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java @@ -340,7 +340,7 @@ private static String formatDecimal(double value, int fractionPieces) { } public String getStringRep() { - if (duration < 0) { + if (duration < 0 && TimeUnit.MILLISECONDS == timeUnit) { return Long.toString(duration); } return switch (timeUnit) { diff --git a/libs/core/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java b/libs/core/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java index 435853ee9e789..e518ccd2d26be 100644 --- a/libs/core/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java +++ b/libs/core/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java @@ -109,6 +109,7 @@ public void testRoundTrip() { assertThat(TimeValue.parseTimeValue(s, null, "test").getStringRep(), equalTo(s)); final TimeValue t = new TimeValue(randomIntBetween(1, 128), randomFrom(TimeUnit.values())); assertThat(TimeValue.parseTimeValue(t.getStringRep(), null, "test"), equalTo(t)); + assertThat(TimeValue.timeValueSeconds(-1), equalTo(TimeValue.parseTimeValue(TimeValue.timeValueSeconds(-1).getStringRep(), "foo"))); } private static final String FRACTIONAL_TIME_VALUES_ARE_NOT_SUPPORTED = "fractional time values are not supported"; diff --git a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java index 5a7990a4e70c5..b39cc11847cca 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java @@ -35,29 +35,29 @@ public final class IndexingSlowLog implements IndexingOperationListener { public static final String INDEX_INDEXING_SLOWLOG_PREFIX = "index.indexing.slowlog"; public static final Setting INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN_SETTING = Setting.timeSetting( INDEX_INDEXING_SLOWLOG_PREFIX + ".threshold.index.warn", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO_SETTING = Setting.timeSetting( INDEX_INDEXING_SLOWLOG_PREFIX + ".threshold.index.info", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING = Setting.timeSetting( INDEX_INDEXING_SLOWLOG_PREFIX + ".threshold.index.debug", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING = Setting.timeSetting( INDEX_INDEXING_SLOWLOG_PREFIX + ".threshold.index.trace", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); diff --git a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java index 81e7cff862e32..d32b9f8e5ad63 100644 --- a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java @@ -55,57 +55,57 @@ public final class SearchSlowLog implements SearchOperationListener { ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.warn", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.info", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.debug", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.trace", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.warn", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.info", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.debug", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); public static final Setting INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING = Setting.timeSetting( INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.trace", - TimeValue.timeValueNanos(-1), - TimeValue.timeValueMillis(-1), + TimeValue.MINUS_ONE, + TimeValue.MINUS_ONE, Property.Dynamic, Property.IndexScope ); diff --git a/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java b/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java index dc2182eb6331e..a08029c7fb3b4 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java @@ -430,18 +430,18 @@ public void testSetLevels() { metadata = newIndexMeta("index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build()); settings.updateIndexMetadata(metadata); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexWarnThreshold()); settings = new IndexSettings(metadata, Settings.EMPTY); log = new IndexingSlowLog(settings, mock(SlowLogFields.class)); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getIndexWarnThreshold()); try { settings.updateIndexMetadata( newIndexMeta( diff --git a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java index d4aec300c666b..a7596cc8342f8 100644 --- a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java +++ b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java @@ -349,18 +349,18 @@ public void testSetQueryLevels() { metadata = newIndexMeta("index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build()); settings.updateIndexMetadata(metadata); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryWarnThreshold()); settings = new IndexSettings(metadata, Settings.EMPTY); log = new SearchSlowLog(settings, mock(SlowLogFields.class)); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getQueryWarnThreshold()); try { settings.updateIndexMetadata( newIndexMeta( @@ -455,18 +455,18 @@ public void testSetFetchLevels() { metadata = newIndexMeta("index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build()); settings.updateIndexMetadata(metadata); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchWarnThreshold()); settings = new IndexSettings(metadata, Settings.EMPTY); log = new SearchSlowLog(settings, mock(SlowLogFields.class)); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchTraceThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchDebugThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchInfoThreshold()); - assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchWarnThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchTraceThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchDebugThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchInfoThreshold()); + assertEquals(TimeValue.MINUS_ONE.nanos(), log.getFetchWarnThreshold()); try { settings.updateIndexMetadata( newIndexMeta(