Skip to content

Commit 7b9e122

Browse files
committed
added response structure for XPackUsage()
1 parent fbfeb22 commit 7b9e122

File tree

4 files changed

+220
-9
lines changed

4 files changed

+220
-9
lines changed

src/Nest/Nest.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,5 @@
1717
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
1818
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
1919
<PackageReference Include="System.Linq.Queryable" Version="4.0.1" />
20-
</ItemGroup>
21-
<ItemGroup>
22-
<Folder Include="Search\FieldCaps" />
23-
</ItemGroup>
24-
<!--<Import Project="..\..\.paket\Paket.Restore.targets" />-->
25-
</Project>
20+
</ItemGroup> <!--<Import Project="..\..\.paket\Paket.Restore.targets" />-->
21+
</Project>

src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,202 @@ namespace Nest
77
{
88
public interface IXPackUsageResponse : IResponse
99
{
10+
[JsonProperty("graph")]
11+
XPackUsage Graph { get; }
12+
13+
[JsonProperty("monitoring")]
14+
MonitoringUsage Monitoring { get; }
15+
16+
[JsonProperty("ml")]
17+
MachineLearningUsage MachineLearning { get; }
18+
19+
[JsonProperty("watcher")]
20+
AlertingUsage Alerting { get; }
21+
22+
[JsonProperty("security")]
23+
SecurityUsage Security { get; }
1024
}
1125

1226
public class XPackUsageResponse : ResponseBase, IXPackUsageResponse
1327
{
14-
public XPackUsage Graph { get; set; }
15-
}
28+
[JsonProperty("graph")]
29+
public XPackUsage Graph { get; internal set; }
30+
31+
[JsonProperty("monitoring")]
32+
public MonitoringUsage Monitoring { get; internal set; }
33+
34+
[JsonProperty("ml")]
35+
public MachineLearningUsage MachineLearning { get; internal set; }
1636

37+
[JsonProperty("watcher")]
38+
public AlertingUsage Alerting { get; internal set; }
39+
40+
[JsonProperty("security")]
41+
public SecurityUsage Security { get; internal set; }
42+
}
1743

1844
public class XPackUsage
1945
{
2046
public bool Available { get; internal set; }
2147
public bool Enabled { get; internal set; }
2248
}
2349

50+
public class SecurityUsage : XPackUsage
51+
{
52+
[JsonProperty("system_key")]
53+
public SecurityFeatureToggle SystemKey { get; internal set; }
54+
55+
[JsonProperty("anonymous")]
56+
public SecurityFeatureToggle Anonymous { get; internal set; }
57+
58+
[JsonProperty("ssl")]
59+
public SslUsage Ssl { get; internal set; }
60+
61+
[JsonProperty("ipfilter")]
62+
public IpFilterUsage IpFilter { get; internal set; }
63+
64+
[JsonProperty("audit")]
65+
public AuditUsage Audit { get; internal set; }
66+
67+
[JsonProperty("roles")]
68+
public IReadOnlyDictionary<string, RoleUsage> Roles { get; internal set; } = EmptyReadOnly<string, RoleUsage>.Dictionary;
69+
70+
[JsonProperty("realms")]
71+
public IReadOnlyDictionary<string, RealmUsage> Realms { get; internal set; } = EmptyReadOnly<string, RealmUsage>.Dictionary;
72+
73+
public class AuditUsage : SecurityFeatureToggle
74+
{
75+
[JsonProperty("outputs")]
76+
public IReadOnlyCollection<string> Outputs { get; internal set; } = EmptyReadOnly<string>.Collection;
77+
}
78+
79+
public class IpFilterUsage
80+
{
81+
[JsonProperty("http")]
82+
public bool Http { get; internal set; }
83+
84+
[JsonProperty("transport")]
85+
public bool Transport { get; internal set; }
86+
}
87+
88+
public class RealmUsage : XPackUsage
89+
{
90+
[JsonProperty("name")]
91+
public IReadOnlyCollection<string> Name { get; internal set; } = EmptyReadOnly<string>.Collection;
92+
93+
[JsonProperty("size")]
94+
public IReadOnlyCollection<long> Size { get; internal set; } = EmptyReadOnly<long>.Collection;
95+
96+
[JsonProperty("order")]
97+
public IReadOnlyCollection<long> Order { get; internal set; } = EmptyReadOnly<long>.Collection;
98+
}
99+
100+
public class RoleUsage
101+
{
102+
[JsonProperty("dls")]
103+
public bool Dls { get; internal set; }
104+
105+
[JsonProperty("fls")]
106+
public bool Fls { get; internal set; }
107+
108+
[JsonProperty("size")]
109+
public long Size { get; internal set; }
110+
}
111+
112+
public class SslUsage
113+
{
114+
[JsonProperty("http")]
115+
public SecurityFeatureToggle Http { get; internal set; }
116+
117+
[JsonProperty("transport")]
118+
public SecurityFeatureToggle Transport { get; internal set; }
119+
}
120+
121+
public class SecurityFeatureToggle
122+
{
123+
[JsonProperty("enabled")]
124+
public bool Enabled { get; internal set; }
125+
}
126+
}
127+
128+
public class AlertingUsage : XPackUsage
129+
{
130+
[JsonProperty("execution")]
131+
public AlertingExecution Execution { get; internal set; }
132+
133+
[JsonProperty("count")]
134+
public AlertingCount Count { get; internal set; }
135+
136+
public class AlertingExecution
137+
{
138+
[JsonProperty("actions")]
139+
public IReadOnlyDictionary<string, ExecutionAction> Actions { get; internal set; } = EmptyReadOnly<string, ExecutionAction>.Dictionary;
140+
}
141+
142+
public class ExecutionAction
143+
{
144+
[JsonProperty("total")]
145+
public long Total { get; internal set; }
146+
147+
[JsonProperty("total_in_ms")]
148+
public long TotalInMilliseconds { get; internal set; }
149+
}
150+
151+
public class AlertingCount
152+
{
153+
[JsonProperty("total")]
154+
public long Total { get; internal set; }
155+
156+
[JsonProperty("active")]
157+
public long Active { get; internal set; }
158+
}
159+
}
160+
161+
public class MonitoringUsage : XPackUsage
162+
{
163+
[JsonProperty("enabled_exporters")]
164+
public IReadOnlyDictionary<string, long> EnabledExporters { get; set; } = EmptyReadOnly<string, long>.Dictionary;
165+
}
166+
167+
public class MachineLearningUsage : XPackUsage
168+
{
169+
[JsonProperty("jobs")]
170+
public IReadOnlyDictionary<string, Job> Jobs { get; set; } = EmptyReadOnly<string, Job>.Dictionary;
171+
172+
[JsonProperty("datafeeds")]
173+
public IReadOnlyDictionary<string, DataFeed> Datafeeds { get; set; } = EmptyReadOnly<string, DataFeed>.Dictionary;
174+
175+
public class DataFeed
176+
{
177+
[JsonProperty("count")]
178+
public long Count { get; internal set; }
179+
}
180+
181+
public class Job
182+
{
183+
[JsonProperty("count")]
184+
public long Count { get; internal set; }
185+
186+
[JsonProperty("detectors")]
187+
public JobStatistics Detectors { get; internal set; }
188+
189+
[JsonProperty("model_size")]
190+
public JobStatistics ModelSize { get; internal set; }
191+
}
192+
193+
public class JobStatistics
194+
{
195+
[JsonProperty("total")]
196+
public double Total { get; internal set; }
197+
198+
[JsonProperty("min")]
199+
public double Minimum { get; internal set; }
200+
201+
[JsonProperty("max")]
202+
public double Maximum { get; internal set; }
203+
204+
[JsonProperty("avg")]
205+
public double Average { get; internal set; }
206+
}
207+
}
24208
}

src/Tests/Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@
3939
<ItemGroup>
4040
<EmbeddedResource Include="Document\Single\Attachment\Attachment_Test_Document.pdf" />
4141
</ItemGroup>
42+
<ItemGroup>
43+
<Folder Include="XPack\Info\XPackInfo" />
44+
<Folder Include="XPack\Info\XPackUsage" />
45+
</ItemGroup>
4246
</Project>

src/Tests/XPack/Info/XPackUsage/XPackUsageApiTests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Elasticsearch.Net;
1+
using System.Collections.Generic;
2+
using Elasticsearch.Net;
3+
using FluentAssertions;
24
using Nest;
35
using Tests.Framework;
46
using Tests.Framework.Integration;
@@ -30,6 +32,31 @@ protected override LazyResponses ClientUsage() => Calls(
3032

3133
protected override void ExpectResponse(IXPackUsageResponse response)
3234
{
35+
response.Graph.Should().NotBeNull("graph object");
36+
response.MachineLearning.Should().NotBeNull("ml object");
37+
response.MachineLearning.Datafeeds.Should().NotBeEmpty("ml datafeeds");
38+
var datafeed = response.MachineLearning.Datafeeds["_all"];
39+
datafeed.Should().NotBeNull("_all datafeed");
40+
var allJob = response.MachineLearning.Jobs["_all"];
41+
allJob.Should().NotBeNull("_all job");
42+
allJob.Detectors.Should().NotBeNull("_all job detectors");
43+
allJob.ModelSize.Should().NotBeNull("_all job model_size");
44+
45+
response.Monitoring.Should().NotBeNull("monitoring object");
46+
response.Monitoring.EnabledExporters.Should().NotBeEmpty("monitoring exporters").And.ContainKey("local");
47+
response.Monitoring.EnabledExporters["local"].Should().Be(1);
48+
49+
response.Security.Should().NotBeNull("security object");
50+
response.Security.Anonymous.Should().NotBeNull("security anonymous object");
51+
response.Security.Audit.Should().NotBeNull("security audit object");
52+
response.Security.Audit.Outputs.Should().NotBeEmpty("security audit outputs").And.Contain("logfile");
53+
response.Security.IpFilter.Should().NotBeNull("security ipfilter object");
54+
response.Security.Realms.Should().NotBeEmpty("security realms");
55+
response.Security.Roles.Should().NotBeEmpty("security roles");
56+
response.Alerting.Should().NotBeNull("alerting object");
57+
response.Alerting.Count.Should().NotBeNull("alerting exection count object");
58+
response.Alerting.Execution.Should().NotBeNull("alerting exection object");
59+
response.Alerting.Execution.Actions.Should().NotBeEmpty("alerting exection actions").And.ContainKey("_all");
3360
}
3461
}
3562
}

0 commit comments

Comments
 (0)