Skip to content

Commit

Permalink
Add aggregation usage to nodes usage
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam committed Jun 4, 2020
1 parent 76bc611 commit 1223bd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ namespace Nest
{
public class NodeUsageInformation
{
/// <summary>
/// Aggregation usage.
/// <para />
/// Available in Elasticsearch 7.8.0+
/// </summary>
[DataMember(Name ="aggregations")]
public IReadOnlyDictionary<string, IReadOnlyDictionary<string, long>> Aggregations { get; internal set; }

[DataMember(Name ="rest_actions")]
public IReadOnlyDictionary<string, int> RestActions { get; internal set; }

Expand Down
29 changes: 26 additions & 3 deletions tests/Tests/Cluster/NodesUsage/NodesUsageApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;

Expand All @@ -24,6 +26,21 @@ public NodesUsageApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(c
protected override HttpMethod HttpMethod => HttpMethod.GET;
protected override string UrlPath => "/_nodes/usage";

protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
var searchResponse = client.Search<Project>(s => s
.Size(0)
.Aggregations(a => a
.Average("avg_commits", avg => avg
.Field(f => f.NumberOfCommits)
)
)
);

if (!searchResponse.IsValid)
throw new Exception($"Exception when setting up {nameof(NodesUsageApiTests)}: {searchResponse.DebugInformation}");
}

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Nodes.Usage(),
(client, f) => client.Nodes.UsageAsync(),
Expand All @@ -43,9 +60,15 @@ protected override void ExpectResponse(NodesUsageResponse response)
response.Nodes.Should().NotBeNull();
response.Nodes.Should().HaveCount(1);

response.Nodes.First().Value.Timestamp.Should().BeBefore(DateTimeOffset.UtcNow);
response.Nodes.First().Value.Since.Should().BeBefore(DateTimeOffset.UtcNow);
response.Nodes.First().Value.RestActions.Should().NotBeNull();
var firstNode = response.Nodes.First();
firstNode.Value.Timestamp.Should().BeBefore(DateTimeOffset.UtcNow);
firstNode.Value.Since.Should().BeBefore(DateTimeOffset.UtcNow);
firstNode.Value.RestActions.Should().NotBeNull();

if (TestClient.Configuration.InRange(">=7.8.0"))
{
firstNode.Value.Aggregations.Should().NotBeNull().And.ContainKey("avg");
}
}
}
}

0 comments on commit 1223bd1

Please sign in to comment.