Skip to content

Commit 7994d6f

Browse files
authored
Fix failing transform tests and support dates_as_epoch_millis (#5209)
Tests were failing due to a change in the transform API which now prefers ISO dates, rather than epoch milliseconds for dates. This resulted in a serialisation failure. This commit addresses that by conditionally producing the requests based on the version of ES being tested, so that a property of the appropriate type is used for deserialisation of the preview. This also adds support for the now dates_as_epoch_millis setting which allows the original epoch millisecond format to be returned for ES 7.11 requests, when the option is true.
1 parent f78d25d commit 7994d6f

File tree

4 files changed

+232
-67
lines changed

4 files changed

+232
-67
lines changed

src/Nest/XPack/Transform/TransformSettings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public interface ITransformSettings
2121

2222
[DataMember(Name = "max_page_search_size")]
2323
public int? MaxPageSearchSize { get; set; }
24+
25+
[DataMember(Name = "dates_as_epoch_millis")]
26+
public bool? DatesAsEpochMilliseconds { get; set; }
2427
}
2528

2629
/// <inheritdoc />
@@ -31,12 +34,16 @@ public class TransformSettings : ITransformSettings
3134

3235
/// <inheritdoc />
3336
public int? MaxPageSearchSize { get; set; }
37+
38+
/// <inheritdoc />
39+
public bool? DatesAsEpochMilliseconds { get; set; }
3440
}
3541

3642
public class TransformSettingsDescriptor : DescriptorBase<TransformSettingsDescriptor, ITransformSettings>, ITransformSettings
3743
{
3844
float? ITransformSettings.DocsPerSecond { get; set; }
3945
int? ITransformSettings.MaxPageSearchSize { get; set; }
46+
bool? ITransformSettings.DatesAsEpochMilliseconds { get; set; }
4047

4148
/// <inheritdoc cref="ITransformSettings.DocsPerSecond"/>
4249
public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
@@ -45,5 +52,9 @@ public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
4552
/// <inheritdoc cref="ITransformSettings.MaxPageSearchSize"/>
4653
public TransformSettingsDescriptor MaxPageSearchSize(int? maxPageSearchSize) =>
4754
Assign(maxPageSearchSize, (a, v) => a.MaxPageSearchSize = v);
55+
56+
/// <inheritdoc cref="ITransformSettings.DatesAsEpochMilliseconds"/>
57+
public TransformSettingsDescriptor DatesAsEpochMilliseconds(bool? datesAsEpochMillis = true) =>
58+
Assign(datesAsEpochMillis, (a, v) => a.DatesAsEpochMilliseconds = v);
4859
}
4960
}

tests/Tests.Domain/Project.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ public class Metadata
196196
public class ProjectTransform
197197
{
198198
public double? AverageCommits { get; set; }
199+
200+
public long WeekStartedOnMillis { get; set; }
199201

200-
public long WeekStartedOn { get; set; }
202+
public DateTime WeekStartedOnDate { get; set; }
201203

202204
public long SumIntoMaster { get; set; }
203205
}

tests/Tests/XPack/Transform/TransformApiTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using System.Threading.Tasks;
45
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
56
using FluentAssertions;
67
using Nest;
8+
using Tests.Core.Client;
79
using Tests.Core.Extensions;
810
using Tests.Core.ManagedElasticsearch.Clusters;
911
using Tests.Domain;
@@ -171,7 +173,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
171173
},
172174
GroupBy = new Dictionary<string, ISingleGroupSource>
173175
{
174-
{ "weekStartedOn", new DateHistogramGroupSource()
176+
{ TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", new DateHistogramGroupSource
175177
{
176178
Field = Field<Project>(f => f.StartedOn),
177179
CalendarInterval = DateInterval.Week
@@ -207,7 +209,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
207209
)
208210
)
209211
.GroupBy(g => g
210-
.DateHistogram("weekStartedOn", dh => dh
212+
.DateHistogram(TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", dh => dh
211213
.Field(f => f.StartedOn)
212214
.CalendarInterval(DateInterval.Week)
213215
)
@@ -317,6 +319,11 @@ [I] public async Task PreviewTransformResponse() => await Assert<PreviewTransfor
317319
r.GeneratedDestinationIndex.Mappings.Should().NotBeNull();
318320
r.GeneratedDestinationIndex.Settings.Should().NotBeNull();
319321
r.GeneratedDestinationIndex.Aliases.Should().NotBeNull();
322+
323+
if (TestClient.Configuration.InRange("<7.11.0"))
324+
r.Preview.First().WeekStartedOnMillis.Should().BeGreaterOrEqualTo(1);
325+
else
326+
r.Preview.First().WeekStartedOnDate.Should().NotBe(DateTime.MinValue);
320327
});
321328

322329
[I] public async Task UpdateTransformResponse() => await Assert<UpdateTransformResponse>(UpdateTransformStep, (v, r) =>

0 commit comments

Comments
 (0)