Skip to content

Commit 65ff0f4

Browse files
Stuart Camcodebrain
Stuart Cam
authored andcommitted
Implement ML Info Api (#3571)
1 parent fe81d07 commit 65ff0f4

File tree

12 files changed

+262
-1
lines changed

12 files changed

+262
-1
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ApiGenerator
2626
//"rank_eval.json",
2727

2828
// these API's are new and need to be mapped
29-
"xpack.ml.info.json",
3029
"xpack.ml.delete_forecast.json",
3130
"xpack.ml.find_file_structure.json",
3231
"delete_by_query_rethrottle.json",

src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

+5
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,11 @@ public class GetAnomalyRecordsRequestParameters : RequestParameters<GetAnomalyRe
24522452
{
24532453
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
24542454
}
2455+
///<summary>Request options for XpackMlInfo<pre></pre></summary>
2456+
public partial class MachineLearningInfoRequestParameters : RequestParameters<MachineLearningInfoRequestParameters>
2457+
{
2458+
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
2459+
}
24552460
///<summary>Request options for XpackMlOpenJob<pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html</pre></summary>
24562461
public class OpenJobRequestParameters : RequestParameters<OpenJobRequestParameters>
24572462
{

src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs

+8
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,14 @@ public TResponse XpackMlGetRecords<TResponse>(string job_id, PostData body, GetA
36063606
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
36073607
public Task<TResponse> XpackMlGetRecordsAsync<TResponse>(string job_id, PostData body, GetAnomalyRecordsRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
36083608
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"_xpack/ml/anomaly_detectors/{job_id.NotNull("job_id")}/results/records"), ctx, body, _params(requestParameters));
3609+
///<summary>GET on /_xpack/ml/info <para></para></summary>
3610+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
3611+
public TResponse XpackMlInfo<TResponse>(MachineLearningInfoRequestParameters requestParameters = null)
3612+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(GET, Url($"_xpack/ml/info"), null, _params(requestParameters));
3613+
///<summary>GET on /_xpack/ml/info <para></para></summary>
3614+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
3615+
public Task<TResponse> XpackMlInfoAsync<TResponse>(MachineLearningInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
3616+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(GET, Url($"_xpack/ml/info"), ctx, null, _params(requestParameters));
36093617
///<summary>POST on /_xpack/ml/anomaly_detectors/{job_id}/_open <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html</para></summary>
36103618
///<param name="job_id">The ID of the job to open</param>
36113619
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

+6
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,12 @@ public partial interface IElasticLowLevelClient
29202920
///<param name="body">Record selection criteria</param>
29212921
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
29222922
Task<TResponse> XpackMlGetRecordsAsync<TResponse>(string job_id, PostData body, GetAnomalyRecordsRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
2923+
///<summary>GET on /_xpack/ml/info <para></para></summary>
2924+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2925+
TResponse XpackMlInfo<TResponse>(MachineLearningInfoRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
2926+
///<summary>GET on /_xpack/ml/info <para></para></summary>
2927+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2928+
Task<TResponse> XpackMlInfoAsync<TResponse>(MachineLearningInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
29232929
///<summary>POST on /_xpack/ml/anomaly_detectors/{job_id}/_open <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html</para></summary>
29242930
///<param name="job_id">The ID of the job to open</param>
29252931
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Elasticsearch.Net;
5+
6+
namespace Nest
7+
{
8+
public partial interface IElasticClient
9+
{
10+
/// <summary>
11+
/// Retrieves machine learning job results for one or more categories.
12+
/// </summary>
13+
IMachineLearningInfoResponse MachineLearningInfo(Func<MachineLearningInfoDescriptor, IMachineLearningInfoRequest> selector = null);
14+
15+
/// <inheritdoc />
16+
IMachineLearningInfoResponse MachineLearningInfo(IMachineLearningInfoRequest request);
17+
18+
/// <inheritdoc />
19+
Task<IMachineLearningInfoResponse> MachineLearningInfoAsync(Func<MachineLearningInfoDescriptor, IMachineLearningInfoRequest> selector = null,
20+
CancellationToken cancellationToken = default(CancellationToken)
21+
);
22+
23+
/// <inheritdoc />
24+
Task<IMachineLearningInfoResponse> MachineLearningInfoAsync(IMachineLearningInfoRequest request,
25+
CancellationToken cancellationToken = default(CancellationToken)
26+
);
27+
}
28+
29+
public partial class ElasticClient
30+
{
31+
/// <inheritdoc />
32+
public IMachineLearningInfoResponse MachineLearningInfo(Func<MachineLearningInfoDescriptor, IMachineLearningInfoRequest> selector = null) =>
33+
MachineLearningInfo(selector.InvokeOrDefault(new MachineLearningInfoDescriptor()));
34+
35+
/// <inheritdoc />
36+
public IMachineLearningInfoResponse MachineLearningInfo(IMachineLearningInfoRequest request) =>
37+
Dispatcher.Dispatch<IMachineLearningInfoRequest, MachineLearningInfoRequestParameters, MachineLearningInfoResponse>(
38+
request,
39+
(p, d) => LowLevelDispatch.XpackMlInfoDispatch<MachineLearningInfoResponse>(p)
40+
);
41+
42+
/// <inheritdoc />
43+
public Task<IMachineLearningInfoResponse> MachineLearningInfoAsync(Func<MachineLearningInfoDescriptor, IMachineLearningInfoRequest> selector = null,
44+
CancellationToken cancellationToken = default(CancellationToken)
45+
) =>
46+
MachineLearningInfoAsync(selector.InvokeOrDefault(new MachineLearningInfoDescriptor()), cancellationToken);
47+
48+
/// <inheritdoc />
49+
public Task<IMachineLearningInfoResponse> MachineLearningInfoAsync(IMachineLearningInfoRequest request,
50+
CancellationToken cancellationToken = default(CancellationToken)
51+
) =>
52+
Dispatcher.DispatchAsync<IMachineLearningInfoRequest, MachineLearningInfoRequestParameters, MachineLearningInfoResponse, IMachineLearningInfoResponse>(
53+
request,
54+
cancellationToken,
55+
(p, d, c) => LowLevelDispatch.XpackMlInfoDispatchAsync<MachineLearningInfoResponse>(p, c)
56+
);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
/// <summary>
7+
/// Retrieve job results for one or more categories.
8+
/// </summary>
9+
public partial interface IMachineLearningInfoRequest { }
10+
11+
/// <inheritdoc />
12+
public partial class MachineLearningInfoRequest { }
13+
14+
/// <inheritdoc />
15+
[DescriptorFor("XpackMlInfo")]
16+
public partial class MachineLearningInfoDescriptor { }
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
public interface IMachineLearningInfoResponse : IResponse
6+
{
7+
[JsonProperty("defaults")]
8+
Defaults Defaults { get; }
9+
10+
[JsonProperty("limits")]
11+
Limits Limits { get; }
12+
13+
[JsonProperty("upgrade_mode")]
14+
bool? UpgradeMode { get; }
15+
}
16+
17+
public class MachineLearningInfoResponse : ResponseBase, IMachineLearningInfoResponse
18+
{
19+
[JsonProperty("defaults")]
20+
public Defaults Defaults { get; internal set; }
21+
22+
[JsonProperty("limits")]
23+
public Limits Limits { get; internal set; }
24+
25+
[JsonProperty("upgrade_mode")]
26+
public bool? UpgradeMode { get; internal set; }
27+
}
28+
29+
public class Defaults
30+
{
31+
[JsonProperty("anomaly_detectors")]
32+
public AnomalyDetectors AnomalyDetectors { get; internal set; }
33+
34+
[JsonProperty("datafeeds")]
35+
public Datafeeds Datafeeds { get; internal set; }
36+
}
37+
38+
public class AnomalyDetectors
39+
{
40+
[JsonProperty("model_memory_limit")]
41+
public string ModelMemoryLimit { get; internal set; }
42+
43+
[JsonProperty("categorization_examples_limit")]
44+
public int CategorizationExamplesLimit { get; internal set; }
45+
46+
[JsonProperty("model_snapshot_retention_days")]
47+
public int ModelSnapshotRetentionDays { get; internal set; }
48+
}
49+
50+
public class Datafeeds
51+
{
52+
[JsonProperty("scroll_size")]
53+
public int ScrollSize { get; internal set; }
54+
}
55+
56+
public class Limits
57+
{
58+
[JsonProperty("max_model_memory_limit")]
59+
public string MaxModelMemoryLimit { get; internal set; }
60+
}
61+
}

src/Nest/_Generated/_Descriptors.generated.cs

+8
Original file line numberDiff line numberDiff line change
@@ -4435,6 +4435,14 @@ public GetAnomalyRecordsDescriptor(Id job_id) : base(r=>r.Required("job_id", job
44354435

44364436
// Request parameters
44374437

4438+
}
4439+
///<summary>descriptor for XpackMlInfo <pre></pre></summary>
4440+
public partial class MachineLearningInfoDescriptor : RequestDescriptorBase<MachineLearningInfoDescriptor,MachineLearningInfoRequestParameters, IMachineLearningInfoRequest>, IMachineLearningInfoRequest
4441+
{
4442+
// values part of the url path
4443+
4444+
// Request parameters
4445+
44384446
}
44394447
///<summary>descriptor for XpackMlOpenJob <pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html</pre></summary>
44404448
public partial class OpenJobDescriptor : RequestDescriptorBase<OpenJobDescriptor,OpenJobRequestParameters, IOpenJobRequest>, IOpenJobRequest

src/Nest/_Generated/_LowLevelDispatch.generated.cs

+20
Original file line numberDiff line numberDiff line change
@@ -3892,6 +3892,26 @@ internal partial class LowLevelDispatch
38923892
throw InvalidDispatch("XpackMlGetRecords", p, new [] { GET, POST }, "/_xpack/ml/anomaly_detectors/{job_id}/results/records");
38933893
}
38943894

3895+
internal TResponse XpackMlInfoDispatch<TResponse>(IRequest<MachineLearningInfoRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
3896+
{
3897+
switch(p.HttpMethod)
3898+
{
3899+
case GET:
3900+
return _lowLevel.XpackMlInfo<TResponse>(p.RequestParameters);
3901+
}
3902+
throw InvalidDispatch("XpackMlInfo", p, new [] { GET }, "/_xpack/ml/info");
3903+
}
3904+
3905+
internal Task<TResponse> XpackMlInfoDispatchAsync<TResponse>(IRequest<MachineLearningInfoRequestParameters> p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new()
3906+
{
3907+
switch(p.HttpMethod)
3908+
{
3909+
case GET:
3910+
return _lowLevel.XpackMlInfoAsync<TResponse>(p.RequestParameters,ct);
3911+
}
3912+
throw InvalidDispatch("XpackMlInfo", p, new [] { GET }, "/_xpack/ml/info");
3913+
}
3914+
38953915
internal TResponse XpackMlOpenJobDispatch<TResponse>(IRequest<OpenJobRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
38963916
{
38973917
switch(p.HttpMethod)

src/Nest/_Generated/_Requests.generated.cs

+12
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,18 @@ public partial class ListTasksRequest : PlainRequestBase<ListTasksRequestParamet
38733873
public string ParentNode { get => Q<string>("parent_node"); set => Q("parent_node", value); }
38743874
}
38753875
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
3876+
public partial interface IMachineLearningInfoRequest : IRequest<MachineLearningInfoRequestParameters>
3877+
{
3878+
}
3879+
///<summary>Request parameters for XpackMlInfo <pre></pre></summary>
3880+
public partial class MachineLearningInfoRequest : PlainRequestBase<MachineLearningInfoRequestParameters>, IMachineLearningInfoRequest
3881+
{
3882+
protected IMachineLearningInfoRequest Self => this;
3883+
// values part of the url path
3884+
3885+
// Request parameters
3886+
}
3887+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
38763888
public partial interface IMigrationAssistanceRequest : IRequest<MigrationAssistanceRequestParameters>
38773889
{
38783890
Indices Index { get; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Linq;
3+
using Elasticsearch.Net;
4+
using FluentAssertions;
5+
using Nest;
6+
using Tests.Core.Extensions;
7+
using Tests.Framework;
8+
using Tests.Framework.Integration;
9+
using Tests.Framework.ManagedElasticsearch.Clusters;
10+
11+
namespace Tests.XPack.MachineLearning.Info
12+
{
13+
public class MachineLearningInfoApiTests
14+
: MachineLearningIntegrationTestBase<IMachineLearningInfoResponse, IMachineLearningInfoRequest, MachineLearningInfoDescriptor, MachineLearningInfoRequest>
15+
{
16+
public MachineLearningInfoApiTests(MachineLearningCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
17+
18+
protected override bool ExpectIsValid => true;
19+
protected override object ExpectJson => null;
20+
protected override int ExpectStatusCode => 200;
21+
protected override Func<MachineLearningInfoDescriptor, IMachineLearningInfoRequest> Fluent => f => f;
22+
protected override HttpMethod HttpMethod => HttpMethod.GET;
23+
24+
protected override MachineLearningInfoRequest Initializer => new MachineLearningInfoRequest();
25+
26+
protected override string UrlPath => $"_xpack/ml/info";
27+
protected override LazyResponses ClientUsage() => Calls(
28+
(client, f) => client.MachineLearningInfo(f),
29+
(client, f) => client.MachineLearningInfoAsync(f),
30+
(client, r) => client.MachineLearningInfo(r),
31+
(client, r) => client.MachineLearningInfoAsync(r)
32+
);
33+
34+
protected override MachineLearningInfoDescriptor NewDescriptor() => new MachineLearningInfoDescriptor();
35+
36+
protected override void ExpectResponse(IMachineLearningInfoResponse response)
37+
{
38+
response.ShouldBeValid();
39+
40+
response.Defaults.AnomalyDetectors.ModelMemoryLimit.Should().Be("1gb");
41+
response.Defaults.AnomalyDetectors.CategorizationExamplesLimit.Should().Be(4);
42+
response.Defaults.AnomalyDetectors.ModelSnapshotRetentionDays.Should().Be(1);
43+
44+
response.Defaults.Datafeeds.ScrollSize.Should().Be(1000);
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Threading.Tasks;
2+
using Elastic.Xunit.XunitPlumbing;
3+
using Nest;
4+
using Tests.Framework;
5+
using static Tests.Framework.UrlTester;
6+
7+
namespace Tests.XPack.MachineLearning.GetCategories
8+
{
9+
public class InfoUrlTests : UrlTestsBase
10+
{
11+
[U] public override async Task Urls()
12+
{
13+
await GET("_xpack/ml/info")
14+
.Fluent(c => c.MachineLearningInfo())
15+
.Request(c => c.MachineLearningInfo(new MachineLearningInfoRequest()))
16+
.FluentAsync(c => c.MachineLearningInfoAsync())
17+
.RequestAsync(c => c.MachineLearningInfoAsync(new MachineLearningInfoRequest()));
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)