[Monitoring] Make MonitoringDoc immutable (elastic/x-pack-elasticsearch#785)
This commit makes the MonitoringDoc immutable and removes the type() and id() methods from "resolvers" so that they are not anymore in charge of computing the documents types and ids. Now each MonitoringDoc knows its type and is able to compute its own id if needed. Original commit: elastic/x-pack-elasticsearch@5161cedcc8
This commit is contained in:
parent
70f621ed7e
commit
b642ba6351
|
@ -286,13 +286,6 @@
|
|||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]cleaner[/\\]CleanerService.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]client[/\\]MonitoringClient.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]Collector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]cluster[/\\]ClusterStateCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]cluster[/\\]ClusterStatsCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]indices[/\\]IndexRecoveryCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]indices[/\\]IndexStatsCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]indices[/\\]IndicesStatsCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]node[/\\]NodeStatsCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]collector[/\\]shards[/\\]ShardsCollector.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]exporter[/\\]ExportBulk.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]exporter[/\\]Exporter.java" checks="LineLength" />
|
||||
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]monitoring[/\\]exporter[/\\]Exporters.java" checks="LineLength" />
|
||||
|
|
|
@ -10,54 +10,76 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MonitoringBulkDoc extends MonitoringDoc {
|
||||
// TODO remove inherance from MonitoringDoc once all resolvers are removed
|
||||
public class MonitoringBulkDoc extends MonitoringDoc implements Writeable {
|
||||
|
||||
private MonitoringIndex index = MonitoringIndex.TIMESTAMPED;
|
||||
private MonitoringIndex index;
|
||||
private String type;
|
||||
private String id;
|
||||
private BytesReference source;
|
||||
private XContentType xContentType;
|
||||
|
||||
public MonitoringBulkDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
}
|
||||
|
||||
public MonitoringBulkDoc(String monitoringId, String monitoringVersion,
|
||||
MonitoringIndex index, String type, String id,
|
||||
BytesReference source, XContentType xContentType) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
this.index = index;
|
||||
MonitoringIndex index, String type, String id,
|
||||
String clusterUUID, long timestamp, MonitoringDoc.Node sourceNode,
|
||||
BytesReference source, XContentType xContentType) {
|
||||
super(monitoringId, monitoringVersion, type, id, clusterUUID, timestamp, sourceNode);
|
||||
this.index = index != null ? index : MonitoringIndex.TIMESTAMPED;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.source = source;
|
||||
this.xContentType = xContentType;
|
||||
}
|
||||
|
||||
public MonitoringBulkDoc(String monitoringId, String monitoringVersion,
|
||||
MonitoringIndex index, String type, String id,
|
||||
BytesReference source, XContentType xContentType) {
|
||||
this(monitoringId, monitoringVersion, index, type, id, null, 0, null, source, xContentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*
|
||||
* Here we use a static helper method to read a serialized {@link MonitoringBulkDoc} instance
|
||||
* instead of the usual <code>MonitoringBulkDoc(StreamInput in)</code> constructor because
|
||||
* MonitoringBulkDoc still inherits from MonitoringDoc and using ctors would make things
|
||||
* cumbersome. This will be replaced by a ctor <code>MonitoringBulkDoc(StreamInput in)</code>
|
||||
* once MonitoringBulkDoc does not inherit from MonitoringDoc anymore.
|
||||
*/
|
||||
public MonitoringBulkDoc(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
index = MonitoringIndex.readFrom(in);
|
||||
type = in.readOptionalString();
|
||||
id = in.readOptionalString();
|
||||
source = in.readBytesReference();
|
||||
public static MonitoringBulkDoc readFrom(StreamInput in) throws IOException {
|
||||
String monitoringId = in.readOptionalString();
|
||||
String monitoringVersion = in.readOptionalString();
|
||||
String clusterUUID = in.readOptionalString();
|
||||
long timestamp = in.readVLong();
|
||||
MonitoringDoc.Node sourceNode = in.readOptionalWriteable(MonitoringDoc.Node::new);
|
||||
MonitoringIndex index = MonitoringIndex.readFrom(in);
|
||||
String type = in.readOptionalString();
|
||||
String id = in.readOptionalString();
|
||||
BytesReference source = in.readBytesReference();
|
||||
XContentType xContentType;
|
||||
if (source != BytesArray.EMPTY && in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
|
||||
xContentType = XContentType.readFrom(in);
|
||||
} else {
|
||||
xContentType = XContentFactory.xContentType(source);
|
||||
}
|
||||
return new MonitoringBulkDoc(monitoringId, monitoringVersion, index, type, id, clusterUUID,
|
||||
timestamp, sourceNode, source, xContentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeOptionalString(getMonitoringId());
|
||||
out.writeOptionalString(getMonitoringVersion());
|
||||
out.writeOptionalString(getClusterUUID());
|
||||
out.writeVLong(getTimestamp());
|
||||
out.writeOptionalWriteable(getSourceNode());
|
||||
index.writeTo(out);
|
||||
out.writeOptionalString(type);
|
||||
out.writeOptionalString(id);
|
||||
|
|
|
@ -117,7 +117,7 @@ public class MonitoringBulkRequest extends ActionRequest {
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
docs.addAll(in.readList(MonitoringBulkDoc::new));
|
||||
docs.addAll(in.readList(MonitoringBulkDoc::readFrom));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -19,10 +20,10 @@ import org.elasticsearch.transport.TransportService;
|
|||
import org.elasticsearch.xpack.monitoring.exporter.Exporters;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TransportMonitoringBulkAction extends HandledTransportAction<MonitoringBulkRequest, MonitoringBulkResponse> {
|
||||
|
||||
|
@ -70,34 +71,49 @@ public class TransportMonitoringBulkAction extends HandledTransportAction<Monito
|
|||
* - timestamp
|
||||
* - source node
|
||||
*/
|
||||
Collection<MonitoringDoc> prepareForExport(Collection<? extends MonitoringDoc> docs) {
|
||||
final String clusterUUID = clusterService.state().metaData().clusterUUID();
|
||||
Function<MonitoringDoc, MonitoringDoc> updateClusterUUID = doc -> {
|
||||
if (doc.getClusterUUID() == null) {
|
||||
doc.setClusterUUID(clusterUUID);
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
Collection<MonitoringDoc> prepareForExport(Collection<MonitoringBulkDoc> bulkDocs) {
|
||||
final long defaultTimestamp = System.currentTimeMillis();
|
||||
final String defaultClusterUUID = clusterService.state().metaData().clusterUUID();
|
||||
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
Function<MonitoringDoc, MonitoringDoc> updateTimestamp = doc -> {
|
||||
if (doc.getTimestamp() == 0) {
|
||||
doc.setTimestamp(timestamp);
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
DiscoveryNode discoveryNode = clusterService.localNode();
|
||||
final MonitoringDoc.Node defaultNode = new MonitoringDoc.Node(discoveryNode.getId(),
|
||||
discoveryNode.getHostName(), discoveryNode.getAddress().toString(),
|
||||
discoveryNode.getHostAddress(), discoveryNode.getName(),
|
||||
discoveryNode.getAttributes());
|
||||
|
||||
final DiscoveryNode sourceNode = clusterService.localNode();
|
||||
Function<MonitoringDoc, MonitoringDoc> updateSourceNode = doc -> {
|
||||
if (doc.getSourceNode() == null) {
|
||||
doc.setSourceNode(sourceNode);
|
||||
List<MonitoringDoc> docs = new ArrayList<>();
|
||||
for (MonitoringBulkDoc bulkDoc : bulkDocs) {
|
||||
String clusterUUID;
|
||||
if (Strings.hasLength(bulkDoc.getClusterUUID())) {
|
||||
clusterUUID = bulkDoc.getClusterUUID();
|
||||
} else {
|
||||
clusterUUID = defaultClusterUUID;
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
|
||||
return docs.stream()
|
||||
.map(updateClusterUUID.andThen(updateTimestamp.andThen(updateSourceNode)))
|
||||
.collect(Collectors.toList());
|
||||
long timestamp;
|
||||
if (bulkDoc.getTimestamp() != 0L) {
|
||||
timestamp = bulkDoc.getTimestamp();
|
||||
} else {
|
||||
timestamp = defaultTimestamp;
|
||||
}
|
||||
|
||||
MonitoringDoc.Node node;
|
||||
if (bulkDoc.getSourceNode() != null) {
|
||||
node = bulkDoc.getSourceNode();
|
||||
} else {
|
||||
node = defaultNode;
|
||||
}
|
||||
|
||||
// TODO Convert MonitoringBulkDoc to a simple MonitoringDoc when all resolvers are
|
||||
// removed and MonitoringBulkDoc does not inherit from MonitoringDoc anymore.
|
||||
// Monitoring indices will be resolved here instead of being resolved at export
|
||||
// time.
|
||||
docs.add(new MonitoringBulkDoc(bulkDoc.getMonitoringId(),
|
||||
bulkDoc.getMonitoringVersion(), bulkDoc.getIndex(), bulkDoc.getType(),
|
||||
bulkDoc.getId(), clusterUUID, timestamp, node, bulkDoc.getSource(),
|
||||
bulkDoc.getXContentType()));
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,61 +6,59 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.cluster;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.license.License;
|
||||
import org.elasticsearch.xpack.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ClusterStatsCollector} and indexed in the
|
||||
* monitoring data index. It contains all information about the current cluster, mostly
|
||||
* for enabling/disabling features on Kibana side according to the license and also for
|
||||
* the "phone home" feature.
|
||||
*/
|
||||
public class ClusterInfoMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private String clusterName;
|
||||
private String version;
|
||||
private License license;
|
||||
private List<XPackFeatureSet.Usage> usage;
|
||||
private ClusterStatsResponse clusterStats;
|
||||
public static final String TYPE = "cluster_info";
|
||||
|
||||
public ClusterInfoMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final String clusterName;
|
||||
private final String version;
|
||||
private final License license;
|
||||
private final List<XPackFeatureSet.Usage> usage;
|
||||
private final ClusterStatsResponse clusterStats;
|
||||
|
||||
public ClusterInfoMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
String clusterName, String version, License license,
|
||||
List<XPackFeatureSet.Usage> usage,
|
||||
ClusterStatsResponse clusterStats) {
|
||||
super(monitoringId, monitoringVersion, TYPE, clusterUUID, clusterUUID, timestamp, node);
|
||||
this.clusterName = clusterName;
|
||||
this.version = version;
|
||||
this.license = license;
|
||||
this.usage = usage;
|
||||
this.clusterStats = clusterStats;
|
||||
}
|
||||
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public License getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense(License license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public List<XPackFeatureSet.Usage> getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public void setUsage(List<XPackFeatureSet.Usage> usage) {
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public ClusterStatsResponse getClusterStats() {
|
||||
return clusterStats;
|
||||
}
|
||||
|
||||
public void setClusterStats(ClusterStatsResponse clusterStats) {
|
||||
this.clusterStats = clusterStats;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.collector.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -23,21 +18,25 @@ import org.elasticsearch.xpack.monitoring.collector.Collector;
|
|||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.xpack.security.InternalClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Collector for cluster state.
|
||||
* <p>
|
||||
* This collector runs on the master node only and collects {@link ClusterStateMonitoringDoc} document
|
||||
* at a given frequency.
|
||||
* This collector runs on the master node only and collects {@link ClusterStateMonitoringDoc}
|
||||
* document at a given frequency.
|
||||
*/
|
||||
public class ClusterStateCollector extends Collector {
|
||||
|
||||
public static final String NAME = "cluster-state-collector";
|
||||
|
||||
private final Client client;
|
||||
|
||||
public ClusterStateCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, "cluster-state", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -56,36 +55,23 @@ public class ClusterStateCollector extends Collector {
|
|||
long timestamp = System.currentTimeMillis();
|
||||
DiscoveryNode sourceNode = localNode();
|
||||
|
||||
ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().get(monitoringSettings.clusterStateTimeout());
|
||||
ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth()
|
||||
.get(monitoringSettings.clusterStateTimeout());
|
||||
|
||||
// Adds a cluster_state document with associated status
|
||||
ClusterStateMonitoringDoc clusterStateDoc = new ClusterStateMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
clusterStateDoc.setClusterUUID(clusterUUID);
|
||||
clusterStateDoc.setTimestamp(timestamp);
|
||||
clusterStateDoc.setSourceNode(sourceNode);
|
||||
clusterStateDoc.setClusterState(clusterState);
|
||||
clusterStateDoc.setStatus(clusterHealth.getStatus());
|
||||
results.add(clusterStateDoc);
|
||||
results.add(new ClusterStateMonitoringDoc(monitoringId(), monitoringVersion(), clusterUUID,
|
||||
timestamp, sourceNode, clusterState, clusterHealth.getStatus()));
|
||||
|
||||
DiscoveryNodes nodes = clusterState.nodes();
|
||||
if (nodes != null) {
|
||||
for (DiscoveryNode node : nodes) {
|
||||
// Adds a document for every node in the monitoring timestamped index (type "nodes")
|
||||
ClusterStateNodeMonitoringDoc clusterStateNodeDoc = new ClusterStateNodeMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
clusterStateNodeDoc.setClusterUUID(clusterUUID);;
|
||||
clusterStateNodeDoc.setTimestamp(timestamp);
|
||||
clusterStateNodeDoc.setSourceNode(sourceNode);
|
||||
clusterStateNodeDoc.setStateUUID(stateUUID);
|
||||
clusterStateNodeDoc.setNodeId(node.getId());
|
||||
results.add(clusterStateNodeDoc);
|
||||
// Adds a document for every node in the monitoring timestamped index
|
||||
results.add(new ClusterStateNodeMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, sourceNode, stateUUID, node.getId()));
|
||||
|
||||
// Adds a document for every node in the monitoring data index (type "node")
|
||||
DiscoveryNodeMonitoringDoc discoveryNodeDoc = new DiscoveryNodeMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
discoveryNodeDoc.setClusterUUID(clusterUUID);
|
||||
discoveryNodeDoc.setTimestamp(timestamp);
|
||||
discoveryNodeDoc.setSourceNode(node);
|
||||
discoveryNodeDoc.setNode(node);
|
||||
results.add(discoveryNodeDoc);
|
||||
// Adds a document for every node in the monitoring data index
|
||||
results.add(new DiscoveryNodeMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, node));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,30 +7,33 @@ package org.elasticsearch.xpack.monitoring.collector.cluster;
|
|||
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ClusterStateCollector} that contains the
|
||||
* current cluster state.
|
||||
*/
|
||||
public class ClusterStateMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private ClusterState clusterState;
|
||||
private ClusterHealthStatus status;
|
||||
public static final String TYPE = "cluster_state";
|
||||
|
||||
public ClusterStateMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final ClusterState clusterState;
|
||||
private final ClusterHealthStatus status;
|
||||
|
||||
public ClusterStateMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
ClusterState clusterState, ClusterHealthStatus status) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.clusterState = clusterState;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ClusterState getClusterState() {
|
||||
return clusterState;
|
||||
}
|
||||
|
||||
public void setClusterState(ClusterState clusterState) {
|
||||
this.clusterState = clusterState;
|
||||
}
|
||||
|
||||
public ClusterHealthStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(ClusterHealthStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,31 +5,33 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.collector.cluster;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ClusterStateCollector} that contains the id of
|
||||
* every node of the cluster.
|
||||
*/
|
||||
public class ClusterStateNodeMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private String stateUUID;
|
||||
private String nodeId;
|
||||
public static final String TYPE = "node";
|
||||
|
||||
public ClusterStateNodeMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final String stateUUID;
|
||||
private final String nodeId;
|
||||
|
||||
public ClusterStateNodeMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
String stateUUID, String nodeId) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.stateUUID = stateUUID;
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public String getStateUUID() {
|
||||
return stateUUID;
|
||||
}
|
||||
|
||||
public void setStateUUID(String stateUUID) {
|
||||
this.stateUUID = stateUUID;
|
||||
}
|
||||
|
||||
public String getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.License;
|
||||
import org.elasticsearch.license.LicenseService;
|
||||
import org.elasticsearch.license.LicenseUtils;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
|
@ -42,15 +43,14 @@ import java.util.List;
|
|||
*/
|
||||
public class ClusterStatsCollector extends Collector {
|
||||
|
||||
public static final String NAME = "cluster-stats-collector";
|
||||
|
||||
private final LicenseService licenseService;
|
||||
private final Client client;
|
||||
|
||||
public ClusterStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState, InternalClient client,
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client,
|
||||
LicenseService licenseService) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
super(settings, "cluster-stats", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
this.licenseService = licenseService;
|
||||
}
|
||||
|
@ -64,37 +64,32 @@ public class ClusterStatsCollector extends Collector {
|
|||
@Override
|
||||
protected Collection<MonitoringDoc> doCollect() throws Exception {
|
||||
final Supplier<ClusterStatsResponse> clusterStatsSupplier =
|
||||
() -> client.admin().cluster().prepareClusterStats().get(monitoringSettings.clusterStatsTimeout());
|
||||
final Supplier<List<XPackFeatureSet.Usage>> usageSupplier = () -> new XPackUsageRequestBuilder(client).get().getUsages();
|
||||
() -> client.admin().cluster().prepareClusterStats()
|
||||
.get(monitoringSettings.clusterStatsTimeout());
|
||||
final Supplier<List<XPackFeatureSet.Usage>> usageSupplier =
|
||||
() -> new XPackUsageRequestBuilder(client).get().getUsages();
|
||||
|
||||
final ClusterStatsResponse clusterStats = clusterStatsSupplier.get();
|
||||
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
final String clusterUUID = clusterUUID();
|
||||
final DiscoveryNode sourceNode = localNode();
|
||||
final String clusterName = clusterService.getClusterName().value();
|
||||
final String version = Version.CURRENT.toString();
|
||||
final License license = licenseService.getLicense();
|
||||
final List<XPackFeatureSet.Usage> usage = collect(usageSupplier);
|
||||
|
||||
final List<MonitoringDoc> results = new ArrayList<>(1);
|
||||
|
||||
// Adds a cluster info document
|
||||
ClusterInfoMonitoringDoc clusterInfoDoc = new ClusterInfoMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
clusterInfoDoc.setClusterUUID(clusterUUID);
|
||||
clusterInfoDoc.setTimestamp(timestamp);
|
||||
clusterInfoDoc.setSourceNode(sourceNode);
|
||||
clusterInfoDoc.setClusterName(clusterService.getClusterName().value());
|
||||
clusterInfoDoc.setVersion(Version.CURRENT.toString());
|
||||
clusterInfoDoc.setLicense(licenseService.getLicense());
|
||||
clusterInfoDoc.setClusterStats(clusterStats);
|
||||
clusterInfoDoc.setUsage(collect(usageSupplier));
|
||||
results.add(clusterInfoDoc);
|
||||
results.add(new ClusterInfoMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, sourceNode, clusterName, version, license, usage,
|
||||
clusterStats));
|
||||
|
||||
// Adds a cluster stats document
|
||||
if (super.shouldCollect()) {
|
||||
ClusterStatsMonitoringDoc clusterStatsDoc = new ClusterStatsMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
clusterStatsDoc.setClusterUUID(clusterUUID);
|
||||
clusterStatsDoc.setTimestamp(timestamp);
|
||||
clusterStatsDoc.setSourceNode(sourceNode);
|
||||
clusterStatsDoc.setClusterStats(clusterStats);
|
||||
results.add(clusterStatsDoc);
|
||||
results.add(new ClusterStatsMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, sourceNode, clusterStats));
|
||||
}
|
||||
|
||||
return Collections.unmodifiableCollection(results);
|
||||
|
@ -106,8 +101,8 @@ public class ClusterStatsCollector extends Collector {
|
|||
return supplier.get();
|
||||
} catch (ElasticsearchSecurityException e) {
|
||||
if (LicenseUtils.isLicenseExpiredException(e)) {
|
||||
logger.trace((Supplier<?>) () -> new ParameterizedMessage(
|
||||
"collector [{}] - unable to collect data because of expired license", name()), e);
|
||||
logger.trace((Supplier<?>) () -> new ParameterizedMessage("collector [{}] - " +
|
||||
"unable to collect data because of expired license", name()), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -6,21 +6,27 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.cluster;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ClusterStatsCollector} that contains the current
|
||||
* cluster stats.
|
||||
*/
|
||||
public class ClusterStatsMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private ClusterStatsResponse clusterStats;
|
||||
public static final String TYPE = "cluster_stats";
|
||||
|
||||
public ClusterStatsMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final ClusterStatsResponse clusterStats;
|
||||
|
||||
public ClusterStatsMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
ClusterStatsResponse clusterStats) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.clusterStats = clusterStats;
|
||||
}
|
||||
|
||||
public ClusterStatsResponse getClusterStats() {
|
||||
return clusterStats;
|
||||
}
|
||||
|
||||
public void setClusterStats(ClusterStatsResponse clusterStats) {
|
||||
this.clusterStats = clusterStats;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,23 @@ package org.elasticsearch.xpack.monitoring.collector.cluster;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ClusterStateCollector} that contains information
|
||||
* about every node of the cluster.
|
||||
*/
|
||||
public class DiscoveryNodeMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private DiscoveryNode node;
|
||||
public static final String TYPE = "node";
|
||||
|
||||
public DiscoveryNodeMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final DiscoveryNode node;
|
||||
|
||||
public DiscoveryNodeMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node) {
|
||||
super(monitoringId, monitoringVersion, TYPE, node.getId(), clusterUUID, timestamp, node);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public DiscoveryNode getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(DiscoveryNode node) {
|
||||
this.node = node;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,18 +24,17 @@ import java.util.List;
|
|||
/**
|
||||
* Collector for the Recovery API.
|
||||
* <p>
|
||||
* This collector runs on the master node only and collects a {@link IndexRecoveryMonitoringDoc} document
|
||||
* for every index that has on-going shard recoveries.
|
||||
* This collector runs on the master node only and collects a {@link IndexRecoveryMonitoringDoc}
|
||||
* document for every index that has on-going shard recoveries.
|
||||
*/
|
||||
public class IndexRecoveryCollector extends Collector {
|
||||
|
||||
public static final String NAME = "index-recovery-collector";
|
||||
|
||||
private final Client client;
|
||||
|
||||
public IndexRecoveryCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, "index-recovery", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -54,12 +53,8 @@ public class IndexRecoveryCollector extends Collector {
|
|||
.get(monitoringSettings.recoveryTimeout());
|
||||
|
||||
if (recoveryResponse.hasRecoveries()) {
|
||||
IndexRecoveryMonitoringDoc indexRecoveryDoc = new IndexRecoveryMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
indexRecoveryDoc.setClusterUUID(clusterUUID());
|
||||
indexRecoveryDoc.setTimestamp(System.currentTimeMillis());
|
||||
indexRecoveryDoc.setSourceNode(localNode());
|
||||
indexRecoveryDoc.setRecoveryResponse(recoveryResponse);
|
||||
results.add(indexRecoveryDoc);
|
||||
results.add(new IndexRecoveryMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID(), System.currentTimeMillis(), localNode(), recoveryResponse));
|
||||
}
|
||||
return Collections.unmodifiableCollection(results);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,26 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.indices;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link IndexRecoveryCollector}
|
||||
*/
|
||||
public class IndexRecoveryMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private RecoveryResponse recoveryResponse;
|
||||
public static final String TYPE = "index_recovery";
|
||||
|
||||
public IndexRecoveryMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final RecoveryResponse recoveryResponse;
|
||||
|
||||
public IndexRecoveryMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
RecoveryResponse recoveryResponse) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.recoveryResponse = recoveryResponse;
|
||||
}
|
||||
|
||||
public RecoveryResponse getRecoveryResponse() {
|
||||
return recoveryResponse;
|
||||
}
|
||||
|
||||
public void setRecoveryResponse(RecoveryResponse recoveryResponse) {
|
||||
this.recoveryResponse = recoveryResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,18 +26,17 @@ import java.util.List;
|
|||
/**
|
||||
* Collector for indices statistics.
|
||||
* <p>
|
||||
* This collector runs on the master node only and collect a {@link IndexStatsMonitoringDoc} document
|
||||
* for each existing index in the cluster.
|
||||
* This collector runs on the master node only and collect a {@link IndexStatsMonitoringDoc}
|
||||
* document for each existing index in the cluster.
|
||||
*/
|
||||
public class IndexStatsCollector extends Collector {
|
||||
|
||||
public static final String NAME = "index-stats-collector";
|
||||
|
||||
private final Client client;
|
||||
|
||||
public IndexStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, "index-stats", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -70,12 +69,8 @@ public class IndexStatsCollector extends Collector {
|
|||
DiscoveryNode sourceNode = localNode();
|
||||
|
||||
for (IndexStats indexStats : indicesStats.getIndices().values()) {
|
||||
IndexStatsMonitoringDoc indexStatsDoc = new IndexStatsMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
indexStatsDoc.setClusterUUID(clusterUUID);
|
||||
indexStatsDoc.setTimestamp(timestamp);
|
||||
indexStatsDoc.setSourceNode(sourceNode);
|
||||
indexStatsDoc.setIndexStats(indexStats);
|
||||
results.add(indexStatsDoc);
|
||||
results.add(new IndexStatsMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, sourceNode, indexStats));
|
||||
}
|
||||
return Collections.unmodifiableCollection(results);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,26 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.indices;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.stats.IndexStats;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link IndexStatsCollector}
|
||||
*/
|
||||
public class IndexStatsMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private IndexStats indexStats;
|
||||
public static final String TYPE = "index_stats";
|
||||
|
||||
public IndexStatsMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final IndexStats indexStats;
|
||||
|
||||
public IndexStatsMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
IndexStats indexStats) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.indexStats = indexStats;
|
||||
}
|
||||
|
||||
public IndexStats getIndexStats() {
|
||||
return indexStats;
|
||||
}
|
||||
|
||||
public void setIndexStats(IndexStats indexStats) {
|
||||
this.indexStats = indexStats;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@ import java.util.Collections;
|
|||
/**
|
||||
* Collector for indices statistics.
|
||||
* <p>
|
||||
* This collector runs on the master node only and collect one {@link IndicesStatsMonitoringDoc} document.
|
||||
* This collector runs on the master node only and collect one {@link IndicesStatsMonitoringDoc}
|
||||
* document.
|
||||
*/
|
||||
public class IndicesStatsCollector extends Collector {
|
||||
|
||||
public static final String NAME = "indices-stats-collector";
|
||||
|
||||
private final Client client;
|
||||
|
||||
public IndicesStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, "indices-stats", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -53,11 +53,9 @@ public class IndicesStatsCollector extends Collector {
|
|||
.setStore(true)
|
||||
.get(monitoringSettings.indicesStatsTimeout());
|
||||
|
||||
IndicesStatsMonitoringDoc indicesStatsDoc = new IndicesStatsMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
indicesStatsDoc.setClusterUUID(clusterUUID());
|
||||
indicesStatsDoc.setTimestamp(System.currentTimeMillis());
|
||||
indicesStatsDoc.setSourceNode(localNode());
|
||||
indicesStatsDoc.setIndicesStats(indicesStats);
|
||||
IndicesStatsMonitoringDoc indicesStatsDoc = new IndicesStatsMonitoringDoc(monitoringId(),
|
||||
monitoringVersion(), clusterUUID(), System.currentTimeMillis(), localNode(),
|
||||
indicesStats);
|
||||
return Collections.singletonList(indicesStatsDoc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,26 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.indices;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link IndicesStatsCollector}
|
||||
*/
|
||||
public class IndicesStatsMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private IndicesStatsResponse indicesStats;
|
||||
public static final String TYPE = "indices_stats";
|
||||
|
||||
public IndicesStatsMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
private final IndicesStatsResponse indicesStats;
|
||||
|
||||
public IndicesStatsMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
IndicesStatsResponse indicesStats) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID, timestamp, node);
|
||||
this.indicesStats = indicesStats;
|
||||
}
|
||||
|
||||
public IndicesStatsResponse getIndicesStats() {
|
||||
return indicesStats;
|
||||
}
|
||||
|
||||
public void setIndicesStats(IndicesStatsResponse indicesStats) {
|
||||
this.indicesStats = indicesStats;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.collector.node;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||
|
@ -23,6 +20,9 @@ import org.elasticsearch.xpack.monitoring.collector.Collector;
|
|||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.xpack.security.InternalClient;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Collector for nodes statistics.
|
||||
* <p>
|
||||
|
@ -31,13 +31,12 @@ import org.elasticsearch.xpack.security.InternalClient;
|
|||
*/
|
||||
public class NodeStatsCollector extends Collector {
|
||||
|
||||
public static final String NAME = "node-stats-collector";
|
||||
|
||||
private final Client client;
|
||||
|
||||
public NodeStatsCollector(Settings settings, ClusterService clusterService, MonitoringSettings monitoringSettings,
|
||||
public NodeStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings,
|
||||
XPackLicenseState licenseState, InternalClient client) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
super(settings, "node-stats", clusterService, monitoringSettings, licenseState);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -53,7 +52,8 @@ public class NodeStatsCollector extends Collector {
|
|||
|
||||
NodesStatsResponse response = client.admin().cluster().nodesStats(request).actionGet();
|
||||
|
||||
// if there's a failure, then we failed to work with the _local node (guaranteed a single exception)
|
||||
// if there's a failure, then we failed to work with the
|
||||
// _local node (guaranteed a single exception)
|
||||
if (response.hasFailures()) {
|
||||
throw response.failures().get(0);
|
||||
}
|
||||
|
@ -61,14 +61,9 @@ public class NodeStatsCollector extends Collector {
|
|||
NodeStats nodeStats = response.getNodes().get(0);
|
||||
DiscoveryNode sourceNode = localNode();
|
||||
|
||||
NodeStatsMonitoringDoc nodeStatsDoc = new NodeStatsMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
nodeStatsDoc.setClusterUUID(clusterUUID());
|
||||
nodeStatsDoc.setTimestamp(System.currentTimeMillis());
|
||||
nodeStatsDoc.setSourceNode(sourceNode);
|
||||
nodeStatsDoc.setNodeId(sourceNode.getId());
|
||||
nodeStatsDoc.setNodeMaster(isLocalNodeMaster());
|
||||
nodeStatsDoc.setNodeStats(nodeStats);
|
||||
nodeStatsDoc.setMlockall(BootstrapInfo.isMemoryLocked());
|
||||
NodeStatsMonitoringDoc nodeStatsDoc = new NodeStatsMonitoringDoc(monitoringId(),
|
||||
monitoringVersion(), clusterUUID(), sourceNode, isLocalNodeMaster(),
|
||||
nodeStats, BootstrapInfo.isMemoryLocked());
|
||||
|
||||
return Collections.singletonList(nodeStatsDoc);
|
||||
}
|
||||
|
|
|
@ -6,32 +6,29 @@
|
|||
package org.elasticsearch.xpack.monitoring.collector.node;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link NodeStatsCollector}
|
||||
*/
|
||||
public class NodeStatsMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
private String nodeId;
|
||||
private boolean nodeMaster;
|
||||
private NodeStats nodeStats;
|
||||
private boolean mlockall;
|
||||
public static final String TYPE = "node_stats";
|
||||
|
||||
public NodeStatsMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
}
|
||||
private final String nodeId;
|
||||
private final boolean nodeMaster;
|
||||
private final NodeStats nodeStats;
|
||||
private final boolean mlockall;
|
||||
|
||||
public void setNodeId(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public void setNodeMaster(boolean nodeMaster) {
|
||||
this.nodeMaster = nodeMaster;
|
||||
}
|
||||
|
||||
public void setNodeStats(NodeStats nodeStats) {
|
||||
public NodeStatsMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, DiscoveryNode node,
|
||||
boolean isMaster, NodeStats nodeStats, boolean mlockall) {
|
||||
super(monitoringId, monitoringVersion, TYPE, null, clusterUUID,
|
||||
nodeStats.getTimestamp(), node);
|
||||
this.nodeId = node.getId();
|
||||
this.nodeMaster = isMaster;
|
||||
this.nodeStats = nodeStats;
|
||||
}
|
||||
|
||||
public void setMlockall(boolean mlockall) {
|
||||
this.mlockall = mlockall;
|
||||
}
|
||||
|
||||
|
@ -50,5 +47,4 @@ public class NodeStatsMonitoringDoc extends MonitoringDoc {
|
|||
public boolean isMlockall() {
|
||||
return mlockall;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,23 +5,26 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.collector.shards;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
/**
|
||||
* Monitoring document collected by {@link ShardsCollector}
|
||||
*/
|
||||
public class ShardMonitoringDoc extends MonitoringDoc {
|
||||
|
||||
public static final String TYPE = "shards";
|
||||
|
||||
private ShardRouting shardRouting;
|
||||
private String clusterStateUUID;
|
||||
|
||||
public ShardMonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
super(monitoringId, monitoringVersion);
|
||||
}
|
||||
|
||||
public void setShardRouting(ShardRouting shardRouting) {
|
||||
public ShardMonitoringDoc(String monitoringId, String monitoringVersion,
|
||||
String clusterUUID, long timestamp, DiscoveryNode node,
|
||||
ShardRouting shardRouting, String clusterStateUUID) {
|
||||
super(monitoringId, monitoringVersion, TYPE, id(clusterStateUUID, shardRouting),
|
||||
clusterUUID, timestamp, node);
|
||||
this.shardRouting = shardRouting;
|
||||
}
|
||||
|
||||
public void setClusterStateUUID(java.lang.String clusterStateUUID) {
|
||||
this.clusterStateUUID = clusterStateUUID;
|
||||
}
|
||||
|
||||
|
@ -32,4 +35,31 @@ public class ShardMonitoringDoc extends MonitoringDoc {
|
|||
public String getClusterStateUUID() {
|
||||
return clusterStateUUID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute an id that has the format:
|
||||
*
|
||||
* {state_uuid}:{node_id || '_na'}:{index}:{shard}:{'p' || 'r'}
|
||||
*/
|
||||
public static String id(String stateUUID, ShardRouting shardRouting) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(stateUUID);
|
||||
builder.append(':');
|
||||
if (shardRouting.assignedToNode()) {
|
||||
builder.append(shardRouting.currentNodeId());
|
||||
} else {
|
||||
builder.append("_na");
|
||||
}
|
||||
builder.append(':');
|
||||
builder.append(shardRouting.getIndexName());
|
||||
builder.append(':');
|
||||
builder.append(Integer.valueOf(shardRouting.id()));
|
||||
builder.append(':');
|
||||
if (shardRouting.primary()) {
|
||||
builder.append("p");
|
||||
} else {
|
||||
builder.append("r");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -5,14 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.collector.shards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
|
@ -23,6 +18,12 @@ import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
|||
import org.elasticsearch.xpack.monitoring.collector.Collector;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Collector for shards.
|
||||
* <p>
|
||||
|
@ -31,11 +32,9 @@ import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
|||
*/
|
||||
public class ShardsCollector extends Collector {
|
||||
|
||||
public static final String NAME = "shards-collector";
|
||||
|
||||
public ShardsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, XPackLicenseState licenseState) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licenseState);
|
||||
super(settings, "shards", clusterService, monitoringSettings, licenseState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,29 +58,25 @@ public class ShardsCollector extends Collector {
|
|||
|
||||
for (ShardRouting shard : shards) {
|
||||
if (match(shard.getIndexName())) {
|
||||
ShardMonitoringDoc shardDoc = new ShardMonitoringDoc(monitoringId(), monitoringVersion());
|
||||
shardDoc.setClusterUUID(clusterUUID);
|
||||
shardDoc.setTimestamp(timestamp);
|
||||
DiscoveryNode node = null;
|
||||
if (shard.assignedToNode()) {
|
||||
// If the shard is assigned to a node, the shard monitoring document
|
||||
// refers to this node
|
||||
shardDoc.setSourceNode(clusterState.getNodes().get(shard.currentNodeId()));
|
||||
node = clusterState.getNodes().get(shard.currentNodeId());
|
||||
}
|
||||
shardDoc.setShardRouting(shard);
|
||||
shardDoc.setClusterStateUUID(stateUUID);
|
||||
results.add(shardDoc);
|
||||
results.add(new ShardMonitoringDoc(monitoringId(), monitoringVersion(),
|
||||
clusterUUID, timestamp, node, shard, stateUUID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableCollection(results);
|
||||
}
|
||||
|
||||
private boolean match(String indexName) {
|
||||
String[] indices = monitoringSettings.indices();
|
||||
return IndexNameExpressionResolver
|
||||
.isAllIndices(Arrays.asList(monitoringSettings.indices())) || Regex.simpleMatch(indices, indexName);
|
||||
return IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))
|
||||
|| Regex.simpleMatch(indices, indexName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,65 +6,84 @@
|
|||
package org.elasticsearch.xpack.monitoring.exporter;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.inject.internal.Nullable;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc.Node.fromDiscoveryNode;
|
||||
|
||||
/**
|
||||
* Base class for all monitoring documents.
|
||||
*/
|
||||
public class MonitoringDoc implements Writeable {
|
||||
public class MonitoringDoc {
|
||||
|
||||
private final String monitoringId;
|
||||
private final String monitoringVersion;
|
||||
@Deprecated private final String monitoringId;
|
||||
@Deprecated private final String monitoringVersion;
|
||||
|
||||
private String clusterUUID;
|
||||
private long timestamp;
|
||||
private Node sourceNode;
|
||||
private final String type;
|
||||
private final String id;
|
||||
|
||||
public MonitoringDoc(String monitoringId, String monitoringVersion) {
|
||||
private final String clusterUUID;
|
||||
private final long timestamp;
|
||||
private final Node sourceNode;
|
||||
|
||||
private final BytesReference source;
|
||||
private final XContentType sourceXContentType;
|
||||
|
||||
protected MonitoringDoc(String monitoringId, String monitoringVersion, String type, String id,
|
||||
String clusterUUID, long timestamp, Node node,
|
||||
BytesReference source, XContentType sourceXContentType) {
|
||||
this.monitoringId = monitoringId;
|
||||
this.monitoringVersion = monitoringVersion;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.clusterUUID = clusterUUID;
|
||||
this.timestamp = timestamp;
|
||||
this.sourceNode = node;
|
||||
this.source = source;
|
||||
this.sourceXContentType = sourceXContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MonitoringDoc(StreamInput in) throws IOException {
|
||||
this(in.readOptionalString(), in.readOptionalString());
|
||||
clusterUUID = in.readOptionalString();
|
||||
timestamp = in.readVLong();
|
||||
sourceNode = in.readOptionalWriteable(Node::new);
|
||||
public MonitoringDoc(String monitoringId, String monitoringVersion, String type, String id,
|
||||
String clusterUUID, long timestamp, Node node) {
|
||||
this(monitoringId, monitoringVersion, type, id, clusterUUID, timestamp, node, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalString(getMonitoringId());
|
||||
out.writeOptionalString(getMonitoringVersion());
|
||||
out.writeOptionalString(getClusterUUID());
|
||||
out.writeVLong(getTimestamp());
|
||||
out.writeOptionalWriteable(getSourceNode());
|
||||
public MonitoringDoc(String monitoringId, String monitoringVersion, String type, String id,
|
||||
String clusterUUID, long timestamp, DiscoveryNode discoveryNode) {
|
||||
this(monitoringId, monitoringVersion, type, id, clusterUUID, timestamp,
|
||||
fromDiscoveryNode(discoveryNode));
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getClusterUUID() {
|
||||
return clusterUUID;
|
||||
}
|
||||
|
||||
public void setClusterUUID(String clusterUUID) {
|
||||
this.clusterUUID = clusterUUID;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMonitoringId() {
|
||||
return monitoringId;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMonitoringVersion() {
|
||||
return monitoringVersion;
|
||||
}
|
||||
|
@ -73,32 +92,49 @@ public class MonitoringDoc implements Writeable {
|
|||
return sourceNode;
|
||||
}
|
||||
|
||||
public void setSourceNode(Node node) {
|
||||
this.sourceNode = node;
|
||||
}
|
||||
|
||||
public void setSourceNode(DiscoveryNode node) {
|
||||
setSourceNode(new Node(node.getId(), node.getHostName(), node.getAddress().toString(),
|
||||
node.getHostAddress(), node.getName(), node.getAttributes()));
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
public BytesReference getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public XContentType getXContentType() {
|
||||
return sourceXContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "monitoring document [class=" + getClass().getSimpleName() +
|
||||
", monitoring id=" + getMonitoringId() +
|
||||
", monitoring version=" + getMonitoringVersion() +
|
||||
"]";
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MonitoringDoc that = (MonitoringDoc) o;
|
||||
return timestamp == that.timestamp &&
|
||||
Objects.equals(monitoringId, that.monitoringId)
|
||||
&& Objects.equals(monitoringVersion, that.monitoringVersion)
|
||||
&& Objects.equals(type, that.type)
|
||||
&& Objects.equals(id, that.id)
|
||||
&& Objects.equals(clusterUUID, that.clusterUUID)
|
||||
&& Objects.equals(sourceNode, that.sourceNode)
|
||||
&& Objects.equals(sourceNode, that.sourceNode)
|
||||
&& Objects.equals(sourceXContentType, that.sourceXContentType);
|
||||
}
|
||||
|
||||
public static class Node implements Writeable, ToXContent {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(monitoringId, monitoringVersion, type, id, clusterUUID, timestamp,
|
||||
sourceNode, source, sourceXContentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Node} represents the node of the cluster from which the monitoring document
|
||||
* has been collected.
|
||||
*/
|
||||
public static class Node implements Writeable,ToXContent {
|
||||
|
||||
private String uuid;
|
||||
private String host;
|
||||
|
@ -181,7 +217,8 @@ public class MonitoringDoc implements Writeable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params)
|
||||
throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(Fields.UUID, getUUID());
|
||||
builder.field(Fields.HOST, getHost());
|
||||
|
@ -199,29 +236,42 @@ public class MonitoringDoc implements Writeable {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Node node = (Node) o;
|
||||
|
||||
if (uuid != null ? !uuid.equals(node.uuid) : node.uuid != null) return false;
|
||||
if (host != null ? !host.equals(node.host) : node.host != null) return false;
|
||||
if (transportAddress != null ? !transportAddress.equals(node.transportAddress) : node.transportAddress != null) return false;
|
||||
if (ip != null ? !ip.equals(node.ip) : node.ip != null) return false;
|
||||
if (name != null ? !name.equals(node.name) : node.name != null) return false;
|
||||
return !(attributes != null ? !attributes.equals(node.attributes) : node.attributes != null);
|
||||
|
||||
return Objects.equals(uuid, node.uuid)
|
||||
&& Objects.equals(host, node.host)
|
||||
&& Objects.equals(transportAddress, node.transportAddress)
|
||||
&& Objects.equals(ip, node.ip)
|
||||
&& Objects.equals(name, node.name)
|
||||
&& Objects.equals(attributes, node.attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = uuid != null ? uuid.hashCode() : 0;
|
||||
result = 31 * result + (host != null ? host.hashCode() : 0);
|
||||
result = 31 * result + (transportAddress != null ? transportAddress.hashCode() : 0);
|
||||
result = 31 * result + (ip != null ? ip.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hash(uuid, host, transportAddress, ip, name, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MonitoringDoc.Node} from a {@link DiscoveryNode}, copying over the
|
||||
* required information.
|
||||
*
|
||||
* @param discoveryNode the {@link DiscoveryNode}
|
||||
* @return a {@link MonitoringDoc.Node} instance, or {@code null} if the given discovery
|
||||
* node is null.
|
||||
*/
|
||||
static Node fromDiscoveryNode(@Nullable DiscoveryNode discoveryNode) {
|
||||
MonitoringDoc.Node node = null;
|
||||
if (discoveryNode != null) {
|
||||
node = new MonitoringDoc.Node(discoveryNode.getId(), discoveryNode.getHostName(),
|
||||
discoveryNode.getAddress().toString(), discoveryNode.getHostAddress(),
|
||||
discoveryNode.getName(), discoveryNode.getAttributes());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
|
|
|
@ -117,8 +117,8 @@ class HttpExportBulk extends ExportBulk {
|
|||
|
||||
if (resolver != null) {
|
||||
String index = resolver.index(doc);
|
||||
String type = resolver.type(doc);
|
||||
String id = resolver.id(doc);
|
||||
String type = doc.getType();
|
||||
String id = doc.getId();
|
||||
|
||||
try (XContentBuilder builder = new XContentBuilder(xContent, out)) {
|
||||
// Builds the bulk action metadata line
|
||||
|
@ -145,8 +145,8 @@ class HttpExportBulk extends ExportBulk {
|
|||
|
||||
logger.trace("added index request [index={}, type={}, id={}]", index, type, id);
|
||||
} else {
|
||||
logger.error("no resolver found for monitoring document [class={}, id={}, version={}]",
|
||||
doc.getClass().getName(), doc.getMonitoringId(), doc.getMonitoringVersion());
|
||||
logger.error("no resolver found for monitoring document [class={}]",
|
||||
doc.getClass().getName());
|
||||
}
|
||||
|
||||
return BytesReference.toBytes(out.bytes());
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.action.bulk.BulkItemResponse;
|
|||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.ExportBulk;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.ExportException;
|
||||
|
@ -61,7 +62,10 @@ public class LocalBulk extends ExportBulk {
|
|||
|
||||
try {
|
||||
MonitoringIndexNameResolver<MonitoringDoc> resolver = resolvers.getResolver(doc);
|
||||
IndexRequest request = new IndexRequest(resolver.index(doc), resolver.type(doc), resolver.id(doc));
|
||||
IndexRequest request = new IndexRequest(resolver.index(doc), doc.getType());
|
||||
if (Strings.hasText(doc.getId())) {
|
||||
request.id(doc.getId());
|
||||
}
|
||||
request.source(resolver.source(doc, XContentType.SMILE), XContentType.SMILE);
|
||||
|
||||
// allow the use of ingest pipelines to be completely optional
|
||||
|
|
|
@ -470,8 +470,8 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
|||
.distinct()
|
||||
.toArray(String[]::new);
|
||||
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(null, null);
|
||||
monitoringDoc.setTimestamp(System.currentTimeMillis());
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(null, null, null, null, null,
|
||||
System.currentTimeMillis(), (MonitoringDoc.Node) null);
|
||||
|
||||
// Get the names of the current monitoring indices
|
||||
Set<String> currents = StreamSupport.stream(getResolvers().spliterator(), false)
|
||||
|
|
|
@ -53,22 +53,6 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
|
|||
*/
|
||||
public abstract String indexPattern();
|
||||
|
||||
/**
|
||||
* Returns the document type under which the monitoring document must be indexed.
|
||||
*
|
||||
* @param document the monitoring document
|
||||
* @return the type of the document
|
||||
*/
|
||||
public abstract String type(T document);
|
||||
|
||||
/**
|
||||
* Returns the document id under which the monitoring document must be indexed.
|
||||
*
|
||||
* @param document the monitoring document
|
||||
* @return the id of the document
|
||||
*/
|
||||
public abstract String id(T document);
|
||||
|
||||
/**
|
||||
* Builds the source of the document in a given XContentType
|
||||
*
|
||||
|
@ -203,12 +187,6 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
|
|||
return String.join(DELIMITER, index, "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(T document) {
|
||||
// Documents in timestamped indices are usually indexed with auto-generated ids
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String templateName() {
|
||||
return String.format(Locale.ROOT, "%s-%s-%s", PREFIX, getId(), MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
|
|
|
@ -9,27 +9,18 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MonitoringBulkDataResolver extends MonitoringIndexNameResolver.Data<MonitoringBulkDoc> {
|
||||
|
||||
@Override
|
||||
public String type(MonitoringBulkDoc document) {
|
||||
return document.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(MonitoringBulkDoc document) {
|
||||
return document.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringBulkDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
BytesReference source = document.getSource();
|
||||
if (source != null && source.length() > 0) {
|
||||
builder.rawField(type(document), source, document.getXContentType());
|
||||
builder.rawField(document.getType(), source, document.getXContentType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -21,16 +22,11 @@ public class MonitoringBulkTimestampedResolver extends MonitoringIndexNameResolv
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(MonitoringBulkDoc document) {
|
||||
return document.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringBulkDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
BytesReference source = document.getSource();
|
||||
if (source != null && source.length() > 0) {
|
||||
builder.rawField(type(document), source, document.getXContentType());
|
||||
builder.rawField(document.getType(), source, document.getXContentType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,18 +22,6 @@ import java.util.Map;
|
|||
|
||||
public class ClusterInfoResolver extends MonitoringIndexNameResolver.Data<ClusterInfoMonitoringDoc> {
|
||||
|
||||
public static final String TYPE = "cluster_info";
|
||||
|
||||
@Override
|
||||
public String type(ClusterInfoMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(ClusterInfoMonitoringDoc document) {
|
||||
return document.getClusterUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(ClusterInfoMonitoringDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.field("cluster_name", document.getClusterName());
|
||||
|
|
|
@ -16,17 +16,10 @@ import java.io.IOException;
|
|||
|
||||
public class ClusterStateNodeResolver extends MonitoringIndexNameResolver.Timestamped<ClusterStateNodeMonitoringDoc> {
|
||||
|
||||
public static final String TYPE = "node";
|
||||
|
||||
public ClusterStateNodeResolver(MonitoredSystem id, Settings settings) {
|
||||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(ClusterStateNodeMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(ClusterStateNodeMonitoringDoc document,
|
||||
XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
|
|
|
@ -41,11 +41,6 @@ public class ClusterStateResolver extends MonitoringIndexNameResolver.Timestampe
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(ClusterStateMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
|
|
@ -48,11 +48,6 @@ public class ClusterStatsResolver extends MonitoringIndexNameResolver.Timestampe
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(ClusterStatsMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
|
|
@ -18,16 +18,6 @@ public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data<Disc
|
|||
|
||||
public static final String TYPE = "node";
|
||||
|
||||
@Override
|
||||
public String type(DiscoveryNodeMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(DiscoveryNodeMonitoringDoc document) {
|
||||
return document.getNode().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(DiscoveryNodeMonitoringDoc document,
|
||||
XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
|
|
|
@ -26,11 +26,6 @@ public class IndexRecoveryResolver extends MonitoringIndexNameResolver.Timestamp
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(IndexRecoveryMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(IndexRecoveryMonitoringDoc document,
|
||||
XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
|
|
|
@ -96,11 +96,6 @@ public class IndexStatsResolver extends MonitoringIndexNameResolver.Timestamped<
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(IndexStatsMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
|
|
@ -52,11 +52,6 @@ public class IndicesStatsResolver extends MonitoringIndexNameResolver.Timestampe
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(IndicesStatsMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
|
|
@ -126,11 +126,6 @@ public class NodeStatsResolver extends MonitoringIndexNameResolver.Timestamped<N
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(NodeStatsMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
|
|
@ -42,16 +42,6 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
|
|||
super(id, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(ShardMonitoringDoc document) {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(ShardMonitoringDoc document) {
|
||||
return id(document.getClusterStateUUID(), document.getShardRouting());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> filters() {
|
||||
return FILTERS;
|
||||
|
@ -73,31 +63,4 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
|
|||
static final String SHARD = "shard";
|
||||
static final String STATE_UUID = "state_uuid";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute an id that has the format:
|
||||
*
|
||||
* {state_uuid}:{node_id || '_na'}:{index}:{shard}:{'p' || 'r'}
|
||||
*/
|
||||
static String id(String stateUUID, ShardRouting shardRouting) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(stateUUID);
|
||||
builder.append(':');
|
||||
if (shardRouting.assignedToNode()) {
|
||||
builder.append(shardRouting.currentNodeId());
|
||||
} else {
|
||||
builder.append("_na");
|
||||
}
|
||||
builder.append(':');
|
||||
builder.append(shardRouting.getIndexName());
|
||||
builder.append(':');
|
||||
builder.append(Integer.valueOf(shardRouting.id()));
|
||||
builder.append(':');
|
||||
if (shardRouting.primary()) {
|
||||
builder.append("p");
|
||||
} else {
|
||||
builder.append("r");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
package org.elasticsearch.xpack.monitoring;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.license.TribeTransportTestCase;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkAction;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDoc;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkRequest;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -39,9 +36,6 @@ public class MonitoringTribeTests extends TribeTransportTestCase {
|
|||
}
|
||||
|
||||
private static void assertMonitoringTransportActionsWorks(Client client) throws Exception {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
doc.setType(randomAsciiOfLength(5));
|
||||
doc.setSource(new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON);
|
||||
client.execute(MonitoringBulkAction.INSTANCE, new MonitoringBulkRequest());
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,14 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.util.concurrent.CountDown;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.XPackSettings;
|
||||
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.collector.indices.IndexStatsMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.collector.indices.IndicesStatsMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.collector.node.NodeStatsMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.collector.shards.ShardMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.cluster.ClusterStateResolver;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.indices.IndexStatsResolver;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.indices.IndicesStatsResolver;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.node.NodeStatsResolver;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.shards.ShardsResolver;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -111,9 +112,9 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
|
|||
|
||||
// And we wait until data have been indexed locally using either by the local or http exporter
|
||||
MonitoringIndexNameResolver.Timestamped resolver = new IndexStatsResolver(MonitoredSystem.ES, Settings.EMPTY);
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(MonitoredSystem.ES.getSystem(), randomAsciiOfLength(2));
|
||||
monitoringDoc.setTimestamp(System.currentTimeMillis());
|
||||
MonitoringDoc monitoringDoc = new IndexStatsMonitoringDoc(MonitoredSystem.ES.getSystem(), null, null, System.currentTimeMillis(), null, null);
|
||||
final String expectedIndex = resolver.index(monitoringDoc);
|
||||
final String indexPattern = resolver.indexPattern();
|
||||
|
||||
logger.info("--> {} Waiting for [{}] to be ready", Thread.currentThread().getName(), expectedIndex);
|
||||
assertBusy(() -> {
|
||||
|
@ -142,13 +143,18 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
|
|||
* Monitoring doesn't really have a Java API so we can't test that, but we can test that we write the data we expected to
|
||||
* write. */
|
||||
|
||||
SearchResponse firstIndexStats = search(resolver, greaterThanOrEqualTo(10L));
|
||||
SearchResponse firstIndexStats =
|
||||
search(indexPattern, IndexStatsMonitoringDoc.TYPE, greaterThanOrEqualTo(10L));
|
||||
|
||||
// All the other aliases should have been created by now so we can assert that we have the data we saved in the bwc indexes
|
||||
SearchResponse firstShards = search(new ShardsResolver(MonitoredSystem.ES, Settings.EMPTY), greaterThanOrEqualTo(10L));
|
||||
SearchResponse firstIndices = search(new IndicesStatsResolver(MonitoredSystem.ES, Settings.EMPTY), greaterThanOrEqualTo(3L));
|
||||
SearchResponse firstNode = search(new NodeStatsResolver(MonitoredSystem.ES, Settings.EMPTY), greaterThanOrEqualTo(3L));
|
||||
SearchResponse firstState = search(new ClusterStateResolver(MonitoredSystem.ES, Settings.EMPTY), greaterThanOrEqualTo(3L));
|
||||
SearchResponse firstShards =
|
||||
search(indexPattern, ShardMonitoringDoc.TYPE, greaterThanOrEqualTo(10L));
|
||||
SearchResponse firstIndices =
|
||||
search(indexPattern, IndicesStatsMonitoringDoc.TYPE, greaterThanOrEqualTo(3L));
|
||||
SearchResponse firstNode =
|
||||
search(indexPattern, NodeStatsMonitoringDoc.TYPE, greaterThanOrEqualTo(3L));
|
||||
SearchResponse firstState =
|
||||
search(indexPattern, ClusterStateMonitoringDoc.TYPE, greaterThanOrEqualTo(3L));
|
||||
|
||||
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setNodes(true).get();
|
||||
final String masterNodeId = clusterStateResponse.getState().getNodes().getMasterNodeId();
|
||||
|
@ -166,15 +172,15 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
|
|||
|
||||
// Wait for monitoring to accumulate some data about the current cluster
|
||||
long indexStatsCount = firstIndexStats.getHits().getTotalHits();
|
||||
assertBusy(() -> search(new IndexStatsResolver(MonitoredSystem.ES, Settings.EMPTY),
|
||||
assertBusy(() -> search(indexPattern, IndexStatsMonitoringDoc.TYPE,
|
||||
greaterThan(indexStatsCount)), 1, TimeUnit.MINUTES);
|
||||
assertBusy(() -> search(new ShardsResolver(MonitoredSystem.ES, Settings.EMPTY),
|
||||
assertBusy(() -> search(indexPattern, ShardMonitoringDoc.TYPE,
|
||||
greaterThan(firstShards.getHits().getTotalHits())), 1, TimeUnit.MINUTES);
|
||||
assertBusy(() -> search(new IndicesStatsResolver(MonitoredSystem.ES, Settings.EMPTY),
|
||||
assertBusy(() -> search(indexPattern, IndicesStatsMonitoringDoc.TYPE,
|
||||
greaterThan(firstIndices.getHits().getTotalHits())), 1, TimeUnit.MINUTES);
|
||||
assertBusy(() -> search(new NodeStatsResolver(MonitoredSystem.ES, Settings.EMPTY),
|
||||
assertBusy(() -> search(indexPattern, NodeStatsMonitoringDoc.TYPE,
|
||||
greaterThan(firstNode.getHits().getTotalHits())), 1, TimeUnit.MINUTES);
|
||||
assertBusy(() -> search(new ClusterStateResolver(MonitoredSystem.ES, Settings.EMPTY),
|
||||
assertBusy(() -> search(indexPattern, ClusterStateMonitoringDoc.TYPE,
|
||||
greaterThan(firstState.getHits().getTotalHits())), 1, TimeUnit.MINUTES);
|
||||
|
||||
} finally {
|
||||
|
@ -205,8 +211,8 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
|
|||
}
|
||||
}
|
||||
|
||||
private SearchResponse search(MonitoringIndexNameResolver<?> resolver, Matcher<Long> hitCount) {
|
||||
SearchResponse response = client().prepareSearch(resolver.indexPattern()).setTypes(resolver.type(null)).get();
|
||||
private SearchResponse search(String indexPattern, String type, Matcher<Long> hitCount) {
|
||||
SearchResponse response = client().prepareSearch(indexPattern).setTypes(type).get();
|
||||
assertThat(response.getHits().getTotalHits(), hitCount);
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ package org.elasticsearch.xpack.monitoring.action;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,11 +30,6 @@ public class MonitoringBulkDocTests extends ESTestCase {
|
|||
for (int i = 0; i < iterations; i++) {
|
||||
MonitoringBulkDoc doc = newRandomMonitoringBulkDoc();
|
||||
|
||||
boolean hasSourceNode = randomBoolean();
|
||||
if (hasSourceNode) {
|
||||
doc.setSourceNode(newRandomSourceNode());
|
||||
}
|
||||
|
||||
BytesStreamOutput output = new BytesStreamOutput();
|
||||
Version outputVersion = randomVersion(random());
|
||||
output.setVersion(outputVersion);
|
||||
|
@ -40,7 +37,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
|
|||
|
||||
StreamInput streamInput = output.bytes().streamInput();
|
||||
streamInput.setVersion(outputVersion);
|
||||
MonitoringBulkDoc doc2 = new MonitoringBulkDoc(streamInput);
|
||||
MonitoringBulkDoc doc2 = MonitoringBulkDoc.readFrom(streamInput);
|
||||
|
||||
assertThat(doc2.getMonitoringId(), equalTo(doc.getMonitoringId()));
|
||||
assertThat(doc2.getMonitoringVersion(), equalTo(doc.getMonitoringVersion()));
|
||||
|
@ -65,7 +62,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
|
|||
Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
|
||||
try (StreamInput in = StreamInput.wrap(data)) {
|
||||
in.setVersion(version);
|
||||
MonitoringBulkDoc bulkDoc = new MonitoringBulkDoc(in);
|
||||
MonitoringBulkDoc bulkDoc = MonitoringBulkDoc.readFrom(in);
|
||||
assertEquals(XContentType.JSON, bulkDoc.getXContentType());
|
||||
assertEquals("mId", bulkDoc.getMonitoringId());
|
||||
assertEquals("5.1.2", bulkDoc.getMonitoringVersion());
|
||||
|
@ -82,24 +79,23 @@ public class MonitoringBulkDocTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private MonitoringBulkDoc newRandomMonitoringBulkDoc() {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
if (frequently()) {
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setType(randomAsciiOfLength(5));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
doc.setSource(new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON);
|
||||
}
|
||||
if (rarely()) {
|
||||
doc.setIndex(MonitoringIndex.DATA);
|
||||
doc.setId(randomAsciiOfLength(2));
|
||||
}
|
||||
return doc;
|
||||
public static MonitoringBulkDoc newRandomMonitoringBulkDoc() {
|
||||
String monitoringId = randomFrom(MonitoredSystem.values()).getSystem();
|
||||
String monitoringVersion = randomVersion(random()).toString();
|
||||
MonitoringIndex index = randomBoolean() ? randomFrom(MonitoringIndex.values()) : null;
|
||||
String type = randomFrom("type1", "type2", "type3");
|
||||
String id = randomBoolean() ? randomAsciiOfLength(3) : null;
|
||||
String clusterUUID = randomBoolean() ? randomAsciiOfLength(5) : null;
|
||||
long timestamp = randomBoolean() ? randomNonNegativeLong() : 0L;
|
||||
MonitoringDoc.Node sourceNode = randomBoolean() ? newRandomSourceNode() : null;
|
||||
BytesReference source = new BytesArray("{\"key\" : \"value\"}");
|
||||
XContentType xContentType = XContentType.JSON;
|
||||
|
||||
return new MonitoringBulkDoc(monitoringId, monitoringVersion, index, type, id,
|
||||
clusterUUID, timestamp, sourceNode, source, xContentType);
|
||||
}
|
||||
|
||||
private MonitoringDoc.Node newRandomSourceNode() {
|
||||
public static MonitoringDoc.Node newRandomSourceNode() {
|
||||
String uuid = null;
|
||||
String name = null;
|
||||
String ip = null;
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -33,20 +34,20 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testValidateRequestSingleDoc() {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(null, null);
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(null, null, null, null, null, null, null);
|
||||
|
||||
assertValidationErrors(new MonitoringBulkRequest().add(doc), hasItems("monitored system id is missing for monitoring document [0]",
|
||||
"monitored system API version is missing for monitoring document [0]",
|
||||
"type is missing for monitoring document [0]",
|
||||
"source is missing for monitoring document [0]"));
|
||||
|
||||
doc = new MonitoringBulkDoc("id", null);
|
||||
doc = new MonitoringBulkDoc("id", null, null, null, null, null, null);
|
||||
assertValidationErrors(new MonitoringBulkRequest().add(doc),
|
||||
hasItems("monitored system API version is missing for monitoring document [0]",
|
||||
"type is missing for monitoring document [0]",
|
||||
"source is missing for monitoring document [0]"));
|
||||
|
||||
doc = new MonitoringBulkDoc("id", "version");
|
||||
doc = new MonitoringBulkDoc("id", "version", null, null, null, null, null);
|
||||
assertValidationErrors(new MonitoringBulkRequest().add(doc), hasItems("type is missing for monitoring document [0]",
|
||||
"source is missing for monitoring document [0]"));
|
||||
|
||||
|
@ -62,32 +63,33 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
|||
MonitoringBulkRequest request = new MonitoringBulkRequest();
|
||||
|
||||
// Doc0 is complete
|
||||
MonitoringBulkDoc doc0 = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
doc0.setType(randomAsciiOfLength(5));
|
||||
doc0.setSource(SOURCE, XContentType.JSON);
|
||||
MonitoringBulkDoc doc0 = new MonitoringBulkDoc(randomAsciiOfLength(2),
|
||||
randomAsciiOfLength(2), MonitoringIndex.TIMESTAMPED, randomAsciiOfLength(5),
|
||||
null, SOURCE, XContentType.JSON);
|
||||
request.add(doc0);
|
||||
|
||||
// Doc1 has no type
|
||||
MonitoringBulkDoc doc1 = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
doc1.setSource(SOURCE, XContentType.JSON);
|
||||
MonitoringBulkDoc doc1 = new MonitoringBulkDoc(randomAsciiOfLength(2),
|
||||
randomAsciiOfLength(2), MonitoringIndex.TIMESTAMPED, null,
|
||||
null, SOURCE, XContentType.JSON);
|
||||
request.add(doc1);
|
||||
|
||||
// Doc2 has no source
|
||||
MonitoringBulkDoc doc2 = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
doc2.setType(randomAsciiOfLength(5));
|
||||
doc2.setSource(BytesArray.EMPTY, XContentType.JSON);
|
||||
MonitoringBulkDoc doc2 = new MonitoringBulkDoc(randomAsciiOfLength(2),
|
||||
randomAsciiOfLength(2), MonitoringIndex.TIMESTAMPED, randomAsciiOfLength(5),
|
||||
null, BytesArray.EMPTY, XContentType.JSON);
|
||||
request.add(doc2);
|
||||
|
||||
// Doc3 has no version
|
||||
MonitoringBulkDoc doc3 = new MonitoringBulkDoc(randomAsciiOfLength(2), null);
|
||||
doc3.setType(randomAsciiOfLength(5));
|
||||
doc3.setSource(SOURCE, XContentType.JSON);
|
||||
MonitoringBulkDoc doc3 = new MonitoringBulkDoc(randomAsciiOfLength(2),
|
||||
null, MonitoringIndex.TIMESTAMPED, randomAsciiOfLength(5),
|
||||
null, SOURCE, XContentType.JSON);
|
||||
request.add(doc3);
|
||||
|
||||
// Doc4 has no id
|
||||
MonitoringBulkDoc doc4 = new MonitoringBulkDoc(null, randomAsciiOfLength(2));
|
||||
doc4.setType(randomAsciiOfLength(5));
|
||||
doc4.setSource(SOURCE, XContentType.JSON);
|
||||
MonitoringBulkDoc doc4 = new MonitoringBulkDoc(null,
|
||||
randomAsciiOfLength(2), MonitoringIndex.TIMESTAMPED, randomAsciiOfLength(5),
|
||||
null, SOURCE, XContentType.JSON);
|
||||
request.add(doc4);
|
||||
|
||||
assertValidationErrors(request, hasItems("type is missing for monitoring document [1]",
|
||||
|
@ -101,7 +103,9 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
|||
MonitoringBulkRequest request = new MonitoringBulkRequest();
|
||||
final int nbDocs = randomIntBetween(1, 20);
|
||||
for (int i = 0; i < nbDocs; i++) {
|
||||
request.add(new MonitoringBulkDoc(String.valueOf(i), String.valueOf(i)));
|
||||
request.add(new MonitoringBulkDoc(String.valueOf(i), String.valueOf(i),
|
||||
randomFrom(MonitoringIndex.values()), randomAsciiOfLength(5),
|
||||
randomAsciiOfLength(5), SOURCE, XContentType.JSON));
|
||||
}
|
||||
assertThat(request.getDocs(), hasSize(nbDocs));
|
||||
}
|
||||
|
@ -162,19 +166,7 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
|||
|
||||
int numDocs = iterations(10, 30);
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(randomAsciiOfLength(2), randomVersion(random()).toString());
|
||||
doc.setType(randomFrom("type1", "type2", "type3"));
|
||||
doc.setSource(SOURCE, XContentType.JSON);
|
||||
if (randomBoolean()) {
|
||||
doc.setIndex(MonitoringIndex.DATA);
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
doc.setId(randomAsciiOfLength(3));
|
||||
}
|
||||
if (rarely()) {
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
}
|
||||
request.add(doc);
|
||||
request.add(MonitoringBulkDocTests.newRandomMonitoringBulkDoc());
|
||||
}
|
||||
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
|
@ -195,10 +187,13 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
|||
assertThat(doc2.getMonitoringId(), equalTo(doc.getMonitoringId()));
|
||||
assertThat(doc2.getMonitoringVersion(), equalTo(doc.getMonitoringVersion()));
|
||||
assertThat(doc2.getClusterUUID(), equalTo(doc.getClusterUUID()));
|
||||
assertThat(doc2.getTimestamp(), equalTo(doc.getTimestamp()));
|
||||
assertThat(doc2.getSourceNode(), equalTo(doc.getSourceNode()));
|
||||
assertThat(doc2.getIndex(), equalTo(doc.getIndex()));
|
||||
assertThat(doc2.getType(), equalTo(doc.getType()));
|
||||
assertThat(doc2.getId(), equalTo(doc.getId()));
|
||||
assertThat(doc2.getSource(), equalTo(doc.getSource()));
|
||||
assertThat(doc2.getXContentType(), equalTo(doc.getXContentType()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -61,9 +62,10 @@ public class MonitoringBulkTests extends MonitoringIntegTestCase {
|
|||
|
||||
int numDocs = scaledRandomIntBetween(100, 5000);
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
doc.setType(randomFrom(types));
|
||||
doc.setSource(jsonBuilder().startObject().field("num", numDocs).endObject().bytes(), XContentType.JSON);
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(),
|
||||
MonitoringTemplateUtils.TEMPLATE_VERSION, null, randomFrom(types), null,
|
||||
jsonBuilder().startObject().field("num", numDocs).endObject().bytes(),
|
||||
XContentType.JSON);
|
||||
requestBuilder.add(doc);
|
||||
}
|
||||
|
||||
|
@ -113,10 +115,13 @@ public class MonitoringBulkTests extends MonitoringIntegTestCase {
|
|||
|
||||
int numDocs = scaledRandomIntBetween(10, 50);
|
||||
for (int k = 0; k < numDocs; k++) {
|
||||
BytesReference source = jsonBuilder().startObject()
|
||||
.field("num", k)
|
||||
.endObject().bytes();
|
||||
MonitoringBulkDoc doc =
|
||||
new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
doc.setType("concurrent");
|
||||
doc.setSource(jsonBuilder().startObject().field("num", k).endObject().bytes(), XContentType.JSON);
|
||||
new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(),
|
||||
MonitoringTemplateUtils.TEMPLATE_VERSION, null,
|
||||
"concurrent", null, source, XContentType.JSON);
|
||||
requestBuilder.add(doc);
|
||||
}
|
||||
|
||||
|
@ -150,15 +155,16 @@ public class MonitoringBulkTests extends MonitoringIntegTestCase {
|
|||
int unsupportedDocs = 0;
|
||||
|
||||
for (int i = 0; i < totalDocs; i++) {
|
||||
BytesReference source = jsonBuilder().startObject().field("num", i).endObject().bytes();
|
||||
MonitoringBulkDoc doc;
|
||||
if (randomBoolean()) {
|
||||
doc = new MonitoringBulkDoc("unknown", MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
doc = new MonitoringBulkDoc("unknown", MonitoringTemplateUtils.TEMPLATE_VERSION,
|
||||
null, randomFrom(types), null, source, XContentType.JSON);
|
||||
unsupportedDocs++;
|
||||
} else {
|
||||
doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION,
|
||||
null, randomFrom(types), null, source, XContentType.JSON);
|
||||
}
|
||||
doc.setType(randomFrom(types));
|
||||
doc.setSource(jsonBuilder().startObject().field("num", i).endObject().bytes(), XContentType.JSON);
|
||||
requestBuilder.add(doc);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,13 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.discovery.DiscoverySettings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -53,7 +56,6 @@ import java.util.function.Consumer;
|
|||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
|
@ -245,11 +247,19 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
|
|||
private static MonitoringBulkRequest randomRequest(final int numDocs) throws IOException {
|
||||
MonitoringBulkRequest request = new MonitoringBulkRequest();
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(randomFrom(MonitoredSystem.values()).getSystem(),
|
||||
randomVersion(random()).toString());
|
||||
doc.setType(randomFrom("type1", "type2"));
|
||||
doc.setSource(jsonBuilder().startObject().field("num", i).endObject().bytes(), XContentType.JSON);
|
||||
request.add(doc);
|
||||
String monitoringId = randomFrom(MonitoredSystem.values()).getSystem();
|
||||
String monitoringVersion = randomVersion(random()).toString();
|
||||
MonitoringIndex index = randomBoolean() ? randomFrom(MonitoringIndex.values()) : null;
|
||||
String type = randomFrom("type1", "type2", "type3");
|
||||
String id = randomAsciiOfLength(10);
|
||||
|
||||
BytesReference source;
|
||||
XContentType xContentType = randomFrom(XContentType.values());
|
||||
try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
|
||||
source = builder.startObject().field("key", i).endObject().bytes();
|
||||
}
|
||||
request.add(new MonitoringBulkDoc(monitoringId, monitoringVersion, index, type, id,
|
||||
null, 0L, null, source, xContentType));
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
@ -294,8 +304,4 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
|
|||
listener.onResponse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setState(ClusterService clusterService, ClusterState clusterState) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.monitoring.cleaner;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.Exporter;
|
||||
|
@ -23,6 +22,8 @@ import org.joda.time.DateTimeZone;
|
|||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.elasticsearch.xpack.monitoring.action.MonitoringBulkDocTests.newRandomSourceNode;
|
||||
|
||||
@ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
|
||||
public abstract class AbstractIndicesCleanerTestCase extends MonitoringIntegTestCase {
|
||||
|
@ -185,7 +186,16 @@ public abstract class AbstractIndicesCleanerTestCase extends MonitoringIntegTest
|
|||
}
|
||||
|
||||
private MonitoringDoc randomMonitoringDoc() {
|
||||
return new MonitoringDoc(randomFrom(MonitoredSystem.values()).getSystem(), VersionUtils.randomVersion(random()).toString());
|
||||
String monitoringId = randomFrom(MonitoredSystem.values()).getSystem();
|
||||
String monitoringVersion = randomVersion(random()).toString();
|
||||
String type = randomFrom("type1", "type2", "type3");
|
||||
String id = randomBoolean() ? randomAsciiOfLength(3) : null;
|
||||
String clusterUUID = randomBoolean() ? randomAsciiOfLength(5) : null;
|
||||
long timestamp = randomBoolean() ? randomNonNegativeLong() : 0L;
|
||||
MonitoringDoc.Node sourceNode = randomBoolean() ? newRandomSourceNode() : null;
|
||||
|
||||
return new MonitoringDoc(monitoringId, monitoringVersion, type, id, clusterUUID,
|
||||
timestamp, sourceNode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,8 +223,8 @@ public abstract class AbstractIndicesCleanerTestCase extends MonitoringIntegTest
|
|||
* Creates a monitoring timestamped index using a given template version.
|
||||
*/
|
||||
protected void createTimestampedIndex(DateTime creationDate, String version) {
|
||||
MonitoringDoc monitoringDoc = randomMonitoringDoc();
|
||||
monitoringDoc.setTimestamp(creationDate.getMillis());
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(null, null, null, null, null,
|
||||
creationDate.getMillis(), (MonitoringDoc.Node) null);
|
||||
|
||||
MonitoringIndexNameResolver.Timestamped resolver =
|
||||
new MockTimestampedIndexNameResolver(MonitoredSystem.ES, Settings.EMPTY, version);
|
||||
|
|
|
@ -256,7 +256,9 @@ public class ExportersTests extends ESTestCase {
|
|||
protected void doRun() throws Exception {
|
||||
List<MonitoringDoc> docs = new ArrayList<>();
|
||||
for (int n = 0; n < threadDocs; n++) {
|
||||
docs.add(new MonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()));
|
||||
docs.add(new MonitoringDoc(MonitoredSystem.ES.getSystem(),
|
||||
Version.CURRENT.toString(), null, null, null, 0L,
|
||||
(MonitoringDoc.Node) null));
|
||||
}
|
||||
barrier.await(10, TimeUnit.SECONDS);
|
||||
exporters.export(docs, ActionListener.wrap(
|
||||
|
|
|
@ -7,129 +7,44 @@ package org.elasticsearch.xpack.monitoring.exporter;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc.Node.fromDiscoveryNode;
|
||||
|
||||
public class MonitoringDocTests extends ESTestCase {
|
||||
|
||||
public void testSerialization() throws IOException {
|
||||
int iterations = randomIntBetween(5, 50);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(randomAsciiOfLength(2), randomAsciiOfLength(2));
|
||||
if (frequently()) {
|
||||
monitoringDoc.setClusterUUID(randomAsciiOfLength(5));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
monitoringDoc.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
public void testFromDiscoveryNode() {
|
||||
assertEquals(null, fromDiscoveryNode(null));
|
||||
|
||||
boolean hasSourceNode = randomBoolean();
|
||||
if (hasSourceNode) {
|
||||
monitoringDoc.setSourceNode(newRandomSourceNode());
|
||||
}
|
||||
String nodeId = randomAsciiOfLength(5);
|
||||
TransportAddress address = buildNewFakeTransportAddress();
|
||||
Version version = randomFrom(Version.V_2_4_1, Version.V_5_0_1, Version.CURRENT);
|
||||
|
||||
BytesStreamOutput output = new BytesStreamOutput();
|
||||
Version outputVersion = randomVersion(random());
|
||||
output.setVersion(outputVersion);
|
||||
monitoringDoc.writeTo(output);
|
||||
|
||||
StreamInput streamInput = output.bytes().streamInput();
|
||||
streamInput.setVersion(randomVersion(random()));
|
||||
MonitoringDoc monitoringDoc2 = new MonitoringDoc(streamInput);
|
||||
|
||||
assertThat(monitoringDoc2.getMonitoringId(), equalTo(monitoringDoc.getMonitoringId()));
|
||||
assertThat(monitoringDoc2.getMonitoringVersion(), equalTo(monitoringDoc.getMonitoringVersion()));
|
||||
assertThat(monitoringDoc2.getClusterUUID(), equalTo(monitoringDoc.getClusterUUID()));
|
||||
assertThat(monitoringDoc2.getTimestamp(), equalTo(monitoringDoc.getTimestamp()));
|
||||
assertThat(monitoringDoc2.getSourceNode(), equalTo(monitoringDoc.getSourceNode()));
|
||||
if (hasSourceNode) {
|
||||
assertThat(monitoringDoc2.getSourceNode().getUUID(), equalTo(monitoringDoc.getSourceNode().getUUID()));
|
||||
assertThat(monitoringDoc2.getSourceNode().getName(), equalTo(monitoringDoc.getSourceNode().getName()));
|
||||
assertThat(monitoringDoc2.getSourceNode().getIp(), equalTo(monitoringDoc.getSourceNode().getIp()));
|
||||
assertThat(monitoringDoc2.getSourceNode().getTransportAddress(),
|
||||
equalTo(monitoringDoc.getSourceNode().getTransportAddress()));
|
||||
assertThat(monitoringDoc2.getSourceNode().getAttributes(), equalTo(monitoringDoc.getSourceNode().getAttributes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testSetSourceNode() {
|
||||
int iterations = randomIntBetween(5, 50);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
MonitoringDoc monitoringDoc = new MonitoringDoc(null, null);
|
||||
|
||||
if (randomBoolean()) {
|
||||
DiscoveryNode discoveryNode = newRandomDiscoveryNode();
|
||||
monitoringDoc.setSourceNode(discoveryNode);
|
||||
|
||||
assertThat(monitoringDoc.getSourceNode().getUUID(), equalTo(discoveryNode.getId()));
|
||||
assertThat(monitoringDoc.getSourceNode().getHost(), equalTo(discoveryNode.getHostName()));
|
||||
assertThat(monitoringDoc.getSourceNode().getTransportAddress(), equalTo(discoveryNode.getAddress().toString()));
|
||||
assertThat(monitoringDoc.getSourceNode().getIp(), equalTo(discoveryNode.getHostAddress()));
|
||||
assertThat(monitoringDoc.getSourceNode().getName(), equalTo(discoveryNode.getName()));
|
||||
assertThat(monitoringDoc.getSourceNode().getAttributes(), equalTo(discoveryNode.getAttributes()));
|
||||
} else {
|
||||
MonitoringDoc.Node node = newRandomSourceNode();
|
||||
monitoringDoc.setSourceNode(node);
|
||||
|
||||
assertThat(monitoringDoc.getSourceNode().getUUID(), equalTo(node.getUUID()));
|
||||
assertThat(monitoringDoc.getSourceNode().getHost(), equalTo(node.getHost()));
|
||||
assertThat(monitoringDoc.getSourceNode().getTransportAddress(), equalTo(node.getTransportAddress()));
|
||||
assertThat(monitoringDoc.getSourceNode().getIp(), equalTo(node.getIp()));
|
||||
assertThat(monitoringDoc.getSourceNode().getName(), equalTo(node.getName()));
|
||||
assertThat(monitoringDoc.getSourceNode().getAttributes(), equalTo(node.getAttributes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MonitoringDoc.Node newRandomSourceNode() {
|
||||
String uuid = null;
|
||||
String name = null;
|
||||
String ip = null;
|
||||
String transportAddress = null;
|
||||
String host = null;
|
||||
Map<String, String> attributes = null;
|
||||
|
||||
if (frequently()) {
|
||||
uuid = randomAsciiOfLength(5);
|
||||
name = randomAsciiOfLength(5);
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
ip = randomAsciiOfLength(5);
|
||||
transportAddress = randomAsciiOfLength(5);
|
||||
host = randomAsciiOfLength(3);
|
||||
}
|
||||
if (rarely()) {
|
||||
int nbAttributes = randomIntBetween(0, 5);
|
||||
attributes = new HashMap<>();
|
||||
for (int i = 0; i < nbAttributes; i++) {
|
||||
attributes.put("key#" + i, String.valueOf(i));
|
||||
}
|
||||
}
|
||||
return new MonitoringDoc.Node(uuid, host, transportAddress, ip, name, attributes);
|
||||
}
|
||||
|
||||
private DiscoveryNode newRandomDiscoveryNode() {
|
||||
String name = randomBoolean() ? randomAsciiOfLength(5) : "";
|
||||
Map<String, String> attributes = new HashMap<>();
|
||||
if (rarely()) {
|
||||
int nbAttributes = randomIntBetween(0, 5);
|
||||
for (int i = 0; i < nbAttributes; i++) {
|
||||
attributes.put("key#" + i, String.valueOf(i));
|
||||
if (randomBoolean()) {
|
||||
int nbAttrs = randomIntBetween(1, 5);
|
||||
for (int i = 0; i < nbAttrs; i++) {
|
||||
attributes.put("attr_" + String.valueOf(i), String.valueOf(i));
|
||||
}
|
||||
}
|
||||
Set<DiscoveryNode.Role> roles = new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values())));
|
||||
return new DiscoveryNode(randomAsciiOfLength(5), randomAsciiOfLength(3), buildNewFakeTransportAddress(),
|
||||
attributes, roles, randomVersion(random()));
|
||||
Set<DiscoveryNode.Role> roles = new HashSet<>();
|
||||
if (randomBoolean()) {
|
||||
randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values())).forEach(roles::add);
|
||||
}
|
||||
final MonitoringDoc.Node expectedNode = new MonitoringDoc.Node(nodeId,
|
||||
address.address().getHostString(), address.toString(),
|
||||
address.getAddress(), name, attributes);
|
||||
|
||||
DiscoveryNode discoveryNode =
|
||||
new DiscoveryNode(name, nodeId, address, attributes, roles, version);
|
||||
assertEquals(expectedNode, fromDiscoveryNode(discoveryNode));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ import org.elasticsearch.test.http.MockResponse;
|
|||
import org.elasticsearch.test.http.MockWebServer;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateCollector;
|
||||
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.collector.indices.IndexRecoveryCollector;
|
||||
import org.elasticsearch.xpack.monitoring.collector.indices.IndexRecoveryMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.Exporter;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.Exporters;
|
||||
|
@ -562,21 +564,18 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
|
|||
}
|
||||
|
||||
private MonitoringDoc newRandomMonitoringDoc() {
|
||||
String monitoringId = MonitoredSystem.ES.getSystem();
|
||||
String monitoringVersion = Version.CURRENT.toString();
|
||||
String clusterUUID = internalCluster().getClusterName();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
DiscoveryNode sourceNode = new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||
|
||||
if (randomBoolean()) {
|
||||
IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
|
||||
doc.setClusterUUID(internalCluster().getClusterName());
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setRecoveryResponse(new RecoveryResponse());
|
||||
return doc;
|
||||
return new IndexRecoveryMonitoringDoc(monitoringId, monitoringVersion, clusterUUID,
|
||||
timestamp, sourceNode, new RecoveryResponse());
|
||||
} else {
|
||||
ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
|
||||
doc.setClusterUUID(internalCluster().getClusterName());
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setClusterState(ClusterState.EMPTY_STATE);
|
||||
doc.setStatus(ClusterHealthStatus.GREEN);
|
||||
return doc;
|
||||
return new ClusterStateMonitoringDoc(monitoringId, monitoringVersion,clusterUUID,
|
||||
timestamp, sourceNode, ClusterState.EMPTY_STATE, ClusterHealthStatus.GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,8 +171,9 @@ public class LocalExporterTemplateTests extends MonitoringIntegTestCase {
|
|||
}
|
||||
|
||||
private String currentTimestampedIndexName() {
|
||||
MonitoringDoc doc = new MonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
MonitoringDoc doc = new MonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT
|
||||
.toString(), null, null, null, System.currentTimeMillis(),
|
||||
(MonitoringDoc.Node) null);
|
||||
|
||||
MockTimestampedIndexNameResolver resolver =
|
||||
new MockTimestampedIndexNameResolver(MonitoredSystem.ES, localExporter, MonitoringTemplateUtils.TEMPLATE_VERSION);
|
||||
|
|
|
@ -204,21 +204,18 @@ public class LocalExporterTests extends MonitoringIntegTestCase {
|
|||
}
|
||||
|
||||
private MonitoringDoc newRandomMonitoringDoc() {
|
||||
String monitoringId = MonitoredSystem.ES.getSystem();
|
||||
String monitoringVersion = Version.CURRENT.toString();
|
||||
String clusterUUID = internalCluster().getClusterName();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
DiscoveryNode sourceNode = new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||
|
||||
if (randomBoolean()) {
|
||||
IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
|
||||
doc.setClusterUUID(internalCluster().getClusterName());
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setRecoveryResponse(new RecoveryResponse());
|
||||
return doc;
|
||||
return new IndexRecoveryMonitoringDoc(monitoringId, monitoringVersion, clusterUUID,
|
||||
timestamp, sourceNode, new RecoveryResponse());
|
||||
} else {
|
||||
ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
|
||||
doc.setClusterUUID(internalCluster().getClusterName());
|
||||
doc.setTimestamp(System.currentTimeMillis());
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setClusterState(ClusterState.EMPTY_STATE);
|
||||
doc.setStatus(ClusterHealthStatus.GREEN);
|
||||
return doc;
|
||||
return new ClusterStateMonitoringDoc(monitoringId, monitoringVersion, clusterUUID,
|
||||
timestamp, sourceNode, ClusterState.EMPTY_STATE, ClusterHealthStatus.GREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,23 +27,12 @@ public class DataResolverTests extends MonitoringIndexNameResolverTestCase {
|
|||
|
||||
@Override
|
||||
protected MonitoringDoc newMonitoringDoc() {
|
||||
MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2),
|
||||
null, null, randomAsciiOfLength(5), Math.abs(randomLong()),
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkFilters() {
|
||||
return false;
|
||||
|
@ -55,16 +44,6 @@ public class DataResolverTests extends MonitoringIndexNameResolverTestCase {
|
|||
|
||||
private MonitoringIndexNameResolver.Data<MonitoringDoc> newDataResolver() {
|
||||
return new MonitoringIndexNameResolver.Data<MonitoringDoc>() {
|
||||
@Override
|
||||
public String type(MonitoringDoc document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(MonitoringDoc document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
}
|
||||
|
|
|
@ -84,32 +84,6 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean checkResolvedType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testType() {
|
||||
if (checkResolvedType()) {
|
||||
assertThat(newResolver().type(newMonitoringDoc()), not(isEmptyOrNullString()));
|
||||
} else {
|
||||
assertThat(newResolver().type(newMonitoringDoc()), is(nullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkResolvedId() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testId() {
|
||||
if (checkResolvedId()) {
|
||||
assertThat(newResolver().id(newMonitoringDoc()), not(isEmptyOrNullString()));
|
||||
} else {
|
||||
assertThat(newResolver().id(newMonitoringDoc()), is(nullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkFilters() {
|
||||
return true;
|
||||
}
|
||||
|
@ -145,7 +119,6 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
|
|||
}
|
||||
|
||||
if (resolver instanceof MonitoringIndexNameResolver.Data) {
|
||||
MonitoringIndexNameResolver.Data data = (MonitoringIndexNameResolver.Data) resolver;
|
||||
assertThat(resolver.index(newMonitoringDoc()),
|
||||
equalTo(PREFIX + DELIMITER + MonitoringIndexNameResolver.Data.DATA + DELIMITER + TEMPLATE_VERSION));
|
||||
}
|
||||
|
|
|
@ -36,24 +36,12 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas
|
|||
|
||||
@Override
|
||||
protected MonitoringDoc newMonitoringDoc() {
|
||||
MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode(randomAsciiOfLength(5), buildNewFakeTransportAddress(),
|
||||
emptyMap(), emptySet(), Version.CURRENT));
|
||||
MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2),
|
||||
null, null, randomAsciiOfLength(5), 1437580442979L, // "2015-07-22T15:54:02.979Z"
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkFilters() {
|
||||
return false;
|
||||
|
@ -61,7 +49,6 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas
|
|||
|
||||
public void testTimestampedResolver() {
|
||||
final MonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L); // "2015-07-22T15:54:02.979Z"
|
||||
|
||||
for (String format : Arrays.asList("YYYY", "YYYY.MM", "YYYY.MM.dd", "YYYY.MM.dd-HH", "YYYY.MM.dd-HH.mm", "YYYY.MM.dd-HH.mm.SS")) {
|
||||
Settings settings = Settings.EMPTY;
|
||||
|
@ -82,11 +69,6 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas
|
|||
|
||||
private MonitoringIndexNameResolver.Timestamped<MonitoringDoc> newTimestampedResolver(MonitoredSystem id, Settings settings) {
|
||||
return new MonitoringIndexNameResolver.Timestamped<MonitoringDoc>(id, settings) {
|
||||
@Override
|
||||
public String type(MonitoringDoc document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
// noop
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.common.util.set.Sets;
|
|||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDoc;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDocTests;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringIndex;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolverTestCase;
|
||||
|
@ -19,7 +20,6 @@ import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolverTe
|
|||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
||||
/**
|
||||
* Tests {@link MonitoringBulkDataResolver}.
|
||||
|
@ -30,27 +30,14 @@ public class MonitoringBulkDataResolverTests extends MonitoringIndexNameResolver
|
|||
|
||||
@Override
|
||||
protected MonitoringBulkDoc newMonitoringDoc() {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION,
|
||||
MonitoringIndex.DATA, "kibana", id,
|
||||
new BytesArray("{\"field1\" : \"value1\"}"), XContentType.JSON);
|
||||
|
||||
if (randomBoolean()) {
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
}
|
||||
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(),
|
||||
MonitoringTemplateUtils.TEMPLATE_VERSION, MonitoringIndex.DATA, "kibana", id,
|
||||
randomAsciiOfLength(5), Math.abs(randomLong()),
|
||||
MonitoringBulkDocTests.newRandomSourceNode(),
|
||||
new BytesArray("{\"field1\" : \"value1\"}"), XContentType.JSON);
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testId() {
|
||||
MonitoringBulkDoc doc = newMonitoringDoc();
|
||||
|
||||
assertThat(newResolver(doc).id(doc), sameInstance(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkFilters() {
|
||||
return false;
|
||||
|
@ -61,8 +48,6 @@ public class MonitoringBulkDataResolverTests extends MonitoringIndexNameResolver
|
|||
|
||||
MonitoringBulkDataResolver resolver = newResolver(doc);
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-data-2"));
|
||||
assertThat(resolver.type(doc), equalTo(doc.getType()));
|
||||
assertThat(resolver.id(doc), sameInstance(id));
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -5,21 +5,17 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.resolver.bulk;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDoc;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkDocTests;
|
||||
import org.elasticsearch.xpack.monitoring.action.MonitoringIndex;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolverTestCase;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Tests {@link MonitoringBulkTimestampedResolver}.
|
||||
|
@ -29,28 +25,16 @@ public class MonitoringBulkTimestampedResolverTests
|
|||
|
||||
@Override
|
||||
protected MonitoringBulkDoc newMonitoringDoc() {
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(), MonitoringTemplateUtils.TEMPLATE_VERSION,
|
||||
MonitoringIndex.TIMESTAMPED, "kibana_stats", null,
|
||||
new BytesArray("{\"field1\" : \"value1\"}"), XContentType.JSON);
|
||||
|
||||
doc.setTimestamp(1437580442979L);
|
||||
if (randomBoolean()) {
|
||||
doc.setId(randomAsciiOfLength(35));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
}
|
||||
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
MonitoringBulkDoc doc = new MonitoringBulkDoc(MonitoredSystem.KIBANA.getSystem(),
|
||||
MonitoringTemplateUtils.TEMPLATE_VERSION, MonitoringIndex.TIMESTAMPED,
|
||||
"kibana_stats",
|
||||
randomBoolean() ? randomAsciiOfLength(35) : null,
|
||||
randomAsciiOfLength(5), 1437580442979L,
|
||||
MonitoringBulkDocTests.newRandomSourceNode(),
|
||||
new BytesArray("{\"field1\" : \"value1\"}"), XContentType.JSON);
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkFilters() {
|
||||
return false;
|
||||
|
@ -61,8 +45,6 @@ public class MonitoringBulkTimestampedResolverTests
|
|||
|
||||
MonitoringBulkTimestampedResolver resolver = newResolver(doc);
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-kibana-2-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(doc.getType()));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -40,20 +40,23 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas
|
|||
.issueDate(1437580442979L)
|
||||
.expiryDate(1437580442979L + TimeValue.timeValueHours(2).getMillis());
|
||||
|
||||
ClusterInfoMonitoringDoc doc = new ClusterInfoMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setVersion(randomFrom(Version.V_2_0_0, Version.CURRENT).toString());
|
||||
doc.setLicense(licenseBuilder.build());
|
||||
doc.setClusterName(randomAsciiOfLength(5));
|
||||
doc.setClusterStats(
|
||||
|
||||
|
||||
ClusterInfoMonitoringDoc doc = new ClusterInfoMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5),
|
||||
Math.abs(randomLong()),
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
randomAsciiOfLength(5),
|
||||
randomFrom(Version.V_2_0_0, Version.CURRENT).toString(),
|
||||
licenseBuilder.build(),
|
||||
Collections.singletonList(new MonitoringFeatureSet.Usage(randomBoolean(), randomBoolean(), emptyMap())),
|
||||
new ClusterStatsResponse(
|
||||
Math.abs(randomLong()),
|
||||
ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList()));
|
||||
doc.setUsage(Collections.singletonList(new MonitoringFeatureSet.Usage(randomBoolean(), randomBoolean(), emptyMap())));
|
||||
Collections.emptyList())
|
||||
);
|
||||
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to generated random ClusterInfoMonitoringDoc", e);
|
||||
|
@ -66,16 +69,10 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas
|
|||
}
|
||||
|
||||
public void testClusterInfoResolver() throws Exception {
|
||||
String clusterUUID = UUID.randomUUID().toString();
|
||||
|
||||
ClusterInfoMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setClusterUUID(clusterUUID);
|
||||
|
||||
ClusterInfoResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-data-" + MonitoringTemplateUtils.TEMPLATE_VERSION));
|
||||
assertThat(resolver.type(doc), equalTo(ClusterInfoResolver.TYPE));
|
||||
assertThat(resolver.id(doc), equalTo(clusterUUID));
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
"cluster_uuid",
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.index.query.QueryBuilders;
|
|||
import org.elasticsearch.license.License;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterInfoMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase;
|
||||
|
@ -65,14 +66,14 @@ public class ClusterInfoTests extends MonitoringIntegTestCase {
|
|||
awaitIndexExists(dataIndex);
|
||||
|
||||
// waiting for cluster info collector to collect data
|
||||
awaitMonitoringDocsCount(equalTo(1L), ClusterInfoResolver.TYPE);
|
||||
awaitMonitoringDocsCount(equalTo(1L), ClusterInfoMonitoringDoc.TYPE);
|
||||
|
||||
// retrieving cluster info document
|
||||
GetResponse response = client().prepareGet(dataIndex, ClusterInfoResolver.TYPE, clusterUUID).get();
|
||||
GetResponse response = client().prepareGet(dataIndex, ClusterInfoMonitoringDoc.TYPE, clusterUUID).get();
|
||||
assertTrue("cluster_info document does not exist in data index", response.isExists());
|
||||
|
||||
assertThat(response.getIndex(), equalTo(dataIndex));
|
||||
assertThat(response.getType(), equalTo(ClusterInfoResolver.TYPE));
|
||||
assertThat(response.getType(), equalTo(ClusterInfoMonitoringDoc.TYPE));
|
||||
assertThat(response.getId(), equalTo(clusterUUID));
|
||||
|
||||
Map<String, Object> source = response.getSource();
|
||||
|
@ -139,7 +140,7 @@ public class ClusterInfoTests extends MonitoringIntegTestCase {
|
|||
|
||||
assertHitCount(client().prepareSearch().setSize(0)
|
||||
.setIndices(dataIndex)
|
||||
.setTypes(ClusterInfoResolver.TYPE)
|
||||
.setTypes(ClusterInfoMonitoringDoc.TYPE)
|
||||
.setQuery(
|
||||
QueryBuilders.boolQuery()
|
||||
.should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.ACTIVE.label()))
|
||||
|
|
|
@ -25,12 +25,10 @@ public class ClusterStateNodeResolverTests extends
|
|||
|
||||
@Override
|
||||
protected ClusterStateNodeMonitoringDoc newMonitoringDoc() {
|
||||
ClusterStateNodeMonitoringDoc doc = new ClusterStateNodeMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setNodeId(UUID.randomUUID().toString());
|
||||
doc.setStateUUID(UUID.randomUUID().toString());
|
||||
ClusterStateNodeMonitoringDoc doc = new ClusterStateNodeMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
UUID.randomUUID().toString(), randomAsciiOfLength(5));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -39,24 +37,11 @@ public class ClusterStateNodeResolverTests extends
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testClusterStateNodeResolver() throws Exception {
|
||||
final String nodeId = UUID.randomUUID().toString();
|
||||
final String stateUUID = UUID.randomUUID().toString();
|
||||
|
||||
ClusterStateNodeMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setNodeId(nodeId);
|
||||
doc.setStateUUID(stateUUID);
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
ClusterStateNodeResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(ClusterStateNodeResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -28,34 +28,25 @@ public class ClusterStateResolverTests extends MonitoringIndexNameResolverTestCa
|
|||
|
||||
@Override
|
||||
protected ClusterStateMonitoringDoc newMonitoringDoc() {
|
||||
ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setStatus(randomFrom(ClusterHealthStatus.values()));
|
||||
|
||||
DiscoveryNode masterNode = new DiscoveryNode("master", buildNewFakeTransportAddress(),
|
||||
emptyMap(), emptySet(), Version.CURRENT);
|
||||
DiscoveryNode otherNode = new DiscoveryNode("other", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(masterNode).add(otherNode).masterNodeId(masterNode.getId()).build();
|
||||
ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(discoveryNodes).build();
|
||||
doc.setClusterState(clusterState);
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
clusterState, randomFrom(ClusterHealthStatus.values()));
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void testClusterStateResolver() throws IOException {
|
||||
ClusterStateMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
ClusterStateResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(ClusterStateResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
|||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateNodeMonitoringDoc;
|
||||
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
|
||||
import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase;
|
||||
|
@ -113,10 +114,10 @@ public class ClusterStateTests extends MonitoringIntegTestCase {
|
|||
awaitIndexExists(timestampedIndex);
|
||||
|
||||
logger.debug("--> waiting for documents to be collected");
|
||||
awaitMonitoringDocsCount(greaterThanOrEqualTo(nbNodes), ClusterStateNodeResolver.TYPE);
|
||||
awaitMonitoringDocsCount(greaterThanOrEqualTo(nbNodes), ClusterStateNodeMonitoringDoc.TYPE);
|
||||
|
||||
logger.debug("--> searching for monitoring documents of type [{}]", ClusterStateNodeResolver.TYPE);
|
||||
SearchResponse response = client().prepareSearch(timestampedIndex).setTypes(ClusterStateNodeResolver.TYPE).get();
|
||||
logger.debug("--> searching for monitoring documents of type [{}]", ClusterStateNodeMonitoringDoc.TYPE);
|
||||
SearchResponse response = client().prepareSearch(timestampedIndex).setTypes(ClusterStateNodeMonitoringDoc.TYPE).get();
|
||||
assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(nbNodes));
|
||||
|
||||
logger.debug("--> checking that every document contains the expected fields");
|
||||
|
@ -141,7 +142,7 @@ public class ClusterStateTests extends MonitoringIntegTestCase {
|
|||
logger.debug("--> check that node attributes are indexed");
|
||||
assertThat(client().prepareSearch().setSize(0)
|
||||
.setIndices(timestampedIndex)
|
||||
.setTypes(ClusterStateNodeResolver.TYPE)
|
||||
.setTypes(ClusterStateNodeMonitoringDoc.TYPE)
|
||||
.setQuery(QueryBuilders.matchQuery(MonitoringIndexNameResolver.Fields.SOURCE_NODE + ".attributes.custom", randomInt))
|
||||
.get().getHits().getTotalHits(), greaterThan(0L));
|
||||
|
||||
|
|
|
@ -61,27 +61,18 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa
|
|||
|
||||
@Override
|
||||
protected ClusterStatsMonitoringDoc newMonitoringDoc() {
|
||||
ClusterStatsMonitoringDoc doc = new ClusterStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setClusterStats(randomClusterStats());
|
||||
ClusterStatsMonitoringDoc doc = new ClusterStatsMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
randomClusterStats());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testClusterStatsResolver() throws Exception {
|
||||
ClusterStatsMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
ClusterStatsResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(ClusterStatsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -33,17 +33,16 @@ public class IndexRecoveryResolverTests extends MonitoringIndexNameResolverTestC
|
|||
|
||||
@Override
|
||||
protected IndexRecoveryMonitoringDoc newMonitoringDoc() {
|
||||
IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
|
||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||
Map<String, java.util.List<RecoveryState>> shardRecoveryStates = new HashMap<>();
|
||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId("test", "uuid", 0), localNode.getId(), true,
|
||||
ShardRoutingState.INITIALIZING, RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
|
||||
shardRecoveryStates.put("test", Collections.singletonList(new RecoveryState(shardRouting, localNode, null)));
|
||||
doc.setRecoveryResponse(new RecoveryResponse(10, 10, 0, false, shardRecoveryStates, Collections.emptyList()));
|
||||
|
||||
IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
new RecoveryResponse(10, 10, 0, false, shardRecoveryStates, Collections.emptyList()));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -52,19 +51,11 @@ public class IndexRecoveryResolverTests extends MonitoringIndexNameResolverTestC
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testIndexRecoveryResolver() throws Exception {
|
||||
IndexRecoveryMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
IndexRecoveryResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(IndexRecoveryResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -38,34 +38,23 @@ import java.util.UUID;
|
|||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class IndexStatsResolverTests extends MonitoringIndexNameResolverTestCase<IndexStatsMonitoringDoc, IndexStatsResolver> {
|
||||
|
||||
@Override
|
||||
protected IndexStatsMonitoringDoc newMonitoringDoc() {
|
||||
IndexStatsMonitoringDoc doc = new IndexStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setIndexStats(randomIndexStats());
|
||||
IndexStatsMonitoringDoc doc = new IndexStatsMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
randomIndexStats());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testIndexStatsResolver() throws Exception {
|
||||
IndexStatsMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
|
||||
IndexStatsResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(IndexStatsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -47,29 +47,18 @@ public class IndicesStatsResolverTests extends MonitoringIndexNameResolverTestCa
|
|||
|
||||
@Override
|
||||
protected IndicesStatsMonitoringDoc newMonitoringDoc() {
|
||||
IndicesStatsMonitoringDoc doc = new IndicesStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setIndicesStats(randomIndicesStats());
|
||||
IndicesStatsMonitoringDoc doc = new IndicesStatsMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
randomIndicesStats());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testIndicesStatsResolver() throws Exception {
|
||||
IndicesStatsMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(1437580442979L);
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
|
||||
IndicesStatsResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(IndicesStatsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet("cluster_uuid", "timestamp", "source_node", "indices_stats"), XContentType.JSON);
|
||||
|
|
|
@ -19,19 +19,18 @@ import java.util.UUID;
|
|||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class DiscoveryNodeResolverTests extends MonitoringIndexNameResolverTestCase<DiscoveryNodeMonitoringDoc, DiscoveryNodeResolver> {
|
||||
|
||||
@Override
|
||||
protected DiscoveryNodeMonitoringDoc newMonitoringDoc() {
|
||||
DiscoveryNodeMonitoringDoc doc = new DiscoveryNodeMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setNode(new DiscoveryNode(randomAsciiOfLength(3), UUID.randomUUID().toString(),
|
||||
buildNewFakeTransportAddress(), emptyMap(), emptySet(),
|
||||
VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT)));
|
||||
DiscoveryNodeMonitoringDoc doc = new DiscoveryNodeMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode(randomAsciiOfLength(3), UUID.randomUUID().toString(),
|
||||
buildNewFakeTransportAddress(), emptyMap(), emptySet(),
|
||||
randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT)));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -42,12 +41,9 @@ public class DiscoveryNodeResolverTests extends MonitoringIndexNameResolverTestC
|
|||
|
||||
public void testDiscoveryNodeResolver() throws Exception {
|
||||
DiscoveryNodeMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
DiscoveryNodeResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-data-" + MonitoringTemplateUtils.TEMPLATE_VERSION));
|
||||
assertThat(resolver.type(doc), equalTo(DiscoveryNodeResolver.TYPE));
|
||||
assertThat(resolver.id(doc), equalTo(doc.getNode().getId()));
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
|
|
@ -59,22 +59,13 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase<
|
|||
|
||||
@Override
|
||||
protected NodeStatsMonitoringDoc newMonitoringDoc() {
|
||||
NodeStatsMonitoringDoc doc = new NodeStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
doc.setNodeMaster(randomBoolean());
|
||||
doc.setNodeId(UUID.randomUUID().toString());
|
||||
doc.setMlockall(randomBoolean());
|
||||
doc.setNodeStats(randomNodeStats());
|
||||
NodeStatsMonitoringDoc doc = new NodeStatsMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5),
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
randomBoolean(), randomNodeStats(), randomBoolean());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkResolvedId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertSourceField(String field, Map<String, Object> sourceFields) {
|
||||
// Assertions on node stats fields that are not reported on Windows platforms
|
||||
|
@ -111,12 +102,9 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase<
|
|||
|
||||
public void testNodeStatsResolver() throws IOException {
|
||||
NodeStatsMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
NodeStatsResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(NodeStatsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), nullValue());
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
|
@ -161,7 +149,8 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase<
|
|||
new ThreadPoolStats.Stats(ThreadPool.Names.SEARCH, 0, 0, 0, 0, 0, 0),
|
||||
new ThreadPoolStats.Stats(InternalWatchExecutor.THREAD_POOL_NAME, 0, 0, 0, 0, 0, 0)
|
||||
);
|
||||
return new NodeStats(new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), 0,
|
||||
return new NodeStats(new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
1437580442979L,
|
||||
new NodeIndicesStats(new CommonStats(), statsByShard), OsProbe.getInstance().osStats(),
|
||||
ProcessProbe.getInstance().processStats(), JvmStats.jvmStats(),
|
||||
new ThreadPoolStats(threadPoolStats),
|
||||
|
|
|
@ -7,11 +7,9 @@ package org.elasticsearch.xpack.monitoring.resolver.shards;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -30,11 +28,6 @@ public class ShardsResolverTests extends MonitoringIndexNameResolverTestCase<Sha
|
|||
|
||||
@Override
|
||||
protected ShardMonitoringDoc newMonitoringDoc() {
|
||||
ShardMonitoringDoc doc = new ShardMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2));
|
||||
doc.setClusterUUID(randomAsciiOfLength(5));
|
||||
doc.setTimestamp(Math.abs(randomLong()));
|
||||
doc.setClusterStateUUID(UUID.randomUUID().toString());
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
|
||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(
|
||||
new ShardId(new Index(randomAsciiOfLength(5), UUID.randomUUID().toString()), randomIntBetween(0, 5)),
|
||||
|
@ -42,22 +35,20 @@ public class ShardsResolverTests extends MonitoringIndexNameResolverTestCase<Sha
|
|||
shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
shardRouting = shardRouting.moveToStarted();
|
||||
shardRouting = shardRouting.relocate("node-1", ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
doc.setShardRouting(shardRouting);
|
||||
|
||||
ShardMonitoringDoc doc = new ShardMonitoringDoc(randomMonitoringId(),
|
||||
randomAsciiOfLength(2), randomAsciiOfLength(5), 1437580442979L,
|
||||
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
||||
shardRouting,
|
||||
UUID.randomUUID().toString());
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void testShardsResolver() throws Exception {
|
||||
ShardMonitoringDoc doc = newMonitoringDoc();
|
||||
doc.setTimestamp(1437580442979L);
|
||||
|
||||
final String clusterStateUUID = UUID.randomUUID().toString();
|
||||
doc.setClusterStateUUID(clusterStateUUID);
|
||||
doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
|
||||
|
||||
ShardsResolver resolver = newResolver();
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(ShardsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), equalTo(ShardsResolver.id(clusterStateUUID, doc.getShardRouting())));
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
"cluster_uuid",
|
||||
|
@ -70,46 +61,5 @@ public class ShardsResolverTests extends MonitoringIndexNameResolverTestCase<Sha
|
|||
"shard.relocating_node",
|
||||
"shard.shard",
|
||||
"shard.index"), XContentType.JSON);
|
||||
|
||||
final String index = "test-" + randomIntBetween(0, 100);
|
||||
final int shardId = randomIntBetween(0, 500);
|
||||
final boolean primary = randomBoolean();
|
||||
final String sourceNode = "node-" + randomIntBetween(0, 5);
|
||||
final String relocationNode = "node-" + randomIntBetween(6, 10);
|
||||
|
||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(new Index(index, ""), shardId),
|
||||
null, primary, ShardRoutingState.UNASSIGNED);
|
||||
shardRouting = shardRouting.initialize(sourceNode, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
shardRouting = shardRouting.moveToStarted();
|
||||
shardRouting = shardRouting.relocate(relocationNode, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
doc.setShardRouting(shardRouting);
|
||||
|
||||
assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22"));
|
||||
assertThat(resolver.type(doc), equalTo(ShardsResolver.TYPE));
|
||||
assertThat(resolver.id(doc), equalTo(ShardsResolver.id(clusterStateUUID, shardRouting)));
|
||||
assertThat(resolver.id(doc),
|
||||
equalTo(clusterStateUUID + ":" + sourceNode + ":" + index + ":" + shardId + ":" + (primary ? "p" : "r")));
|
||||
|
||||
assertSource(resolver.source(doc, XContentType.JSON),
|
||||
Sets.newHashSet(
|
||||
"cluster_uuid",
|
||||
"timestamp",
|
||||
"source_node",
|
||||
"state_uuid",
|
||||
"shard.state",
|
||||
"shard.primary",
|
||||
"shard.node",
|
||||
"shard.relocating_node",
|
||||
"shard.shard",
|
||||
"shard.index"), XContentType.JSON);
|
||||
}
|
||||
|
||||
public void testShardId() {
|
||||
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(new Index("bar", ""), 42), false,
|
||||
RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
||||
assertThat(ShardsResolver.id("foo", shardRouting), equalTo("foo:_na:bar:42:r"));
|
||||
shardRouting = shardRouting.initialize("node1", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
shardRouting = shardRouting.moveToStarted();
|
||||
assertThat(ShardsResolver.id("foo", shardRouting), equalTo("foo:node1:bar:42:r"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -377,16 +377,6 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase {
|
|||
super(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(MonitoringDoc document) {
|
||||
throw new UnsupportedOperationException("MockDataIndexNameResolver does not support resolving type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id(MonitoringDoc document) {
|
||||
throw new UnsupportedOperationException("MockDataIndexNameResolver does not support resolving id");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
throw new UnsupportedOperationException("MockDataIndexNameResolver does not support resolving building XContent");
|
||||
|
@ -399,11 +389,6 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase {
|
|||
super(system, settings, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(MonitoringDoc document) {
|
||||
throw new UnsupportedOperationException("MockTimestampedIndexNameResolver does not support resolving type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildXContent(MonitoringDoc document, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
throw new UnsupportedOperationException("MockTimestampedIndexNameResolver does not support resolving building XContent");
|
||||
|
|
Loading…
Reference in New Issue