Skip to content

Commit

Permalink
[Remove] Deprecated Fractional ByteSizeValue support (#9005)
Browse files Browse the repository at this point in the history
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 <nknize@apache.org>
  • Loading branch information
nknize committed Jul 31, 2023
1 parent 35662f0 commit 0b1f875
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Refactor] MediaTypeParser to MediaTypeParserRegistry ([#8636](https://github.com/opensearch-project/OpenSearch/pull/8636))
- Create separate SourceLookup instance per segment slice in SignificantTextAggregatorFactory ([#8807](https://github.com/opensearch-project/OpenSearch/pull/8807))
- Add support for aggregation profiler with concurrent aggregation ([#8801](https://github.com/opensearch-project/OpenSearch/pull/8801))
- [Remove] Deprecated Fractional ByteSizeValue support #9005 ([#9005](https://github.com/opensearch-project/OpenSearch/pull/9005))

### Deprecated

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

[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
package org.opensearch.ingest.common;

import org.opensearch.OpenSearchException;
import org.opensearch.OpenSearchParseException;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.ingest.IngestDocument;
import org.opensearch.ingest.Processor;
import org.opensearch.ingest.RandomDocumentPicks;
import org.hamcrest.CoreMatchers;

import static org.hamcrest.Matchers.equalTo;

public class BytesProcessorTests extends AbstractStringProcessorTestCase<Long> {

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

public void testFractional() throws Exception {
public void testFractional() {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "1.1kb");
Processor processor = newProcessor(fieldName, randomBoolean(), fieldName);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1126L));
assertWarnings(
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [1.1kb] found for setting " + "[Ingest Field]"
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> processor.execute(ingestDocument));
assertThat(
e.getMessage(),
CoreMatchers.containsString(
"Fractional bytes values have been deprecated since Legacy 6.2. " + "Use non-fractional bytes values instead:"
)
);
}
}
24 changes: 5 additions & 19 deletions server/src/main/java/org/opensearch/common/unit/ByteSizeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.logging.LogConfigurator;
import org.opensearch.common.network.NetworkService;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;

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

/**
* We have to lazy initialize the deprecation logger as otherwise a static logger here would be constructed before logging is configured
* leading to a runtime failure (see {@link LogConfigurator#checkErrorListener()} ). The premature construction would come from any
* {@link ByteSizeValue} object constructed in, for example, settings in {@link NetworkService}.
*
* @opensearch.internal
*/
static class DeprecationLoggerHolder {
static DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ByteSizeValue.class);
}

public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES);

private final long size;
Expand Down Expand Up @@ -262,14 +248,14 @@ private static ByteSizeValue parse(
return new ByteSizeValue(Long.parseLong(s), unit);
} catch (final NumberFormatException e) {
try {
final double doubleValue = Double.parseDouble(s);
DeprecationLoggerHolder.deprecationLogger.deprecate(
"fractional_byte_values",
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]",
Double.parseDouble(s);
throw new OpenSearchParseException(
"Failed to parse bytes value [{}]. Fractional bytes values have been "
+ "deprecated since Legacy 6.2. Use non-fractional bytes values instead: found for setting [{}]",
e,
initialInput,
settingName
);
return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));
} catch (final NumberFormatException ignored) {
throw new OpenSearchParseException("failed to parse [{}]", e, initialInput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,10 @@ public void testParseInvalidNumber() throws IOException {
public void testParseFractionalNumber() throws IOException {
ByteSizeUnit unit = randomValueOtherThan(ByteSizeUnit.BYTES, () -> randomFrom(ByteSizeUnit.values()));
String fractionalValue = "23.5" + unit.getSuffix();
ByteSizeValue instance = ByteSizeValue.parseBytesSizeValue(fractionalValue, "test");
assertEquals(fractionalValue, instance.toString());
assertWarnings(
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: ["
+ fractionalValue
+ "] found for setting [test]"
// test exception is thrown: fractional byte size values has been deprecated since Legacy 6.2
OpenSearchParseException e = expectThrows(
OpenSearchParseException.class,
() -> ByteSizeValue.parseBytesSizeValue(fractionalValue, "test")
);
}

Expand Down

0 comments on commit 0b1f875

Please sign in to comment.