Skip to content

Commit 0b1f875

Browse files
authored
[Remove] Deprecated Fractional ByteSizeValue support (opensearch-project#9005)
This commit removes the deprecation warning for fractional bytes size values and, instead, throws an OpenSearchParseException if a user passes in a fraction byte value (e.g., 5.2b).. This leniency was deprecated a long time ago in Legacy 6.2 so the removal should come as no surprise to users. Signed-off-by: Nicholas Walter Knize <[email protected]>
1 parent 35662f0 commit 0b1f875

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
103103
- [Refactor] MediaTypeParser to MediaTypeParserRegistry ([#8636](https://github.com/opensearch-project/OpenSearch/pull/8636))
104104
- Create separate SourceLookup instance per segment slice in SignificantTextAggregatorFactory ([#8807](https://github.com/opensearch-project/OpenSearch/pull/8807))
105105
- Add support for aggregation profiler with concurrent aggregation ([#8801](https://github.com/opensearch-project/OpenSearch/pull/8801))
106+
- [Remove] Deprecated Fractional ByteSizeValue support #9005 ([#9005](https://github.com/opensearch-project/OpenSearch/pull/9005))
106107

107108
### Deprecated
108109

@@ -113,4 +114,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
113114
### Security
114115

115116
[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD
116-
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x
117+
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x

modules/ingest-common/src/test/java/org/opensearch/ingest/common/BytesProcessorTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
package org.opensearch.ingest.common;
3434

3535
import org.opensearch.OpenSearchException;
36+
import org.opensearch.OpenSearchParseException;
3637
import org.opensearch.common.unit.ByteSizeUnit;
3738
import org.opensearch.common.unit.ByteSizeValue;
3839
import org.opensearch.ingest.IngestDocument;
3940
import org.opensearch.ingest.Processor;
4041
import org.opensearch.ingest.RandomDocumentPicks;
4142
import org.hamcrest.CoreMatchers;
4243

43-
import static org.hamcrest.Matchers.equalTo;
44-
4544
public class BytesProcessorTests extends AbstractStringProcessorTestCase<Long> {
4645

4746
private String modifiedInput;
@@ -101,14 +100,16 @@ public void testMissingUnits() {
101100
assertThat(exception.getMessage(), CoreMatchers.containsString("unit is missing or unrecognized"));
102101
}
103102

104-
public void testFractional() throws Exception {
103+
public void testFractional() {
105104
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
106105
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "1.1kb");
107106
Processor processor = newProcessor(fieldName, randomBoolean(), fieldName);
108-
processor.execute(ingestDocument);
109-
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1126L));
110-
assertWarnings(
111-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [1.1kb] found for setting " + "[Ingest Field]"
107+
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> processor.execute(ingestDocument));
108+
assertThat(
109+
e.getMessage(),
110+
CoreMatchers.containsString(
111+
"Fractional bytes values have been deprecated since Legacy 6.2. " + "Use non-fractional bytes values instead:"
112+
)
112113
);
113114
}
114115
}

server/src/main/java/org/opensearch/common/unit/ByteSizeValue.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
import org.opensearch.core.common.io.stream.StreamInput;
3838
import org.opensearch.core.common.io.stream.StreamOutput;
3939
import org.opensearch.core.common.io.stream.Writeable;
40-
import org.opensearch.common.logging.DeprecationLogger;
41-
import org.opensearch.common.logging.LogConfigurator;
42-
import org.opensearch.common.network.NetworkService;
4340
import org.opensearch.core.xcontent.ToXContentFragment;
4441
import org.opensearch.core.xcontent.XContentBuilder;
4542

@@ -54,17 +51,6 @@
5451
*/
5552
public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, ToXContentFragment {
5653

57-
/**
58-
* We have to lazy initialize the deprecation logger as otherwise a static logger here would be constructed before logging is configured
59-
* leading to a runtime failure (see {@link LogConfigurator#checkErrorListener()} ). The premature construction would come from any
60-
* {@link ByteSizeValue} object constructed in, for example, settings in {@link NetworkService}.
61-
*
62-
* @opensearch.internal
63-
*/
64-
static class DeprecationLoggerHolder {
65-
static DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ByteSizeValue.class);
66-
}
67-
6854
public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES);
6955

7056
private final long size;
@@ -262,14 +248,14 @@ private static ByteSizeValue parse(
262248
return new ByteSizeValue(Long.parseLong(s), unit);
263249
} catch (final NumberFormatException e) {
264250
try {
265-
final double doubleValue = Double.parseDouble(s);
266-
DeprecationLoggerHolder.deprecationLogger.deprecate(
267-
"fractional_byte_values",
268-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]",
251+
Double.parseDouble(s);
252+
throw new OpenSearchParseException(
253+
"Failed to parse bytes value [{}]. Fractional bytes values have been "
254+
+ "deprecated since Legacy 6.2. Use non-fractional bytes values instead: found for setting [{}]",
255+
e,
269256
initialInput,
270257
settingName
271258
);
272-
return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));
273259
} catch (final NumberFormatException ignored) {
274260
throw new OpenSearchParseException("failed to parse [{}]", e, initialInput);
275261
}

server/src/test/java/org/opensearch/common/unit/ByteSizeValueTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,10 @@ public void testParseInvalidNumber() throws IOException {
336336
public void testParseFractionalNumber() throws IOException {
337337
ByteSizeUnit unit = randomValueOtherThan(ByteSizeUnit.BYTES, () -> randomFrom(ByteSizeUnit.values()));
338338
String fractionalValue = "23.5" + unit.getSuffix();
339-
ByteSizeValue instance = ByteSizeValue.parseBytesSizeValue(fractionalValue, "test");
340-
assertEquals(fractionalValue, instance.toString());
341-
assertWarnings(
342-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: ["
343-
+ fractionalValue
344-
+ "] found for setting [test]"
339+
// test exception is thrown: fractional byte size values has been deprecated since Legacy 6.2
340+
OpenSearchParseException e = expectThrows(
341+
OpenSearchParseException.class,
342+
() -> ByteSizeValue.parseBytesSizeValue(fractionalValue, "test")
345343
);
346344
}
347345

0 commit comments

Comments
 (0)