From 172d4ff12bafc9867ae235afc97f56200125d47d Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Tue, 3 Sep 2019 11:45:56 +1000 Subject: [PATCH] Add timing stats to machine learning job stats Relates: #4001 This commit adds timing stats to Machine Learning job stats --- .../MachineLearning/Job/Config/JobStats.cs | 45 ++++++++++++++++++- .../GetJobStats/GetJobStatsApiTests.cs | 17 +++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/Nest/XPack/MachineLearning/Job/Config/JobStats.cs b/src/Nest/XPack/MachineLearning/Job/Config/JobStats.cs index a55f553641e..7a9b19664f9 100644 --- a/src/Nest/XPack/MachineLearning/Job/Config/JobStats.cs +++ b/src/Nest/XPack/MachineLearning/Job/Config/JobStats.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Runtime.Serialization; using Elasticsearch.Net; +using Elasticsearch.Net.Utf8Json; namespace Nest { @@ -57,6 +59,47 @@ public class JobStats /// [DataMember(Name = "state")] public JobState State { get; internal set; } + + /// + /// Timing-related statistics about the job's progress + /// + /// Valid only in Elasticsearch 7.3.0+ + /// + [DataMember(Name = "timing_stats")] + public TimingStats TimingStats { get; internal set; } + } + + public class TimingStats + { + [DataMember(Name = "job_id")] + public string JobId { get; internal set; } + + [DataMember(Name = "bucket_count")] + public long BucketCount { get; internal set; } + + /// + /// Minimum among all bucket processing times in milliseconds + /// + [DataMember(Name = "minimum_bucket_processing_time_ms")] + public double MinimumBucketProcessingTimeMilliseconds { get; internal set; } + + /// + /// Maximum among all bucket processing times in milliseconds + /// + [DataMember(Name = "maximum_bucket_processing_time_ms")] + public double MaximumBucketProcessingTimeMilliseconds { get; internal set; } + + /// + /// Average of all bucket processing times in milliseconds + /// + [DataMember(Name = "average_bucket_processing_time_ms")] + public double AverageBucketProcessingTimeMilliseconds { get; internal set; } + + /// + /// Exponential moving average of all bucket processing times in milliseconds + /// + [DataMember(Name = "exponential_average_bucket_processing_time_ms")] + public double ExponentialAverageBucketProcessingTimeMilliseconds { get; internal set; } } public class JobForecastStatistics diff --git a/src/Tests/Tests/XPack/MachineLearning/GetJobStats/GetJobStatsApiTests.cs b/src/Tests/Tests/XPack/MachineLearning/GetJobStats/GetJobStatsApiTests.cs index df53f6cc108..25948170b19 100644 --- a/src/Tests/Tests/XPack/MachineLearning/GetJobStats/GetJobStatsApiTests.cs +++ b/src/Tests/Tests/XPack/MachineLearning/GetJobStats/GetJobStatsApiTests.cs @@ -3,6 +3,7 @@ using Elasticsearch.Net; using FluentAssertions; using Nest; +using Tests.Configuration; using Tests.Core.Extensions; using Tests.Framework.EndpointTests.TestState; @@ -26,6 +27,11 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues foreach (var callUniqueValue in values) PutJob(client, callUniqueValue.Value); } + protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values) + { + foreach (var callUniqueValue in values) DeleteJob(client, callUniqueValue.Value); + } + protected override LazyResponses ClientUsage() => Calls( (client, f) => client.MachineLearning.GetJobStats(f), (client, f) => client.MachineLearning.GetJobStatsAsync(f), @@ -65,6 +71,17 @@ protected override void ExpectResponse(GetJobStatsResponse response) firstJob.ModelSizeStats.TotalByFieldCount.Should().Be(0); firstJob.ModelSizeStats.TotalOverFieldCount.Should().Be(0); firstJob.ModelSizeStats.TotalPartitionFieldCount.Should().Be(0); + + if (TestConfiguration.Instance.InRange(">=7.3.0")) + { + firstJob.TimingStats.Should().NotBeNull(); + firstJob.TimingStats.JobId.Should().Be(firstJob.JobId); + firstJob.TimingStats.BucketCount.Should().Be(0); + firstJob.TimingStats.MinimumBucketProcessingTimeMilliseconds.Should().Be(0); + firstJob.TimingStats.MaximumBucketProcessingTimeMilliseconds.Should().Be(0); + firstJob.TimingStats.AverageBucketProcessingTimeMilliseconds.Should().Be(0); + firstJob.TimingStats.ExponentialAverageBucketProcessingTimeMilliseconds.Should().Be(0); + } } }