-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(cherry picked from commit f1d1cce)
- Loading branch information
Showing
15 changed files
with
673 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/eql/EqlFeatureSetUsage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.eql; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class EqlFeatureSetUsage extends XPackFeatureSet.Usage { | ||
|
||
private final Map<String, Object> stats; | ||
|
||
public EqlFeatureSetUsage(StreamInput in) throws IOException { | ||
super(in); | ||
stats = in.readMap(); | ||
} | ||
|
||
public EqlFeatureSetUsage(boolean available, boolean enabled, Map<String, Object> stats) { | ||
super(XPackField.EQL, available, enabled); | ||
this.stats = stats; | ||
} | ||
|
||
public Map<String, Object> stats() { | ||
return stats; | ||
} | ||
|
||
@Override | ||
protected void innerXContent(XContentBuilder builder, Params params) throws IOException { | ||
super.innerXContent(builder, params); | ||
if (enabled) { | ||
for (Map.Entry<String, Object> entry : stats.entrySet()) { | ||
builder.field(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeMap(stats); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlFeatureSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.core.eql.EqlFeatureSetUsage; | ||
import org.elasticsearch.xpack.core.watcher.common.stats.Counters; | ||
import org.elasticsearch.xpack.eql.plugin.EqlPlugin; | ||
import org.elasticsearch.xpack.eql.plugin.EqlStatsAction; | ||
import org.elasticsearch.xpack.eql.plugin.EqlStatsRequest; | ||
import org.elasticsearch.xpack.eql.plugin.EqlStatsResponse; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class EqlFeatureSet implements XPackFeatureSet { | ||
|
||
private final boolean enabled; | ||
private final XPackLicenseState licenseState; | ||
private final Client client; | ||
|
||
@Inject | ||
public EqlFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, Client client) { | ||
this.enabled = EqlPlugin.isEnabled(settings); | ||
this.licenseState = licenseState; | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return XPackField.EQL; | ||
} | ||
|
||
@Override | ||
public boolean available() { | ||
return licenseState.isEqlAllowed(); | ||
} | ||
|
||
@Override | ||
public boolean enabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> nativeCodeInfo() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void usage(ActionListener<XPackFeatureSet.Usage> listener) { | ||
if (enabled) { | ||
EqlStatsRequest request = new EqlStatsRequest(); | ||
request.includeStats(true); | ||
client.execute(EqlStatsAction.INSTANCE, request, ActionListener.wrap(r -> { | ||
List<Counters> countersPerNode = r.getNodes() | ||
.stream() | ||
.map(EqlStatsResponse.NodeStatsResponse::getStats) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList()); | ||
Counters mergedCounters = Counters.merge(countersPerNode); | ||
listener.onResponse(new EqlFeatureSetUsage(available(), enabled(), mergedCounters.toNestedMap())); | ||
}, listener::onFailure)); | ||
} else { | ||
listener.onResponse(new EqlFeatureSetUsage(available(), enabled(), Collections.emptyMap())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlStatsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.plugin; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class EqlStatsAction extends ActionType<EqlStatsResponse> { | ||
|
||
public static final EqlStatsAction INSTANCE = new EqlStatsAction(); | ||
public static final String NAME = "cluster:monitor/xpack/eql/stats/dist"; | ||
|
||
private EqlStatsAction() { | ||
super(NAME, EqlStatsResponse::new); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlStatsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.plugin; | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodeRequest; | ||
import org.elasticsearch.action.support.nodes.BaseNodesRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Request to gather usage statistics | ||
*/ | ||
public class EqlStatsRequest extends BaseNodesRequest<EqlStatsRequest> { | ||
|
||
private boolean includeStats; | ||
|
||
public EqlStatsRequest() { | ||
super((String[]) null); | ||
} | ||
|
||
public EqlStatsRequest(StreamInput in) throws IOException { | ||
super(in); | ||
includeStats = in.readBoolean(); | ||
} | ||
|
||
public boolean includeStats() { | ||
return includeStats; | ||
} | ||
|
||
public void includeStats(boolean includeStats) { | ||
this.includeStats = includeStats; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(includeStats); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "eql_stats"; | ||
} | ||
|
||
static class NodeStatsRequest extends BaseNodeRequest { | ||
boolean includeStats; | ||
|
||
NodeStatsRequest(StreamInput in) throws IOException { | ||
super(in); | ||
includeStats = in.readBoolean(); | ||
} | ||
|
||
NodeStatsRequest(EqlStatsRequest request) { | ||
includeStats = request.includeStats(); | ||
} | ||
|
||
public boolean includeStats() { | ||
return includeStats; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(includeStats); | ||
} | ||
} | ||
} |
Oops, something went wrong.