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

XPack info and usage improvements. #3764

Merged
merged 2 commits into from
May 28, 2019
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
15 changes: 15 additions & 0 deletions src/Nest/XPack/Info/XPackInfo/XPackInfoResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,33 @@ public class MinimalLicenseInformation

public class XPackFeatures
{
[JsonProperty("ccr")]
public XPackFeature Ccr { get; internal set; }

[JsonProperty("graph")]
public XPackFeature Graph { get; internal set; }

[JsonProperty("ilm")]
public XPackFeature Ilm { get; internal set; }

[JsonProperty("logstash")]
public XPackFeature Logstash { get; internal set; }

[JsonProperty("ml")]
public XPackFeature MachineLearning { get; internal set; }

[JsonProperty("monitoring")]
public XPackFeature Monitoring { get; internal set; }

[JsonProperty("rollup")]
public XPackFeature Rollup { get; internal set; }

[JsonProperty("security")]
public XPackFeature Security { get; internal set; }

[JsonProperty("sql")]
public XPackFeature Sql { get; internal set; }

[JsonProperty("watcher")]
public XPackFeature Watcher { get; internal set; }
}
Expand Down
91 changes: 89 additions & 2 deletions src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,87 @@ namespace Nest
{
public interface IXPackUsageResponse : IResponse
{
[JsonProperty("watcher")]
AlertingUsage Alerting { get; }
[JsonProperty("ccr")]
CcrUsage Ccr { get; }

[JsonProperty("graph")]
XPackUsage Graph { get; }

[JsonProperty("logstash")]
XPackUsage Logstash { get; }

[JsonProperty("ml")]
MachineLearningUsage MachineLearning { get; }

[JsonProperty("monitoring")]
MonitoringUsage Monitoring { get; }

[JsonProperty("rollup")]
XPackUsage Rollup { get; }

[JsonProperty("security")]
SecurityUsage Security { get; }

[JsonProperty("sql")]
SqlUsage Sql { get; }

[JsonProperty("watcher")]
AlertingUsage Alerting { get; }
}

public class SqlUsage : XPackUsage
{
[JsonProperty("features")]
public IReadOnlyDictionary<string, int> Features { get; set; } = EmptyReadOnly<string, int>.Dictionary;

[JsonProperty("queries")]
public IReadOnlyDictionary<string, QueryUsage> Queries { get; set; } = EmptyReadOnly<string, QueryUsage>.Dictionary;
}

public class QueryUsage
{
[JsonProperty("total")]
public int Total { get; internal set; }

[JsonProperty("paging")]
public int Paging { get; internal set; }

[JsonProperty("failed")]
public int Failed { get; internal set; }

[JsonProperty("count")]
public int? Count { get; internal set; }
}

public class CcrUsage : XPackUsage
{
[JsonProperty("auto_follow_patterns_count")]
public int AutoFollowPatternsCount { get; internal set; }

[JsonProperty("follower_indices_count")]
public int FollowerIndicesCount { get; internal set; }
}

public class XPackUsageResponse : ResponseBase, IXPackUsageResponse
{
[JsonProperty("sql")]
public SqlUsage Sql { get; internal set; }

[JsonProperty("rollup")]
public XPackUsage Rollup { get; internal set; }

[JsonProperty("ccr")]
public CcrUsage Ccr { get; internal set; }

[JsonProperty("watcher")]
public AlertingUsage Alerting { get; internal set; }

[JsonProperty("graph")]
public XPackUsage Graph { get; internal set; }

[JsonProperty("logstash")]
public XPackUsage Logstash { get; internal set; }

[JsonProperty("ml")]
public MachineLearningUsage MachineLearning { get; internal set; }

Expand All @@ -41,7 +98,10 @@ public class XPackUsageResponse : ResponseBase, IXPackUsageResponse

public class XPackUsage
{
[JsonProperty("available")]
public bool Available { get; internal set; }

[JsonProperty("enabled")]
public bool Enabled { get; internal set; }
}

Expand All @@ -59,6 +119,9 @@ public class SecurityUsage : XPackUsage
[JsonProperty("realms")]
public IReadOnlyDictionary<string, RealmUsage> Realms { get; internal set; } = EmptyReadOnly<string, RealmUsage>.Dictionary;

[JsonProperty("role_mapping")]
public IReadOnlyDictionary<string, RoleMappingUsage> RoleMapping { get; internal set; } = EmptyReadOnly<string, RoleMappingUsage>.Dictionary;

[JsonProperty("roles")]
public IReadOnlyDictionary<string, RoleUsage> Roles { get; internal set; } = EmptyReadOnly<string, RoleUsage>.Dictionary;

Expand All @@ -68,6 +131,15 @@ public class SecurityUsage : XPackUsage
[JsonProperty("system_key")]
public SecurityFeatureToggle SystemKey { get; internal set; }

public class RoleMappingUsage
{
[JsonProperty("enabled")]
public int Enabled { get; internal set; }

[JsonProperty("size")]
public int Size { get; internal set; }
}

public class AuditUsage : SecurityFeatureToggle
{
[JsonProperty("outputs")]
Expand Down Expand Up @@ -131,12 +203,24 @@ public class AlertingUsage : XPackUsage
[JsonProperty("execution")]
public AlertingExecution Execution { get; internal set; }

[JsonProperty("watch")]
public AlertingInput Watch { get; internal set; }

public class AlertingExecution
{
[JsonProperty("actions")]
public IReadOnlyDictionary<string, ExecutionAction> Actions { get; internal set; } = EmptyReadOnly<string, ExecutionAction>.Dictionary;
}

public class AlertingInput
{
[JsonProperty("input")]
public IReadOnlyDictionary<string, AlertingCount> Input { get; internal set; } = EmptyReadOnly<string, AlertingCount>.Dictionary;

[JsonProperty("trigger")]
public IReadOnlyDictionary<string, AlertingCount> Trigger { get; internal set; } = EmptyReadOnly<string, AlertingCount>.Dictionary;
}

public class ExecutionAction
{
[JsonProperty("total")]
Expand All @@ -158,6 +242,9 @@ public class AlertingCount

public class MonitoringUsage : XPackUsage
{
[JsonProperty("collection_enabled")]
public bool CollectionEnabled { get; internal set; }

[JsonProperty("enabled_exporters")]
public IReadOnlyDictionary<string, long> EnabledExporters { get; set; } = EmptyReadOnly<string, long>.Dictionary;
}
Expand Down
90 changes: 90 additions & 0 deletions src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Threading.Tasks;
using Elastic.Xunit.XunitPlumbing;
using FluentAssertions;
using Nest;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Framework;
using Tests.Framework.EndpointTests.TestState;
using Tests.Framework.Integration;

namespace Tests.XPack.Info
{
[SkipVersion("<6.8.0", "All APIs exist in Elasticsearch 6.8.0")]
public class XPackInfoApiTests : CoordinatedIntegrationTestBase<XPackCluster>
{
private const string XPackInfoStep = nameof(XPackInfoStep);
private const string XPackUsageStep = nameof(XPackUsageStep);

public XPackInfoApiTests(XPackCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage)
{
{
XPackInfoStep, u => u.Calls<XPackInfoDescriptor, XPackInfoRequest, IXPackInfoRequest, IXPackInfoResponse>(
v => new XPackInfoRequest(),
(v, d) => d,
(v, c, f) => c.XPackInfo(f),
(v, c, f) => c.XPackInfoAsync(f),
(v, c, r) => c.XPackInfo(r),
(v, c, r) => c.XPackInfoAsync(r)
)
},
{
XPackUsageStep, u => u.Calls<XPackUsageDescriptor, XPackUsageRequest, IXPackUsageRequest, IXPackUsageResponse>(
v => new XPackUsageRequest(),
(v, d) => d,
(v, c, f) => c.XPackUsage(f),
(v, c, f) => c.XPackUsageAsync(f),
(v, c, r) => c.XPackUsage(r),
(v, c, r) => c.XPackUsageAsync(r)
)
}
}) { }

[I] public async Task XPackInfoResponse() => await Assert<XPackInfoResponse>(XPackInfoStep, (v, r) =>
{
r.IsValid.Should().BeTrue();
r.ApiCall.HttpStatusCode.Should().Be(200);

r.Build.Should().NotBeNull();
r.Features.Should().NotBeNull();
r.Features.Ccr.Should().NotBeNull();
r.Features.Graph.Should().NotBeNull();
r.Features.Ilm.Should().NotBeNull();
r.Features.Logstash.Should().NotBeNull();
r.Features.MachineLearning.Should().NotBeNull();
r.Features.MachineLearning.NativeCodeInformation.Should().NotBeNull();
r.Features.Monitoring.Should().NotBeNull();
r.Features.Rollup.Should().NotBeNull();
r.Features.Security.Should().NotBeNull();
r.Features.Sql.Should().NotBeNull();
r.Features.Watcher.Should().NotBeNull();
r.License.Should().NotBeNull();
});

[I] public async Task XPackUsageResponse() => await Assert<XPackUsageResponse>(XPackUsageStep, (v, r) =>
{
r.IsValid.Should().BeTrue();
r.ApiCall.HttpStatusCode.Should().Be(200);

r.Ccr.Should().NotBeNull();
r.Graph.Should().NotBeNull();
r.Logstash.Should().NotBeNull();
r.MachineLearning.Should().NotBeNull();
r.MachineLearning.Datafeeds.Should().NotBeNull();
r.MachineLearning.Jobs.Should().NotBeNull();
r.Monitoring.Should().NotBeNull();
r.Monitoring.EnabledExporters.Should().NotBeNull();
r.Rollup.Should().NotBeNull();
r.Security.Should().NotBeNull();
r.Security.Roles.Should().NotBeNull();
r.Security.Realms.Should().NotBeNull();
r.Security.RoleMapping.Should().NotBeNull();
r.Sql.Should().NotBeNull();
r.Sql.Features.Should().NotBeNull();
r.Sql.Queries.Should().NotBeNull();
r.Alerting.Should().NotBeNull();
r.Alerting.Count.Should().NotBeNull();
r.Alerting.Execution.Should().NotBeNull();
r.Alerting.Watch.Should().NotBeNull();
});
}
}
28 changes: 28 additions & 0 deletions src/Tests/Tests/XPack/Info/XPackInfoUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Threading.Tasks;
using Elastic.Xunit.XunitPlumbing;
using Nest;
using Tests.Framework;
using static Tests.Framework.UrlTester;

namespace Tests.XPack.Info
{
public class XPackInfoUrlTests : UrlTestsBase
{
[U] public override async Task Urls()
{
await GET("/_xpack")
.Fluent(c => c.XPackInfo())
.Request(c => c.XPackInfo())
.FluentAsync(c => c.XPackInfoAsync())
.RequestAsync(c => c.XPackInfoAsync())
;

await GET("/_xpack/usage")
.Fluent(c => c.XPackUsage())
.Request(c => c.XPackUsage())
.FluentAsync(c => c.XPackUsageAsync())
.RequestAsync(c => c.XPackUsageAsync())
;
}
}
}