Skip to content

Commit 2ab4db2

Browse files
Mpdreamzrusscam
authored andcommitted
Feature/node stats 6.3 (#3359)
* fix #3329 Add Adaptive selection statistics to NodeStats * add ingest statistics
1 parent 9e07d93 commit 2ab4db2

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class AdaptiveSelectionStats
7+
{
8+
/// <summary>
9+
/// The number of outstanding search requests from the node these stats are for to the keyed node.
10+
/// </summary>
11+
[JsonProperty("outgoing_searches")]
12+
public long OutgoingSearches { get; internal set; }
13+
14+
/// <summary>
15+
/// The exponentially weighted moving average queue size of search requests on the keyed node.
16+
/// </summary>
17+
[JsonProperty("avg_queue_size")]
18+
public long AverageQueueSize { get; internal set; }
19+
20+
/// <summary>
21+
/// The exponentially weighted moving average service time of search requests on the keyed node.
22+
/// </summary>
23+
/// <remarks>only set when requesting human readable response</remarks>
24+
[JsonProperty("avg_service_time")]
25+
public string AverageServiceTime { get; internal set; }
26+
27+
/// <summary>
28+
/// The exponentially weighted moving average service time of search requests on the keyed node.
29+
/// </summary>
30+
[JsonProperty("avg_service_time_ns")]
31+
public long AverageServiceTimeInNanoseconds { get; internal set; }
32+
33+
/// <summary>
34+
/// The exponentially weighted moving average response time of search requests on the keyed node.
35+
/// </summary>
36+
/// <remarks>only set when requesting human readable response</remarks>
37+
[JsonProperty("avg_response_time")]
38+
public long AverageResponseTime { get; internal set; }
39+
40+
/// <summary>
41+
/// The exponentially weighted moving average response time of search requests on the keyed node.
42+
/// </summary>
43+
[JsonProperty("avg_response_time_ns")]
44+
public long AverageResponseTimeInNanoseconds { get; internal set; }
45+
46+
/// <summary>
47+
/// The rank of this node; used for shard selection when routing search requests.
48+
/// </summary>
49+
[JsonProperty("rank")]
50+
public string Rank { get; internal set; }
51+
}
52+
}

src/Nest/Cluster/NodesStats/NodeStats.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ public class NodeStats
6060

6161
[JsonProperty("http")]
6262
public HttpStats Http { get; internal set; }
63+
64+
[JsonProperty("ingest")]
65+
public NodeIngestStats Ingest { get; internal set; }
66+
67+
[JsonProperty("adaptive_selection")]
68+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, AdaptiveSelectionStats>))]
69+
public IReadOnlyDictionary<string, AdaptiveSelectionStats> AdaptiveSelection { get; internal set; }
70+
= EmptyReadOnly<string, AdaptiveSelectionStats>.Dictionary;
6371
}
6472

73+
6574
[JsonObject]
6675
public class ScriptStats
6776
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class IngestStats
7+
{
8+
/// <summary>
9+
/// The total number of document ingested during the lifetime of this node
10+
/// </summary>
11+
[JsonProperty("count")]
12+
public long Count { get; set; }
13+
14+
/// <summary>
15+
/// The total time spent on ingest preprocessing documents during the lifetime of this node
16+
/// </summary>
17+
[JsonProperty("time_in_millis")]
18+
public long TimeInMilliseconds { get; set; }
19+
20+
/// <summary>
21+
/// The total number of documents currently being ingested.
22+
/// </summary>
23+
[JsonProperty("current")]
24+
public long Current { get; set; }
25+
26+
/// <summary>
27+
/// The total number ingest preprocessing operations failed during the lifetime of this node
28+
/// </summary>
29+
[JsonProperty("failed")]
30+
public long Failed { get; set; }
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public class NodeIngestStats
7+
{
8+
/// <summary> Overal global ingest statistics </summary>
9+
[JsonProperty("total")]
10+
public IngestStats Total { get; set; }
11+
12+
/// <summary> Per pipeline ingest statistics </summary>
13+
[JsonProperty("pipelines")]
14+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, IngestStats>))]
15+
public IReadOnlyDictionary<string, IngestStats> Pipelines { get; internal set; }
16+
= EmptyReadOnly<string, IngestStats>.Dictionary;
17+
}
18+
}

src/Tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void SeedNode()
3737
{
3838
if (!TestClient.Configuration.ForceReseed && this.AlreadySeeded()) return;
3939
// Ensure a clean slate by deleting everything regardless of whether they may already exist
40+
this.ClusterSettings();
4041
this.DeleteIndicesAndTemplates();
4142
// and now recreate everything
4243
this.CreateIndicesAndSeedIndexData();
@@ -47,6 +48,17 @@ public void SeedNode()
4748
// If raw_fields exists assume this cluster is already seeded.
4849
private bool AlreadySeeded() => this.Client.IndexTemplateExists(TestsIndexTemplateName).Exists;
4950

51+
public void ClusterSettings()
52+
{
53+
var putSettingsResponse = this.Client.ClusterPutSettings(s=>s
54+
.Transient(t=>t
55+
.Add("cluster.routing.use_adaptive_replica_selection", true)
56+
)
57+
);
58+
59+
putSettingsResponse.ShouldBeValid();
60+
}
61+
5062
public void DeleteIndicesAndTemplates()
5163
{
5264
if (this.Client.IndexTemplateExists(TestsIndexTemplateName).Exists)

src/Tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Nest;
66
using Tests.Core.Extensions;
77
using Tests.Core.ManagedElasticsearch.Clusters;
8+
using Tests.Domain;
89
using Tests.Framework;
910
using Tests.Framework.Integration;
1011
using Tests.Framework.ManagedElasticsearch.Clusters;
@@ -28,6 +29,22 @@ protected override LazyResponses ClientUsage() => Calls(
2829
protected override HttpMethod HttpMethod => HttpMethod.GET;
2930
protected override string UrlPath => "/_nodes/stats";
3031

32+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
33+
{
34+
// performing a bunch of search actions to make sure some stats have been gathered
35+
// even if this api is tested in isolation
36+
for (var i = 0; i < 5; i++)
37+
{
38+
var searchResult = client.MultiSearch(m => m
39+
.Search<Project>(s => s.MatchAll().Size(0))
40+
.Search<Project>(s => s.MatchAll().Size(0))
41+
.Search<Project>(s => s.MatchAll().Size(0))
42+
.Search<Project>(s => s.MatchAll().Size(0))
43+
);
44+
searchResult.ShouldBeValid();
45+
}
46+
}
47+
3148
protected override void ExpectResponse(INodesStatsResponse response)
3249
{
3350
response.ClusterName.Should().NotBeNullOrWhiteSpace();
@@ -47,6 +64,25 @@ protected override void ExpectResponse(INodesStatsResponse response)
4764
Assert(node.FileSystem);
4865
Assert(node.ThreadPool);
4966
Assert(node.Jvm);
67+
Assert(node.AdaptiveSelection);
68+
Assert(node.Ingest);
69+
}
70+
71+
protected void Assert(NodeIngestStats nodeIngestStats)
72+
{
73+
nodeIngestStats.Should().NotBeNull();
74+
nodeIngestStats.Total.Should().NotBeNull();
75+
nodeIngestStats.Pipelines.Should().NotBeNull().And.NotBeEmpty();
76+
}
77+
78+
protected void Assert(IReadOnlyDictionary<string, AdaptiveSelectionStats> adaptiveSelectionStats)
79+
{
80+
adaptiveSelectionStats.Should().NotBeNull(); //.And.NotBeEmpty();
81+
// TODO: for the single node case, this is empty. Should it be?
82+
// var nodeSelectionStats = adaptiveSelectionStats.First().Value;
83+
// nodeSelectionStats.Rank.Should().NotBeNullOrWhiteSpace();
84+
// nodeSelectionStats.AverageResponseTimeInNanoseconds.Should().BeGreaterThan(0);
85+
// nodeSelectionStats.AverageServiceTimeInNanoseconds.Should().BeGreaterThan(0);
5086
}
5187

5288
protected void Assert(NodeStats node)

0 commit comments

Comments
 (0)