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 aggregation usage to nodes usage #4737

Merged
merged 1 commit into from
Jun 10, 2020
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
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");
}
}
}
}