Skip to content

Commit b3af5b9

Browse files
author
Stuart Cam
authored
Indices ShardsStats in 5.x (#3194)
Fixes #3185
1 parent 1b2568f commit b3af5b9

File tree

9 files changed

+198
-4
lines changed

9 files changed

+198
-4
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Nest
45
{
56
[JsonObject]
67
public class IndicesStats
78
{
89
[JsonProperty(PropertyName = "primaries")]
9-
public IndexStats Primaries { get; set; }
10+
public IndexStats Primaries { get; internal set; }
11+
1012
[JsonProperty(PropertyName = "total")]
11-
public IndexStats Total { get; set; }
13+
public IndexStats Total { get; internal set; }
14+
15+
[JsonProperty("shards")]
16+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, ShardStats[]>))]
17+
public IReadOnlyDictionary<string, ShardStats[]> Shards { get; internal set; } = EmptyReadOnly<string, ShardStats[]>.Dictionary;
1218
}
1319
}

src/Nest/Indices/Monitoring/IndicesStats/IndicesStatsResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ public class IndicesStatsResponse : ResponseBase, IIndicesStatsResponse
2323
[JsonProperty(PropertyName = "indices")]
2424
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, IndicesStats>))]
2525
public IReadOnlyDictionary<string, IndicesStats> Indices { get; internal set; } = EmptyReadOnly<string, IndicesStats>.Dictionary;
26-
2726
}
2827
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
[JsonObject]
7+
public class ShardCommit
8+
{
9+
[JsonProperty("id")]
10+
public string Id { get; internal set; }
11+
12+
[JsonProperty("generation")]
13+
public int Generation { get; internal set; }
14+
15+
[JsonProperty("user_data")]
16+
public IReadOnlyDictionary<string, string> UserData { get; internal set; }
17+
18+
[JsonProperty("num_docs")]
19+
public long NumberOfDocuments { get; internal set; }
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class ShardPath
7+
{
8+
[JsonProperty("state_path")]
9+
public string StatePath { get; internal set; }
10+
11+
[JsonProperty("data_path")]
12+
public string DataPath { get; internal set; }
13+
14+
[JsonProperty("is_custom_data_path")]
15+
public bool IsCustomDataPath { get; internal set; }
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class ShardRouting
7+
{
8+
[JsonProperty("state")]
9+
public ShardRoutingState State { get; internal set; }
10+
11+
[JsonProperty("primary")]
12+
public bool Primary { get; internal set; }
13+
14+
[JsonProperty("node")]
15+
public string Node { get; internal set; }
16+
17+
[JsonProperty("relocating_node")]
18+
public string RelocatingNode { get; internal set; }
19+
}
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Runtime.Serialization;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
4+
5+
namespace Nest
6+
{
7+
[JsonConverter(typeof(StringEnumConverter))]
8+
public enum ShardRoutingState
9+
{
10+
/// <summary>
11+
/// The shard is not assigned to any node.
12+
/// </summary>
13+
[EnumMember(Value = "UNASSIGNED")]
14+
Unassigned,
15+
16+
/// <summary>
17+
/// The shard is initializing (probably recovering from either a peer shard or gateway).
18+
/// </summary>
19+
[EnumMember(Value = "INITIALIZING")]
20+
Initializing,
21+
22+
/// <summary>
23+
/// The shard is started.
24+
/// </summary>
25+
[EnumMember(Value = "STARTED")]
26+
Started,
27+
28+
/// <summary>
29+
/// The shard is in the process being relocated.
30+
/// </summary>
31+
[EnumMember(Value = "RELOCATING")]
32+
Relocating
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class ShardStats
7+
{
8+
[JsonProperty("routing")]
9+
public ShardRouting Routing { get; internal set; }
10+
11+
[JsonProperty("store")]
12+
public ShardStatsStore Store { get; internal set; }
13+
14+
[JsonProperty("commit")]
15+
public ShardCommit Commit { get; internal set; }
16+
17+
[JsonProperty("shard_path")]
18+
public ShardPath Path { get; internal set; }
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class ShardStatsStore
7+
{
8+
[JsonProperty("size_in_bytes")]
9+
public long SizeInBytes { get; internal set; }
10+
11+
[JsonProperty("throttle_time_in_millis")]
12+
public long ThrottleTimeInMilliseconds { get; internal set; }
13+
}
14+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Linq;
3+
using Elasticsearch.Net;
4+
using FluentAssertions;
5+
using Nest;
6+
using Tests.Framework;
7+
using Tests.Framework.Integration;
8+
using Tests.Framework.ManagedElasticsearch.Clusters;
9+
10+
namespace Tests.Indices.Monitoring.IndicesStats
11+
{
12+
public class IndicesStatsWithShardsInformationApiTests : ApiIntegrationTestBase<WritableCluster, IIndicesStatsResponse,
13+
IIndicesStatsRequest, IndicesStatsDescriptor, IndicesStatsRequest>
14+
{
15+
public IndicesStatsWithShardsInformationApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage)
16+
{
17+
}
18+
19+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
20+
{
21+
var createShardedIndex = this.Client.CreateIndex(RandomString(), c => c
22+
.Settings(settings => settings
23+
.NumberOfShards(3)
24+
)
25+
);
26+
createShardedIndex.ShouldBeValid();
27+
}
28+
29+
protected override LazyResponses ClientUsage() => Calls(
30+
fluent: (client, f) => client.IndicesStats(Infer.AllIndices, f),
31+
fluentAsync: (client, f) => client.IndicesStatsAsync(Infer.AllIndices, f),
32+
request: (client, r) => client.IndicesStats(r),
33+
requestAsync: (client, r) => client.IndicesStatsAsync(r)
34+
);
35+
36+
protected override bool ExpectIsValid => true;
37+
protected override int ExpectStatusCode => 200;
38+
protected override HttpMethod HttpMethod => HttpMethod.GET;
39+
protected override string UrlPath => "/_stats?level=shards";
40+
41+
protected override Func<IndicesStatsDescriptor, IIndicesStatsRequest> Fluent => d => d.Level(Level.Shards);
42+
43+
protected override IndicesStatsRequest Initializer => new IndicesStatsRequest(Infer.AllIndices)
44+
{
45+
Level = Level.Shards
46+
};
47+
48+
protected override void ExpectResponse(IIndicesStatsResponse response)
49+
{
50+
var firstIndex = response.Indices.First().Value;
51+
firstIndex.Shards.Should().NotBeNull();
52+
53+
var firstShard = firstIndex.Shards.Values.First();
54+
firstShard.Length.Should().Be(1);
55+
56+
var first = firstShard.First();
57+
first.Routing.Should().NotBeNull();
58+
first.Commit.Should().NotBeNull();
59+
first.Path.Should().NotBeNull();
60+
first.Store.Should().NotBeNull();
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)