Skip to content

Commit

Permalink
Fix failing transform tests and support dates_as_epoch_millis (#5209)
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 7994d6f)
  • Loading branch information
stevejgordon authored and Mpdreamz committed Dec 28, 2020
1 parent be56367 commit 610ca70
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 67 deletions.
11 changes: 11 additions & 0 deletions src/Nest/XPack/Transform/TransformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface ITransformSettings

[DataMember(Name = "max_page_search_size")]
public int? MaxPageSearchSize { get; set; }

[DataMember(Name = "dates_as_epoch_millis")]
public bool? DatesAsEpochMilliseconds { get; set; }
}

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

/// <inheritdoc />
public int? MaxPageSearchSize { get; set; }

/// <inheritdoc />
public bool? DatesAsEpochMilliseconds { get; set; }
}

public class TransformSettingsDescriptor : DescriptorBase<TransformSettingsDescriptor, ITransformSettings>, ITransformSettings
{
float? ITransformSettings.DocsPerSecond { get; set; }
int? ITransformSettings.MaxPageSearchSize { get; set; }
bool? ITransformSettings.DatesAsEpochMilliseconds { get; set; }

/// <inheritdoc cref="ITransformSettings.DocsPerSecond"/>
public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
Expand All @@ -45,5 +52,9 @@ public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
/// <inheritdoc cref="ITransformSettings.MaxPageSearchSize"/>
public TransformSettingsDescriptor MaxPageSearchSize(int? maxPageSearchSize) =>
Assign(maxPageSearchSize, (a, v) => a.MaxPageSearchSize = v);

/// <inheritdoc cref="ITransformSettings.DatesAsEpochMilliseconds"/>
public TransformSettingsDescriptor DatesAsEpochMilliseconds(bool? datesAsEpochMillis = true) =>
Assign(datesAsEpochMillis, (a, v) => a.DatesAsEpochMilliseconds = v);
}
}
4 changes: 3 additions & 1 deletion tests/Tests.Domain/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ public class Metadata
public class ProjectTransform
{
public double? AverageCommits { get; set; }

public long WeekStartedOnMillis { get; set; }

public long WeekStartedOn { get; set; }
public DateTime WeekStartedOnDate { get; set; }

public long SumIntoMaster { get; set; }
}
Expand Down
11 changes: 9 additions & 2 deletions tests/Tests/XPack/Transform/TransformApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using FluentAssertions;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;
Expand Down Expand Up @@ -171,7 +173,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
},
GroupBy = new Dictionary<string, ISingleGroupSource>
{
{ "weekStartedOn", new DateHistogramGroupSource()
{ TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", new DateHistogramGroupSource
{
Field = Field<Project>(f => f.StartedOn),
CalendarInterval = DateInterval.Week
Expand Down Expand Up @@ -207,7 +209,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
)
)
.GroupBy(g => g
.DateHistogram("weekStartedOn", dh => dh
.DateHistogram(TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", dh => dh
.Field(f => f.StartedOn)
.CalendarInterval(DateInterval.Week)
)
Expand Down Expand Up @@ -317,6 +319,11 @@ [I] public async Task PreviewTransformResponse() => await Assert<PreviewTransfor
r.GeneratedDestinationIndex.Mappings.Should().NotBeNull();
r.GeneratedDestinationIndex.Settings.Should().NotBeNull();
r.GeneratedDestinationIndex.Aliases.Should().NotBeNull();

if (TestClient.Configuration.InRange("<7.11.0"))
r.Preview.First().WeekStartedOnMillis.Should().BeGreaterOrEqualTo(1);
else
r.Preview.First().WeekStartedOnDate.Should().NotBe(DateTime.MinValue);
});

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

0 comments on commit 610ca70

Please sign in to comment.