Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timing stats to machine learning job stats #4069

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/Nest/XPack/MachineLearning/Job/Config/JobStats.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -57,6 +59,47 @@ public class JobStats
/// </summary>
[DataMember(Name = "state")]
public JobState State { get; internal set; }

/// <summary>
/// Timing-related statistics about the job's progress
/// <para />
/// Valid only in Elasticsearch 7.3.0+
/// </summary>
[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; }

/// <summary>
/// Minimum among all bucket processing times in milliseconds
/// </summary>
[DataMember(Name = "minimum_bucket_processing_time_ms")]
public double MinimumBucketProcessingTimeMilliseconds { get; internal set; }

/// <summary>
/// Maximum among all bucket processing times in milliseconds
/// </summary>
[DataMember(Name = "maximum_bucket_processing_time_ms")]
public double MaximumBucketProcessingTimeMilliseconds { get; internal set; }

/// <summary>
/// Average of all bucket processing times in milliseconds
/// </summary>
[DataMember(Name = "average_bucket_processing_time_ms")]
public double AverageBucketProcessingTimeMilliseconds { get; internal set; }

/// <summary>
/// Exponential moving average of all bucket processing times in milliseconds
/// </summary>
[DataMember(Name = "exponential_average_bucket_processing_time_ms")]
public double ExponentialAverageBucketProcessingTimeMilliseconds { get; internal set; }
}

public class JobForecastStatistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Configuration;
using Tests.Core.Extensions;
using Tests.Framework.EndpointTests.TestState;

Expand All @@ -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),
Expand Down Expand Up @@ -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);
}
}
}

Expand Down