Skip to content

Commit 64b01b5

Browse files
committed
Switch interval validation to accept DateHistogramInterval
1 parent 9435f41 commit 64b01b5

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

server/src/main/java/org/elasticsearch/action/downsample/DownsampleConfig.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,28 @@ public DownsampleConfig(final StreamInput in) throws IOException {
144144
* - The target interval needs to be a multiple of the source interval
145145
* throws an IllegalArgumentException to signal that the target interval is not acceptable
146146
*/
147-
public static void validateSourceAndTargetIntervals(DownsampleConfig source, DownsampleConfig target) {
148-
long sourceMillis = source.fixedInterval.estimateMillis();
149-
long targetMillis = target.fixedInterval.estimateMillis();
147+
public static void validateSourceAndTargetIntervals(
148+
DateHistogramInterval sourceFxedInterval,
149+
DateHistogramInterval targetFixedInterval
150+
) {
151+
long sourceMillis = sourceFxedInterval.estimateMillis();
152+
long targetMillis = targetFixedInterval.estimateMillis();
150153
if (sourceMillis >= targetMillis) {
151154
// Downsampling interval must be greater than source interval
152155
throw new IllegalArgumentException(
153156
"Downsampling interval ["
154-
+ target.fixedInterval
157+
+ targetFixedInterval
155158
+ "] must be greater than the source index interval ["
156-
+ source.fixedInterval
159+
+ sourceFxedInterval
157160
+ "]."
158161
);
159162
} else if (targetMillis % sourceMillis != 0) {
160163
// Downsampling interval must be a multiple of the source interval
161164
throw new IllegalArgumentException(
162165
"Downsampling interval ["
163-
+ target.fixedInterval
166+
+ targetFixedInterval
164167
+ "] must be a multiple of the source index interval ["
165-
+ source.fixedInterval
168+
+ sourceFxedInterval
166169
+ "]."
167170
);
168171
}

x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,15 +863,16 @@ private static void validateDownsamplingConfiguration(
863863

864864
Map<String, String> meta = timestampFieldType.meta();
865865
if (meta.isEmpty() == false) {
866-
String interval = meta.get(config.getIntervalType());
867-
DownsampleConfig.SamplingMethod sourceSamplingMethod = DownsampleConfig.SamplingMethod.fromIndexMetadata(sourceIndexMetadata);
868-
if (interval != null) {
866+
String sourceInterval = meta.get(config.getIntervalType());
867+
if (sourceInterval != null) {
869868
try {
870-
DownsampleConfig sourceConfig = new DownsampleConfig(new DateHistogramInterval(interval), sourceSamplingMethod);
871-
DownsampleConfig.validateSourceAndTargetIntervals(sourceConfig, config);
869+
DownsampleConfig.validateSourceAndTargetIntervals(new DateHistogramInterval(sourceInterval), config.getFixedInterval());
872870
} catch (IllegalArgumentException exception) {
873871
e.addValidationError("Source index is a downsampled index. " + exception.getMessage());
874872
}
873+
DownsampleConfig.SamplingMethod sourceSamplingMethod = DownsampleConfig.SamplingMethod.fromIndexMetadata(
874+
sourceIndexMetadata
875+
);
875876
if (Objects.equals(sourceSamplingMethod, config.getSamplingMethodOrDefault()) == false) {
876877
e.addValidationError(
877878
"Source index is a downsampled index. Downsampling method ["

0 commit comments

Comments
 (0)