Skip to content

Commit

Permalink
[Bug] Fix Setting#byteSizeSetting to use whole value string (#9011)
Browse files Browse the repository at this point in the history
This fixes a bug where the Setting#byteSizeSetting static method
returned fractional byte values when calling .toString inside the
lambda. The change is to directly return the bytes value as a string
instead of using ByteSizeValue#toString which tries to be smart and
by pretty printing in a more human-friendly format.

Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize authored Jul 31, 2023
1 parent 6c075ae commit dea6889
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.common.Nullable;
import org.opensearch.common.Strings;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
Expand Down Expand Up @@ -2047,7 +2048,7 @@ static boolean parseBoolean(String b, String key, boolean isFiltered) {
}

public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue value, Property... properties) {
return byteSizeSetting(key, (s) -> value.toString(), properties);
return byteSizeSetting(key, (s) -> value.getBytes() + ByteSizeUnit.BYTES.getSuffix(), properties);
}

public static Setting<ByteSizeValue> byteSizeSetting(String key, Setting<ByteSizeValue> fallbackSetting, Property... properties) {
Expand Down

0 comments on commit dea6889

Please sign in to comment.