[Monitoring] Add interval_ms to Monitoring documents (elastic/x-pack-elasticsearch#2650)

This commit adds a new interval_ms field to the monitoring documents. 
This field indicates the current collection interval for Elasticsearch or 
external monitored systems. The value is indexed as a long.

Related to elastic/x-pack-elasticsearch#212

Original commit: elastic/x-pack-elasticsearch@2ceb20455c
This commit is contained in:
Tanguy Leroux 2017-10-13 11:18:47 +02:00 committed by GitHub
parent 10cc0088e4
commit a6776cef97
44 changed files with 264 additions and 164 deletions

View File

@ -201,7 +201,7 @@ public class MonitoringService extends AbstractLifecycleComponent {
}
try {
Collection<MonitoringDoc> result = collector.collect(timestamp);
Collection<MonitoringDoc> result = collector.collect(timestamp, interval.getMillis());
if (result != null) {
results.addAll(result);
}

View File

@ -27,7 +27,7 @@ public class MonitoringBulkDoc implements Writeable {
private final String type;
private final String id;
private final long timestamp;
private final long interval;
private final long intervalMillis;
private final BytesReference source;
private final XContentType xContentType;
@ -35,7 +35,7 @@ public class MonitoringBulkDoc implements Writeable {
final String type,
@Nullable final String id,
final long timestamp,
final long interval,
final long intervalMillis,
final BytesReference source,
final XContentType xContentType) {
@ -44,7 +44,7 @@ public class MonitoringBulkDoc implements Writeable {
// We allow strings to be "" because Logstash 5.2 - 5.3 would submit empty _id values for time-based documents
this.id = Strings.isNullOrEmpty(id) ? null : id;
this.timestamp = timestamp;
this.interval = interval;
this.intervalMillis = intervalMillis;
this.source = Objects.requireNonNull(source);
this.xContentType = Objects.requireNonNull(xContentType);
}
@ -98,7 +98,7 @@ public class MonitoringBulkDoc implements Writeable {
xContentType.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
out.writeVLong(interval);
out.writeVLong(intervalMillis);
}
}
@ -118,8 +118,8 @@ public class MonitoringBulkDoc implements Writeable {
return timestamp;
}
public long getInterval() {
return interval;
public long getIntervalMillis() {
return intervalMillis;
}
public BytesReference getSource() {
@ -140,7 +140,7 @@ public class MonitoringBulkDoc implements Writeable {
}
MonitoringBulkDoc that = (MonitoringBulkDoc) o;
return timestamp == that.timestamp
&& interval == that.interval
&& intervalMillis == that.intervalMillis
&& system == that.system
&& Objects.equals(type, that.type)
&& Objects.equals(id, that.id)
@ -150,6 +150,6 @@ public class MonitoringBulkDoc implements Writeable {
@Override
public int hashCode() {
return Objects.hash(system, type, id, timestamp, interval, source, xContentType);
return Objects.hash(system, type, id, timestamp, intervalMillis, source, xContentType);
}
}

View File

@ -103,6 +103,7 @@ public class TransportMonitoringBulkAction extends HandledTransportAction<Monito
final MonitoredSystem system = bulkDoc.getSystem();
final String type = bulkDoc.getType();
final String id = bulkDoc.getId();
final long intervalMillis = bulkDoc.getIntervalMillis();
final XContentType xContentType = bulkDoc.getXContentType();
final BytesReference source = bulkDoc.getSource();
@ -113,7 +114,8 @@ public class TransportMonitoringBulkAction extends HandledTransportAction<Monito
timestamp = defaultTimestamp;
}
return new BytesReferenceMonitoringDoc(defaultClusterUUID, timestamp, defaultNode, system, type, id, xContentType, source);
return new BytesReferenceMonitoringDoc(defaultClusterUUID, timestamp, intervalMillis,
defaultNode, system, type, id, xContentType, source);
}
/**

View File

@ -81,11 +81,11 @@ public abstract class Collector extends AbstractComponent {
return clusterService.state().nodes().isLocalNodeElectedMaster();
}
public Collection<MonitoringDoc> collect(final long timestamp) {
public Collection<MonitoringDoc> collect(final long timestamp, final long interval) {
try {
if (shouldCollect()) {
logger.trace("collector [{}] - collecting data...", name());
return doCollect(convertNode(timestamp, clusterService.localNode()));
return doCollect(convertNode(timestamp, clusterService.localNode()), interval);
}
} catch (ElasticsearchTimeoutException e) {
logger.error((Supplier<?>) () -> new ParameterizedMessage("collector [{}] timed out when collecting data", name()));
@ -95,7 +95,7 @@ public abstract class Collector extends AbstractComponent {
return null;
}
protected abstract Collection<MonitoringDoc> doCollect(MonitoringDoc.Node sourceNode) throws Exception;
protected abstract Collection<MonitoringDoc> doCollect(MonitoringDoc.Node sourceNode, long interval) throws Exception;
protected String clusterUUID() {
return clusterService.state().metaData().clusterUUID();

View File

@ -67,7 +67,7 @@ public class ClusterStatsCollector extends Collector {
}
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
final Supplier<ClusterStatsResponse> clusterStatsSupplier =
() -> client.admin().cluster().prepareClusterStats().get(getCollectionTimeout());
final Supplier<List<XPackFeatureSet.Usage>> usageSupplier =
@ -83,7 +83,7 @@ public class ClusterStatsCollector extends Collector {
// Adds a cluster stats document
return Collections.singleton(
new ClusterStatsMonitoringDoc(clusterUUID(), timestamp(), node, clusterName, version, clusterStats.getStatus(),
new ClusterStatsMonitoringDoc(clusterUUID(), timestamp(), interval, node, clusterName, version, clusterStats.getStatus(),
license, usage, clusterStats, clusterState));
}

View File

@ -56,6 +56,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
ClusterStatsMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final MonitoringDoc.Node node,
final String clusterName,
final String version,
@ -65,7 +66,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
@Nullable final ClusterStatsResponse clusterStats,
@Nullable final ClusterState clusterState) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null);
super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null);
this.clusterName = Objects.requireNonNull(clusterName);
this.version = Objects.requireNonNull(version);
this.status = Objects.requireNonNull(status);

View File

@ -64,7 +64,7 @@ public class IndexRecoveryCollector extends Collector {
}
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
List<MonitoringDoc> results = new ArrayList<>(1);
RecoveryResponse recoveryResponse = client.admin().indices().prepareRecoveries()
.setIndices(getCollectionIndices())
@ -73,7 +73,7 @@ public class IndexRecoveryCollector extends Collector {
.get(getCollectionTimeout());
if (recoveryResponse.hasRecoveries()) {
results.add(new IndexRecoveryMonitoringDoc(clusterUUID(), timestamp(), node, recoveryResponse));
results.add(new IndexRecoveryMonitoringDoc(clusterUUID(), timestamp(), interval, node, recoveryResponse));
}
return Collections.unmodifiableCollection(results);
}

View File

@ -27,10 +27,11 @@ public class IndexRecoveryMonitoringDoc extends MonitoringDoc {
public IndexRecoveryMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final MonitoringDoc.Node node,
final RecoveryResponse recoveryResponse) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null);
super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null);
this.recoveryResponse = Objects.requireNonNull(recoveryResponse);
}

View File

@ -51,7 +51,7 @@ public class IndexStatsCollector extends Collector {
}
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
final List<MonitoringDoc> results = new ArrayList<>();
final IndicesStatsResponse indicesStats = client.admin().indices().prepareStats()
.setIndices(getCollectionIndices())
@ -73,11 +73,11 @@ public class IndexStatsCollector extends Collector {
final String clusterUuid = clusterUUID();
// add the indices stats that we use to collect the index stats
results.add(new IndicesStatsMonitoringDoc(clusterUuid, timestamp, node, indicesStats));
results.add(new IndicesStatsMonitoringDoc(clusterUuid, timestamp, interval, node, indicesStats));
// collect each index stats document
for (IndexStats indexStats : indicesStats.getIndices().values()) {
results.add(new IndexStatsMonitoringDoc(clusterUuid, timestamp, node, indexStats));
results.add(new IndexStatsMonitoringDoc(clusterUuid, timestamp, interval, node, indexStats));
}
return Collections.unmodifiableCollection(results);

View File

@ -28,9 +28,10 @@ public class IndexStatsMonitoringDoc extends FilteredMonitoringDoc {
IndexStatsMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final MonitoringDoc.Node node,
final IndexStats indexStats) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
this.indexStats = Objects.requireNonNull(indexStats);
}

View File

@ -27,9 +27,10 @@ public class IndicesStatsMonitoringDoc extends FilteredMonitoringDoc {
IndicesStatsMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final MonitoringDoc.Node node,
final IndicesStatsResponse indicesStats) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
this.indicesStats = Objects.requireNonNull(indicesStats);
}

View File

@ -60,7 +60,7 @@ public class JobStatsCollector extends Collector {
}
@Override
protected List<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected List<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
// fetch details about all jobs
final GetJobsStatsAction.Response jobs =
client.getJobsStats(new GetJobsStatsAction.Request(MetaData.ALL))
@ -70,7 +70,7 @@ public class JobStatsCollector extends Collector {
final String clusterUuid = clusterUUID();
return jobs.getResponse().results().stream()
.map(jobStats -> new JobStatsMonitoringDoc(clusterUuid, timestamp, node, jobStats))
.map(jobStats -> new JobStatsMonitoringDoc(clusterUuid, timestamp, interval, node, jobStats))
.collect(Collectors.toList());
}

View File

@ -24,8 +24,12 @@ public class JobStatsMonitoringDoc extends MonitoringDoc {
private final JobStats jobStats;
public JobStatsMonitoringDoc(final String cluster, final long timestamp, final MonitoringDoc.Node node, final JobStats jobStats) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null);
public JobStatsMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final MonitoringDoc.Node node,
final JobStats jobStats) {
super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null);
this.jobStats = Objects.requireNonNull(jobStats);
}

View File

@ -64,7 +64,7 @@ public class NodeStatsCollector extends Collector {
}
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
NodesStatsRequest request = new NodesStatsRequest("_local");
request.indices(FLAGS);
request.os(true);
@ -83,7 +83,7 @@ public class NodeStatsCollector extends Collector {
final NodeStats nodeStats = response.getNodes().get(0);
return Collections.singletonList(new NodeStatsMonitoringDoc(clusterUUID(), nodeStats.getTimestamp(), node,
return Collections.singletonList(new NodeStatsMonitoringDoc(clusterUUID(), nodeStats.getTimestamp(), interval, node,
node.getUUID(), isLocalNodeMaster(), nodeStats, BootstrapInfo.isMemoryLocked()));
}

View File

@ -30,13 +30,14 @@ public class NodeStatsMonitoringDoc extends FilteredMonitoringDoc {
NodeStatsMonitoringDoc(final String cluster,
final long timestamp,
final long interval,
final MonitoringDoc.Node node,
final String nodeId,
final boolean isMaster,
final NodeStats nodeStats,
final boolean mlockall) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
super(cluster, timestamp, interval, node, MonitoredSystem.ES, TYPE, null, XCONTENT_FILTERS);
this.nodeId = Objects.requireNonNull(nodeId);
this.nodeStats = Objects.requireNonNull(nodeStats);
this.nodeMaster = isMaster;

View File

@ -28,11 +28,12 @@ public class ShardMonitoringDoc extends FilteredMonitoringDoc {
ShardMonitoringDoc(final String cluster,
final long timestamp,
final long interval,
final MonitoringDoc.Node node,
final ShardRouting shardRouting,
final String clusterStateUUID) {
super(cluster, timestamp, node, MonitoredSystem.ES, TYPE, id(clusterStateUUID, shardRouting), XCONTENT_FILTERS);
super(cluster, timestamp, interval, node, MonitoredSystem.ES, TYPE, id(clusterStateUUID, shardRouting), XCONTENT_FILTERS);
this.shardRouting = Objects.requireNonNull(shardRouting);
this.clusterStateUUID = Objects.requireNonNull(clusterStateUUID);
}

View File

@ -43,7 +43,7 @@ public class ShardsCollector extends Collector {
}
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node) throws Exception {
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval) throws Exception {
final List<MonitoringDoc> results = new ArrayList<>(1);
final ClusterState clusterState = clusterService.state();
@ -66,7 +66,7 @@ public class ShardsCollector extends Collector {
// If the shard is assigned to a node, the shard monitoring document refers to this node
shardNode = convertNode(node.getTimestamp(), clusterState.getNodes().get(shard.currentNodeId()));
}
results.add(new ShardMonitoringDoc(clusterUUID, timestamp, shardNode, shard, stateUUID));
results.add(new ShardMonitoringDoc(clusterUUID, timestamp, interval, shardNode, shard, stateUUID));
}
}
}

View File

@ -25,13 +25,14 @@ public class BytesReferenceMonitoringDoc extends MonitoringDoc {
public BytesReferenceMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
@Nullable final Node node,
final MonitoredSystem system,
final String type,
@Nullable final String id,
final XContentType xContentType,
final BytesReference source) {
super(cluster, timestamp, node, system, type, id);
super(cluster, timestamp, intervalMillis, node, system, type, id);
this.xContentType = Objects.requireNonNull(xContentType);
this.source = Objects.requireNonNull(source);
}

View File

@ -27,18 +27,19 @@ public abstract class FilteredMonitoringDoc extends MonitoringDoc {
/**
* List of common XContent fields that exist in all monitoring documents
*/
static final Set<String> COMMON_XCONTENT_FILTERS = Sets.newHashSet("cluster_uuid", "timestamp", "type", "source_node");
static final Set<String> COMMON_XCONTENT_FILTERS = Sets.newHashSet("cluster_uuid", "timestamp", "interval_ms", "type", "source_node");
private final Set<String> filters;
public FilteredMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
@Nullable final Node node,
final MonitoredSystem system,
final String type,
@Nullable final String id,
final Set<String> xContentFilters) {
super(cluster, timestamp, node, system, type, id);
super(cluster, timestamp, intervalMillis, node, system, type, id);
if (xContentFilters.isEmpty()) {
throw new IllegalArgumentException("xContentFilters must not be empty");
}

View File

@ -26,6 +26,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
private final String cluster;
private final long timestamp;
private final long intervalMillis;
private final Node node;
private final MonitoredSystem system;
private final String type;
@ -33,6 +34,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
public MonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
@Nullable final Node node,
final MonitoredSystem system,
final String type,
@ -40,6 +42,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
this.cluster = Objects.requireNonNull(cluster);
this.timestamp = timestamp;
this.intervalMillis = intervalMillis;
this.node = node;
this.system = Objects.requireNonNull(system);
this.type = Objects.requireNonNull(type);
@ -54,6 +57,10 @@ public abstract class MonitoringDoc implements ToXContentObject {
return timestamp;
}
public long getIntervalMillis() {
return intervalMillis;
}
public Node getNode() {
return node;
}
@ -80,6 +87,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
}
MonitoringDoc that = (MonitoringDoc) o;
return timestamp == that.timestamp
&& intervalMillis == that.intervalMillis
&& Objects.equals(cluster, that.cluster)
&& Objects.equals(node, that.node)
&& system == that.system
@ -89,7 +97,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
@Override
public int hashCode() {
return Objects.hash(cluster, timestamp, node, system, type, id);
return Objects.hash(cluster, timestamp, intervalMillis, node, system, type, id);
}
@Override
@ -98,6 +106,7 @@ public abstract class MonitoringDoc implements ToXContentObject {
{
builder.field("cluster_uuid", cluster);
builder.field("timestamp", toUTC(timestamp));
builder.field("interval_ms", intervalMillis);
builder.field("type", type);
builder.field("source_node", node);
innerToXContent(builder, params);
@ -153,10 +162,10 @@ public abstract class MonitoringDoc implements ToXContentObject {
transportAddress = in.readOptionalString();
ip = in.readOptionalString();
name = in.readOptionalString();
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
if (in.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
timestamp = in.readVLong();
} else {
// Read the node attributes (removed in 7.0 alpha1)
// Read the node attributes (removed in 6.0 rc1)
int size = in.readVInt();
for (int i = 0; i < size; i++) {
in.readString();
@ -173,10 +182,10 @@ public abstract class MonitoringDoc implements ToXContentObject {
out.writeOptionalString(transportAddress);
out.writeOptionalString(ip);
out.writeOptionalString(name);
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
if (out.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
out.writeVLong(timestamp);
} else {
// Write an empty map of node attributes (removed in 7.0 alpha1)
// Write an empty map of node attributes (removed in 6.0 rc1)
out.writeVInt(0);
}
}

View File

@ -22,6 +22,9 @@
"type": "date",
"format": "date_time"
},
"interval_ms": {
"type": "long"
},
"type": {
"type": "keyword"
},

View File

@ -74,14 +74,14 @@ public class MonitoringBulkDocTests extends ESTestCase {
assertThat(document.getType(), equalTo(type));
assertThat(document.getId(), equalTo(id));
assertThat(document.getTimestamp(), equalTo(timestamp));
assertThat(document.getInterval(), equalTo(interval));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getSource(), equalTo(source));
assertThat(document.getXContentType(), equalTo(xContentType));
}
public void testEqualsAndHashcode() {
final EqualsHashCodeTestUtils.CopyFunction<MonitoringBulkDoc> copy =
doc -> new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getInterval(),
doc -> new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getSource(), doc.getXContentType());
final List<EqualsHashCodeTestUtils.MutateFunction<MonitoringBulkDoc>> mutations = new ArrayList<>();
@ -90,7 +90,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
do {
system = randomFrom(MonitoredSystem.values());
} while (system == doc.getSystem());
return new MonitoringBulkDoc(system, doc.getType(), doc.getId(), doc.getTimestamp(), doc.getInterval(),
return new MonitoringBulkDoc(system, doc.getType(), doc.getId(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getSource(), doc.getXContentType());
});
mutations.add(doc -> {
@ -98,7 +98,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
do {
type = randomAlphaOfLength(5);
} while (type.equals(doc.getType()));
return new MonitoringBulkDoc(doc.getSystem(), type, doc.getId(), doc.getTimestamp(), doc.getInterval(),
return new MonitoringBulkDoc(doc.getSystem(), type, doc.getId(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getSource(), doc.getXContentType());
});
mutations.add(doc -> {
@ -106,7 +106,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
do {
id = randomAlphaOfLength(10);
} while (id.equals(doc.getId()));
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), id, doc.getTimestamp(), doc.getInterval(),
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), id, doc.getTimestamp(), doc.getIntervalMillis(),
doc.getSource(), doc.getXContentType());
});
mutations.add(doc -> {
@ -114,20 +114,20 @@ public class MonitoringBulkDocTests extends ESTestCase {
do {
timestamp = randomNonNegativeLong();
} while (timestamp == doc.getTimestamp());
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), timestamp, doc.getInterval(),
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), timestamp, doc.getIntervalMillis(),
doc.getSource(), doc.getXContentType());
});
mutations.add(doc -> {
long interval;
do {
interval = randomNonNegativeLong();
} while (interval == doc.getInterval());
} while (interval == doc.getIntervalMillis());
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), interval,
doc.getSource(), doc.getXContentType());
});
mutations.add(doc -> {
final BytesReference source = RandomObjects.randomSource(random(), doc.getXContentType());
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getInterval(),
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getIntervalMillis(),
source, doc.getXContentType());
});
mutations.add(doc -> {
@ -135,7 +135,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
do {
xContentType = randomFrom(XContentType.values());
} while (xContentType == doc.getXContentType());
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getInterval(),
return new MonitoringBulkDoc(doc.getSystem(), doc.getType(), doc.getId(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getSource(), xContentType);
});
@ -168,7 +168,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
assertEquals("type", bulkDoc.getType());
assertEquals("id", bulkDoc.getId());
assertEquals(0L, bulkDoc.getTimestamp());
assertEquals(0L, bulkDoc.getInterval());
assertEquals(0L, bulkDoc.getIntervalMillis());
assertEquals("{\"foo\":\"bar\"}", bulkDoc.getSource().utf8ToString());
assertEquals(XContentType.JSON, bulkDoc.getXContentType());
}

View File

@ -136,7 +136,7 @@ public class MonitoringBulkRequestTests extends ESTestCase {
assertThat(bulkDoc.getType(), equalTo(types[count] != null ? types[count] : defaultType));
assertThat(bulkDoc.getId(), equalTo(ids[count]));
assertThat(bulkDoc.getTimestamp(), equalTo(timestamp));
assertThat(bulkDoc.getInterval(), equalTo(interval));
assertThat(bulkDoc.getIntervalMillis(), equalTo(interval));
assertThat(bulkDoc.getSource(), equalTo(sources[count]));
assertThat(bulkDoc.getXContentType(), equalTo(xContentType));
++count;
@ -291,9 +291,9 @@ public class MonitoringBulkRequestTests extends ESTestCase {
assertThat(deserialized.getXContentType(), equalTo(original.getXContentType()));
if (version.onOrAfter(Version.V_6_0_0_rc1)) {
assertThat(deserialized.getInterval(), equalTo(original.getInterval()));
assertThat(deserialized.getIntervalMillis(), equalTo(original.getIntervalMillis()));
} else {
assertThat(deserialized.getInterval(), equalTo(0L));
assertThat(deserialized.getIntervalMillis(), equalTo(0L));
}
}
}

View File

@ -135,6 +135,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
final String type = randomAlphaOfLength(5);
final String id = randomBoolean() ? randomAlphaOfLength(5) : null;
final long timestamp = randomNonNegativeLong();
final long interval = randomNonNegativeLong();
final XContentType xContentType = randomFrom(XContentType.values());
final int nbDocs = randomIntBetween(1, 50);
@ -146,6 +147,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
when(mockBulkDoc.getType()).thenReturn(type);
when(mockBulkDoc.getId()).thenReturn(id + String.valueOf(i));
when(mockBulkDoc.getTimestamp()).thenReturn(timestamp);
when(mockBulkDoc.getIntervalMillis()).thenReturn(interval);
when(mockBulkDoc.getSource()).thenReturn(RandomObjects.randomSource(random(), xContentType));
when(mockBulkDoc.getXContentType()).thenReturn(xContentType);
}
@ -159,6 +161,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
assertThat(exportedDoc.getType(), equalTo(type));
assertThat(exportedDoc.getId(), startsWith(id));
assertThat(exportedDoc.getTimestamp(), equalTo(timestamp));
assertThat(exportedDoc.getIntervalMillis(), equalTo(interval));
assertThat(exportedDoc.getNode().getUUID(), equalTo(discoveryNode.getId()));
assertThat(exportedDoc.getCluster(), equalTo(clusterUUID));
});
@ -202,6 +205,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
final String type = randomAlphaOfLength(5);
final String id = randomBoolean() ? randomAlphaOfLength(5) : null;
final long timestamp = randomBoolean() ? randomNonNegativeLong() : 0L;
final long interval = randomNonNegativeLong();
final XContentType xContentType = randomFrom(XContentType.values());
final MonitoringDoc.Node node = MonitoringTestUtils.randomMonitoringNode(random());
@ -214,6 +218,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
when(mockBulkDoc.getType()).thenReturn(type);
when(mockBulkDoc.getId()).thenReturn(id);
when(mockBulkDoc.getTimestamp()).thenReturn(timestamp);
when(mockBulkDoc.getIntervalMillis()).thenReturn(interval);
when(mockBulkDoc.getSource()).thenReturn(BytesArray.EMPTY);
when(mockBulkDoc.getXContentType()).thenReturn(xContentType);
}
@ -228,6 +233,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
assertThat(exportedDoc.getType(), equalTo(type));
assertThat(exportedDoc.getId(), equalTo(id));
assertThat(exportedDoc.getTimestamp(), equalTo(timestamp != 0L ? timestamp : 123L));
assertThat(exportedDoc.getIntervalMillis(), equalTo(interval));
assertThat(exportedDoc.getNode(), equalTo(node));
assertThat(exportedDoc.getCluster(), equalTo("_cluster"));
});
@ -264,6 +270,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster_uuid\","
+ "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
+ "\"interval_ms\":15000,"
+ "\"type\":\"_type\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -139,7 +139,9 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
new ClusterStatsCollector(Settings.EMPTY, clusterService, licenseState, client, licenseService);
assertEquals(timeout, collector.getCollectionTimeout());
final Collection<MonitoringDoc> results = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final Collection<MonitoringDoc> results = collector.doCollect(node, interval);
assertEquals(1, results.size());
final MonitoringDoc monitoringDoc = results.iterator().next();
@ -148,6 +150,7 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
final ClusterStatsMonitoringDoc document = (ClusterStatsMonitoringDoc) monitoringDoc;
assertThat(document.getCluster(), equalTo(clusterUUID));
assertThat(document.getTimestamp(), greaterThan(0L));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getNode(), equalTo(node));
assertThat(document.getSystem(), is(MonitoredSystem.ES));
assertThat(document.getType(), equalTo(ClusterStatsMonitoringDoc.TYPE));

View File

@ -97,9 +97,9 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
}
@Override
protected ClusterStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected ClusterStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new ClusterStatsMonitoringDoc(cluster, timestamp, node,
return new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node,
clusterName, version, clusterStatus, license, usages, clusterStats, clusterState);
}
@ -120,19 +120,19 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
public void testConstructorClusterNameMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, node,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node,
null, version, clusterStatus, license, usages, clusterStats, clusterState));
}
public void testConstructorVersionMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, node,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node,
clusterName, null, clusterStatus, license, usages, clusterStats, clusterState));
}
public void testConstructorClusterHealthStatusMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, node,
() -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node,
clusterName, version, null, license, usages, clusterStats, clusterState));
}
@ -288,6 +288,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
final ClusterStatsMonitoringDoc doc = new ClusterStatsMonitoringDoc("_cluster",
1502107402133L,
1506593717631L,
node,
clusterName.value(),
"_version",
@ -301,6 +302,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"cluster_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -155,7 +155,9 @@ public class IndexRecoveryCollectorTests extends BaseCollectorTestCase {
assertArrayEquals(Strings.EMPTY_ARRAY, collector.getCollectionIndices());
}
final Collection<MonitoringDoc> results = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final Collection<MonitoringDoc> results = collector.doCollect(node, interval);
verify(indicesAdminClient).prepareRecoveries();
if (nbRecoveries == 0) {
@ -169,6 +171,7 @@ public class IndexRecoveryCollectorTests extends BaseCollectorTestCase {
final IndexRecoveryMonitoringDoc document = (IndexRecoveryMonitoringDoc) monitoringDoc;
assertThat(document.getCluster(), equalTo(clusterUUID));
assertThat(document.getTimestamp(), greaterThan(0L));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getNode(), equalTo(node));
assertThat(document.getSystem(), is(MonitoredSystem.ES));
assertThat(document.getType(), equalTo(IndexRecoveryMonitoringDoc.TYPE));

View File

@ -50,9 +50,9 @@ public class IndexRecoveryMonitoringDocTests extends BaseMonitoringDocTestCase<I
}
@Override
protected IndexRecoveryMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected IndexRecoveryMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new IndexRecoveryMonitoringDoc(cluster, timestamp, node, recoveryResponse);
return new IndexRecoveryMonitoringDoc(cluster, timestamp, interval, node, recoveryResponse);
}
@Override
@ -66,7 +66,7 @@ public class IndexRecoveryMonitoringDocTests extends BaseMonitoringDocTestCase<I
public void testConstructorRecoveryResponseMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new IndexRecoveryMonitoringDoc(cluster, timestamp, node, null));
() -> new IndexRecoveryMonitoringDoc(cluster, timestamp, interval, node, null));
}
@Override
@ -110,12 +110,14 @@ public class IndexRecoveryMonitoringDocTests extends BaseMonitoringDocTestCase<I
final RecoveryResponse recoveryResponse = new RecoveryResponse(10, 7, 3, true, shardRecoveryStates, shardFailures);
final MonitoringDoc.Node node = new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final IndexRecoveryMonitoringDoc document = new IndexRecoveryMonitoringDoc("_cluster", 1502266739402L, node, recoveryResponse);
final IndexRecoveryMonitoringDoc document =
new IndexRecoveryMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, recoveryResponse);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"index_recovery\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -114,7 +114,9 @@ public class IndexStatsCollectorTests extends BaseCollectorTestCase {
final IndexStatsCollector collector = new IndexStatsCollector(Settings.EMPTY, clusterService, licenseState, client);
assertEquals(timeout, collector.getCollectionTimeout());
final Collection<MonitoringDoc> results = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final Collection<MonitoringDoc> results = collector.doCollect(node, interval);
verify(indicesAdminClient).prepareStats();
assertEquals(1 + indices, results.size());
@ -122,6 +124,7 @@ public class IndexStatsCollectorTests extends BaseCollectorTestCase {
for (MonitoringDoc document : results) {
assertThat(document.getCluster(), equalTo(clusterUUID));
assertThat(document.getTimestamp(), greaterThan(0L));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getNode(), equalTo(node));
assertThat(document.getSystem(), is(MonitoredSystem.ES));
assertThat(document.getId(), nullValue());

View File

@ -46,9 +46,9 @@ public class IndexStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestC
}
@Override
protected IndexStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected IndexStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new IndexStatsMonitoringDoc(cluster, timestamp, node, indexStats);
return new IndexStatsMonitoringDoc(cluster, timestamp, interval, node, indexStats);
}
@Override
@ -66,7 +66,7 @@ public class IndexStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestC
}
public void testConstructorIndexStatsMustNotBeNull() {
expectThrows(NullPointerException.class, () -> new IndexStatsMonitoringDoc(cluster, timestamp, node, null));
expectThrows(NullPointerException.class, () -> new IndexStatsMonitoringDoc(cluster, timestamp, interval, node, null));
}
@Override
@ -76,12 +76,13 @@ public class IndexStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestC
when(indexStats.getTotal()).thenReturn(mockCommonStats());
when(indexStats.getPrimaries()).thenReturn(mockCommonStats());
final IndexStatsMonitoringDoc document = new IndexStatsMonitoringDoc("_cluster", 1502266739402L, node, indexStats);
final IndexStatsMonitoringDoc document = new IndexStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, indexStats);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"index_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","
@ -207,12 +208,13 @@ public class IndexStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestC
when(indexStats.getTotal()).thenReturn(null);
when(indexStats.getPrimaries()).thenReturn(null);
final IndexStatsMonitoringDoc document = new IndexStatsMonitoringDoc("_cluster", 1502266739402L, node, indexStats);
final IndexStatsMonitoringDoc document = new IndexStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, indexStats);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"index_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -55,9 +55,9 @@ public class IndicesStatsMonitoringDocTests extends BaseFilteredMonitoringDocTes
}
@Override
protected IndicesStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected IndicesStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new IndicesStatsMonitoringDoc(cluster, timestamp, node, indicesStatsResponse);
return new IndicesStatsMonitoringDoc(cluster, timestamp, interval, node, indicesStatsResponse);
}
@Override
@ -75,7 +75,7 @@ public class IndicesStatsMonitoringDocTests extends BaseFilteredMonitoringDocTes
}
public void testConstructorIndexStatsMustNotBeNull() {
expectThrows(NullPointerException.class, () -> new IndicesStatsMonitoringDoc(cluster, timestamp, node, null));
expectThrows(NullPointerException.class, () -> new IndicesStatsMonitoringDoc(cluster, timestamp, interval, node, null));
}
@Override
@ -91,12 +91,14 @@ public class IndicesStatsMonitoringDocTests extends BaseFilteredMonitoringDocTes
};
final IndicesStatsResponse indicesStatsResponse = newIndicesStatsResponse(shards, -1, -1, -1, emptyList());
final IndicesStatsMonitoringDoc document = new IndicesStatsMonitoringDoc("_cluster", 1502266739402L, node, indicesStatsResponse);
final IndicesStatsMonitoringDoc document =
new IndicesStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, indicesStatsResponse);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"indices_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -139,7 +139,9 @@ public class JobStatsCollectorTests extends BaseCollectorTestCase {
when(client.getJobsStats(eq(new Request(MetaData.ALL)))).thenReturn(future);
when(future.actionGet(timeout)).thenReturn(response);
final List<MonitoringDoc> monitoringDocs = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final List<MonitoringDoc> monitoringDocs = collector.doCollect(node, interval);
assertThat(monitoringDocs, hasSize(jobStats.size()));
@ -149,6 +151,7 @@ public class JobStatsCollectorTests extends BaseCollectorTestCase {
assertThat(jobStatsMonitoringDoc.getCluster(), is(clusterUuid));
assertThat(jobStatsMonitoringDoc.getTimestamp(), greaterThan(0L));
assertThat(jobStatsMonitoringDoc.getIntervalMillis(), equalTo(interval));
assertThat(jobStatsMonitoringDoc.getNode(), equalTo(node));
assertThat(jobStatsMonitoringDoc.getSystem(), is(MonitoredSystem.ES));
assertThat(jobStatsMonitoringDoc.getType(), is(JobStatsMonitoringDoc.TYPE));

View File

@ -46,9 +46,10 @@ public class JobStatsMonitoringDocTests extends BaseMonitoringDocTestCase<JobSta
}
@Override
protected JobStatsMonitoringDoc createMonitoringDoc(final String cluster, final long timestamp, final MonitoringDoc.Node node,
final MonitoredSystem system, final String type, final String id) {
return new JobStatsMonitoringDoc(cluster, timestamp, node, jobStats);
protected JobStatsMonitoringDoc createMonitoringDoc(final String cluster, final long timestamp, long interval,
final MonitoringDoc.Node node, final MonitoredSystem system,
final String type, final String id) {
return new JobStatsMonitoringDoc(cluster, timestamp, interval, node, jobStats);
}
@Override
@ -62,7 +63,7 @@ public class JobStatsMonitoringDocTests extends BaseMonitoringDocTestCase<JobSta
public void testConstructorJobStatsMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new JobStatsMonitoringDoc(cluster, timestamp, node, null));
() -> new JobStatsMonitoringDoc(cluster, timestamp, interval, node, null));
}
@Override
@ -102,12 +103,13 @@ public class JobStatsMonitoringDocTests extends BaseMonitoringDocTestCase<JobSta
final JobStats jobStats = new JobStats("_job", dataCounts, modelStats, JobState.OPENED, discoveryNode, "_explanation", time);
final MonitoringDoc.Node node = new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final JobStatsMonitoringDoc document = new JobStatsMonitoringDoc("_cluster", 1502266739402L, node, jobStats);
final JobStatsMonitoringDoc document = new JobStatsMonitoringDoc("_cluster", 1502266739402L, 1506593717631L, node, jobStats);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"job_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -76,7 +76,8 @@ public class NodeStatsCollectorTests extends BaseCollectorTestCase {
final NodeStatsCollector collector = new NodeStatsCollector(Settings.EMPTY, clusterService, licenseState, client);
assertEquals(timeout, collector.getCollectionTimeout());
final FailedNodeException e = expectThrows(FailedNodeException.class, () -> collector.doCollect(randomMonitoringNode(random())));
final FailedNodeException e = expectThrows(FailedNodeException.class, () ->
collector.doCollect(randomMonitoringNode(random()), randomNonNegativeLong()));
assertEquals(exception, e);
}
@ -109,7 +110,9 @@ public class NodeStatsCollectorTests extends BaseCollectorTestCase {
final NodeStatsCollector collector = new NodeStatsCollector(Settings.EMPTY, clusterService, licenseState, client);
assertEquals(timeout, collector.getCollectionTimeout());
final Collection<MonitoringDoc> results = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final Collection<MonitoringDoc> results = collector.doCollect(node, interval);
assertEquals(1, results.size());
final MonitoringDoc monitoringDoc = results.iterator().next();
@ -118,6 +121,7 @@ public class NodeStatsCollectorTests extends BaseCollectorTestCase {
final NodeStatsMonitoringDoc document = (NodeStatsMonitoringDoc) monitoringDoc;
assertThat(document.getCluster(), equalTo(clusterUUID));
assertThat(document.getTimestamp(), equalTo(timestamp));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getNode(), equalTo(node));
assertThat(document.getSystem(), is(MonitoredSystem.ES));
assertThat(document.getType(), equalTo(NodeStatsMonitoringDoc.TYPE));

View File

@ -64,9 +64,9 @@ public class NodeStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestCa
}
@Override
protected NodeStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected NodeStatsMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new NodeStatsMonitoringDoc(cluster, timestamp, node, nodeId, isMaster, nodeStats, mlockall);
return new NodeStatsMonitoringDoc(cluster, timestamp, interval, node, nodeId, isMaster, nodeStats, mlockall);
}
@Override
@ -88,12 +88,12 @@ public class NodeStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestCa
public void testConstructorNodeIdMustNotBeNull() {
expectThrows(NullPointerException.class, () ->
new NodeStatsMonitoringDoc(cluster, timestamp, node, null, isMaster, nodeStats, mlockall));
new NodeStatsMonitoringDoc(cluster, timestamp, interval, node, null, isMaster, nodeStats, mlockall));
}
public void testConstructorNodeStatsMustNotBeNull() {
expectThrows(NullPointerException.class, () ->
new NodeStatsMonitoringDoc(cluster, timestamp, node, nodeId, isMaster, null, mlockall));
new NodeStatsMonitoringDoc(cluster, timestamp, interval, node, nodeId, isMaster, null, mlockall));
}
@Override
@ -101,12 +101,14 @@ public class NodeStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestCa
final MonitoringDoc.Node node = new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final NodeStats nodeStats = mockNodeStats();
final NodeStatsMonitoringDoc doc = new NodeStatsMonitoringDoc("_cluster", 1502107402133L, node, "_node_id", true, nodeStats, false);
final NodeStatsMonitoringDoc doc =
new NodeStatsMonitoringDoc("_cluster", 1502107402133L, 1506593717631L, node, "_node_id", true, nodeStats, false);
final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"node_stats\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","
@ -326,9 +328,6 @@ public class NodeStatsMonitoringDocTests extends BaseFilteredMonitoringDocTestCa
final FsInfo.IoStats ioStats = new FsInfo.IoStats(new FsInfo.DeviceStats[]{ioStatsTwo});
final FsInfo fs = new FsInfo(no, ioStats, new FsInfo.Path[]{new FsInfo.Path(null, null, ++iota, ++iota, ++iota)});
// TODO: Looks like this filter is not used anymore...
// "node_stats.fs.data.spins",
// Os
final OsStats.Cpu osCpu = new OsStats.Cpu((short) no, new double[]{++iota, ++iota, ++iota});
final OsStats.Cgroup.CpuStat osCpuStat = new OsStats.Cgroup.CpuStat(++iota, ++iota, ++iota);

View File

@ -81,7 +81,7 @@ public class ShardsCollectorTests extends BaseCollectorTestCase {
final ShardsCollector collector = new ShardsCollector(Settings.EMPTY, clusterService, licenseState);
final Collection<MonitoringDoc> results = collector.doCollect(randomMonitoringNode(random()));
final Collection<MonitoringDoc> results = collector.doCollect(randomMonitoringNode(random()), randomNonNegativeLong());
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(0));
verify(clusterService).state();
@ -112,7 +112,9 @@ public class ShardsCollectorTests extends BaseCollectorTestCase {
assertNull(collector.getCollectionTimeout());
assertArrayEquals(indices, collector.getCollectionIndices());
final Collection<MonitoringDoc> results = collector.doCollect(node);
final long interval = randomNonNegativeLong();
final Collection<MonitoringDoc> results = collector.doCollect(node, interval);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo((indices != NONE) ? routingTable.allShards().size() : 0));
@ -123,6 +125,7 @@ public class ShardsCollectorTests extends BaseCollectorTestCase {
final ShardMonitoringDoc document = (ShardMonitoringDoc) monitoringDoc;
assertThat(document.getCluster(), equalTo(clusterUUID));
assertThat(document.getTimestamp(), greaterThan(0L));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getSystem(), is(MonitoredSystem.ES));
assertThat(document.getType(), equalTo(ShardMonitoringDoc.TYPE));
assertThat(document.getId(), equalTo(ShardMonitoringDoc.id(stateUUID, document.getShardRouting())));

View File

@ -46,9 +46,9 @@ public class ShardsMonitoringDocTests extends BaseFilteredMonitoringDocTestCase<
}
@Override
protected ShardMonitoringDoc createMonitoringDoc(String cluster, long timestamp, MonitoringDoc.Node node,
protected ShardMonitoringDoc createMonitoringDoc(String cluster, long timestamp, long interval, MonitoringDoc.Node node,
MonitoredSystem system, String type, String id) {
return new ShardMonitoringDoc(cluster, timestamp, node, shardRouting, stateUuid);
return new ShardMonitoringDoc(cluster, timestamp, interval, node, shardRouting, stateUuid);
}
@Override
@ -72,11 +72,11 @@ public class ShardsMonitoringDocTests extends BaseFilteredMonitoringDocTestCase<
}
public void testConstructorShardRoutingMustNotBeNull() {
expectThrows(NullPointerException.class, () -> new ShardMonitoringDoc(cluster, timestamp, node, null, stateUuid));
expectThrows(NullPointerException.class, () -> new ShardMonitoringDoc(cluster, timestamp, interval, node, null, stateUuid));
}
public void testConstructorStateUuidMustNotBeNull() {
expectThrows(NullPointerException.class, () -> new ShardMonitoringDoc(cluster, timestamp, node, shardRouting, null));
expectThrows(NullPointerException.class, () -> new ShardMonitoringDoc(cluster, timestamp, interval, node, shardRouting, null));
}
public void testIdWithPrimaryShardAssigned() {
@ -103,12 +103,14 @@ public class ShardsMonitoringDocTests extends BaseFilteredMonitoringDocTestCase<
public void testToXContent() throws IOException {
final ShardRouting shardRouting = newShardRouting("_index", 1, "_index_uuid", "_node_uuid", true, INITIALIZING);
final MonitoringDoc.Node node = new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final ShardMonitoringDoc doc = new ShardMonitoringDoc("_cluster", 1502107402133L, node, shardRouting, "_state_uuid");
final ShardMonitoringDoc doc =
new ShardMonitoringDoc("_cluster", 1502107402133L, 1506593717631L, node, shardRouting, "_state_uuid");
final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, randomBoolean());
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-07T12:03:22.133Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"shards\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","

View File

@ -56,12 +56,13 @@ public abstract class BaseFilteredMonitoringDocTestCase<F extends FilteredMonito
}
public void testConstructorFiltersMustNotBeNull() {
expectThrows(NullPointerException.class, () -> new TestFilteredMonitoringDoc(cluster, timestamp, node, system, type, id, null));
expectThrows(NullPointerException.class,
() -> new TestFilteredMonitoringDoc(cluster, timestamp, interval, node, system, type, id, null));
}
public void testConstructorFiltersMustNotBeEmpty() {
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> new TestFilteredMonitoringDoc(cluster, timestamp, node, system, type, id, emptySet()));
() -> new TestFilteredMonitoringDoc(cluster, timestamp, interval, node, system, type, id, emptySet()));
assertThat(e.getMessage(), equalTo("xContentFilters must not be empty"));
}
@ -74,13 +75,14 @@ public abstract class BaseFilteredMonitoringDocTestCase<F extends FilteredMonito
final MonitoringDoc.Node node =
new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final TestFilteredMonitoringDoc document =
new TestFilteredMonitoringDoc("_cluster", 1502266739402L, node, MonitoredSystem.ES, "_type", "_id", filters);
final TestFilteredMonitoringDoc document = new TestFilteredMonitoringDoc("_cluster", 1502266739402L, 1506593717631L,
node, MonitoredSystem.ES, "_type", "_id", filters);
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"_type\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","
@ -106,12 +108,13 @@ public abstract class BaseFilteredMonitoringDocTestCase<F extends FilteredMonito
TestFilteredMonitoringDoc(final String cluster,
final long timestamp,
final long intervalMillis,
final Node node,
final MonitoredSystem system,
final String type,
final String id,
final Set<String> xContentFilters) {
super(cluster, timestamp, node, system, type, id, xContentFilters);
super(cluster, timestamp, intervalMillis, node, system, type, id, xContentFilters);
}
@Override

View File

@ -49,6 +49,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
protected String cluster;
protected long timestamp;
protected long interval;
protected MonitoringDoc.Node node;
protected MonitoredSystem system;
protected String type;
@ -60,6 +61,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
super.setUp();
cluster = UUIDs.randomBase64UUID();
timestamp = frequently() ? randomNonNegativeLong() : 0L;
interval = randomNonNegativeLong();
node = frequently() ? MonitoringTestUtils.randomMonitoringNode(random()) : null;
system = randomFrom(MonitoredSystem.values());
type = randomAlphaOfLength(5);
@ -73,6 +75,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
*/
protected abstract T createMonitoringDoc(String cluster,
long timestamp,
long interval,
@Nullable MonitoringDoc.Node node,
MonitoredSystem system,
String type,
@ -95,8 +98,8 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
public final void testCreateMonitoringDoc() throws IOException {
final int nbIterations = randomIntBetween(3, 20);
for (int i = 0; i < nbIterations; i++) {
final T document1 = createMonitoringDoc(cluster, timestamp, node, system, type, id);
final T document2 = createMonitoringDoc(cluster, timestamp, node, system, type, id);
final T document1 = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id);
final T document2 = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id);
assertNotSame(document1, document2);
assertMonitoringDocEquals(document1, document2);
@ -104,14 +107,15 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
}
public final void testConstructorClusterMustNotBeNull() {
expectThrows(NullPointerException.class, () -> createMonitoringDoc(null, timestamp, node, system, type, id));
expectThrows(NullPointerException.class, () -> createMonitoringDoc(null, timestamp, interval, node, system, type, id));
}
public final void testConstructor() {
final T document = createMonitoringDoc(cluster, timestamp, node, system, type, id);
final T document = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id);
assertThat(document.getCluster(), equalTo(cluster));
assertThat(document.getTimestamp(), equalTo(timestamp));
assertThat(document.getIntervalMillis(), equalTo(interval));
assertThat(document.getNode(), equalTo(node));
assertMonitoringDoc(document);
@ -131,7 +135,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
*/
public final void testToXContentContainsCommonFields() throws IOException {
final XContentType xContentType = randomFrom(XContentType.values());
final T document = createMonitoringDoc(cluster, timestamp, node, system, type, id);
final T document = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id);
final BytesReference bytes = XContentHelper.toXContent(document, xContentType, false);
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, bytes)) {
@ -139,6 +143,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
assertThat(map.get("cluster_uuid"), equalTo(cluster));
assertThat(map.get("timestamp"), equalTo(MonitoringDoc.toUTC(timestamp)));
assertThat(map.get("interval_ms"), equalTo(document.getIntervalMillis()));
assertThat(map.get("type"), equalTo(document.getType()));
if (document.getType().equals(ShardMonitoringDoc.TYPE)) {
@ -267,7 +272,7 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
}
public void testMonitoringNodeBwcSerialization() throws IOException {
final Version version = randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_1_0);
final Version version = randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_0_0_beta2);
final byte[] data = Base64.getDecoder()
.decode("AQVFSWJKdgEDdFFOAQV3cGtMagEFa2xqeWEBBVZTamF2AwVrZXkjMgEyBWtleSMxATEFa2V5IzABMAAAAAAAAA==");

View File

@ -41,9 +41,10 @@ public class BytesReferenceMonitoringDocTests extends BaseMonitoringDocTestCase<
}
@Override
protected BytesReferenceMonitoringDoc createMonitoringDoc(final String cluster, final long timestamp, final MonitoringDoc.Node node,
protected BytesReferenceMonitoringDoc createMonitoringDoc(final String cluster, final long timestamp, final long intervalMillis,
final MonitoringDoc.Node node,
final MonitoredSystem system, final String type, final String id) {
return new BytesReferenceMonitoringDoc(cluster, timestamp, node, system, type, id, xContentType, source);
return new BytesReferenceMonitoringDoc(cluster, timestamp, intervalMillis, node, system, type, id, xContentType, source);
}
@Override
@ -58,22 +59,22 @@ public class BytesReferenceMonitoringDocTests extends BaseMonitoringDocTestCase<
public void testConstructorMonitoredSystemMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, node, null, type, id, xContentType, source));
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, interval, node, null, type, id, xContentType, source));
}
public void testConstructorTypeMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, node, system, null, id, xContentType, source));
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, interval, node, system, null, id, xContentType, source));
}
public void testConstructorXContentTypeMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, node, system, type, id, null, source));
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, interval, node, system, type, id, null, source));
}
public void testConstructorSourceMustNotBeNull() {
expectThrows(NullPointerException.class,
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, node, system, type, id, xContentType, null));
() -> new BytesReferenceMonitoringDoc(cluster, timestamp, interval, node, system, type, id, xContentType, null));
}
@Override
@ -85,13 +86,14 @@ public class BytesReferenceMonitoringDocTests extends BaseMonitoringDocTestCase<
final MonitoringDoc.Node node =
new MonitoringDoc.Node("_uuid", "_host", "_addr", "_ip", "_name", 1504169190855L);
final BytesReferenceMonitoringDoc document =
new BytesReferenceMonitoringDoc("_cluster", 1502266739402L, node, KIBANA, "_type", "_id", xContentType, builder.bytes());
final BytesReferenceMonitoringDoc document = new BytesReferenceMonitoringDoc("_cluster", 1502266739402L, 1506593717631L,
node, KIBANA, "_type", "_id", xContentType, builder.bytes());
final BytesReference xContent = XContentHelper.toXContent(document, XContentType.JSON, false);
assertEquals("{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":\"2017-08-09T08:18:59.402Z\","
+ "\"interval_ms\":1506593717631,"
+ "\"type\":\"_type\","
+ "\"source_node\":{"
+ "\"uuid\":\"_uuid\","
@ -109,7 +111,8 @@ public class BytesReferenceMonitoringDocTests extends BaseMonitoringDocTestCase<
public void testEqualsAndHashcode() {
final EqualsHashCodeTestUtils.CopyFunction<MonitoringDoc> copy = doc ->
createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
final List<EqualsHashCodeTestUtils.MutateFunction<MonitoringDoc>> mutations = new ArrayList<>();
mutations.add(doc -> {
@ -117,44 +120,58 @@ public class BytesReferenceMonitoringDocTests extends BaseMonitoringDocTestCase<
do {
cluster = UUIDs.randomBase64UUID();
} while (cluster.equals(doc.getCluster()));
return createMonitoringDoc(cluster, doc.getTimestamp(), doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
return createMonitoringDoc(cluster, doc.getTimestamp(), doc.getIntervalMillis(),
doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
});
mutations.add(doc -> {
long timestamp;
do {
timestamp = randomNonNegativeLong();
} while (timestamp == doc.getTimestamp());
return createMonitoringDoc(doc.getCluster(), timestamp, doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
return createMonitoringDoc(doc.getCluster(), timestamp, doc.getIntervalMillis(),
doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
});
mutations.add(doc -> {
long intervaMillis;
do {
intervaMillis = randomNonNegativeLong();
} while (intervaMillis == doc.getIntervalMillis());
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), intervaMillis,
doc.getNode(), doc.getSystem(), doc.getType(), doc.getId());
});
mutations.add(doc -> {
MonitoringDoc.Node node;
do {
node = MonitoringTestUtils.randomMonitoringNode(random());
} while (node.equals(doc.getNode()));
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), node, doc.getSystem(), doc.getType(), doc.getId());
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getIntervalMillis(),
node, doc.getSystem(), doc.getType(), doc.getId());
});
mutations.add(doc -> {
MonitoredSystem system;
do {
system = randomFrom(MonitoredSystem.values());
} while (system == doc.getSystem());
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getNode(), system, doc.getType(), doc.getId());
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getNode(), system, doc.getType(), doc.getId());
});
mutations.add(doc -> {
String type;
do {
type = randomAlphaOfLength(5);
} while (type.equals(doc.getType()));
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getNode(), doc.getSystem(), type, doc.getId());
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getNode(), doc.getSystem(), type, doc.getId());
});
mutations.add(doc -> {
String id;
do {
id = randomAlphaOfLength(10);
} while (id.equals(doc.getId()));
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getNode(), doc.getSystem(), doc.getType(), id);
return createMonitoringDoc(doc.getCluster(), doc.getTimestamp(), doc.getIntervalMillis(),
doc.getNode(), doc.getSystem(), doc.getType(), id);
});
checkEqualsAndHashCode(createMonitoringDoc(cluster, timestamp, node, system, type, id), copy, randomFrom(mutations));
checkEqualsAndHashCode(createMonitoringDoc(cluster, timestamp, interval, node, system, type, id), copy, randomFrom(mutations));
}
}

View File

@ -267,8 +267,8 @@ 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 TestMonitoringDoc(randomAlphaOfLength(5), randomNonNegativeLong(), null, MonitoredSystem.ES,
randomAlphaOfLength(5), null, String.valueOf(n)));
docs.add(new TestMonitoringDoc(randomAlphaOfLength(5), randomNonNegativeLong(), randomNonNegativeLong(),
null, MonitoredSystem.ES, randomAlphaOfLength(5), null, String.valueOf(n)));
}
barrier.await(10, TimeUnit.SECONDS);
exporters.export(docs, ActionListener.wrap(
@ -395,8 +395,9 @@ public class ExportersTests extends ESTestCase {
private final String value;
TestMonitoringDoc(String cluster, long timestamp, Node node, MonitoredSystem system, String type, String id, String value) {
super(cluster, timestamp, node, system, type, id);
TestMonitoringDoc(String cluster, long timestamp, long interval,
Node node, MonitoredSystem system, String type, String id, String value) {
super(cluster, timestamp, interval, node, system, type, id);
this.value = value;
}

View File

@ -605,9 +605,10 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
private MonitoringDoc newRandomMonitoringDoc() {
String clusterUUID = internalCluster().getClusterName();
long timestamp = System.currentTimeMillis();
long intervalMillis = randomNonNegativeLong();
MonitoringDoc.Node sourceNode = MonitoringTestUtils.randomMonitoringNode(random());
return new IndexRecoveryMonitoringDoc(clusterUUID, timestamp, sourceNode, new RecoveryResponse());
return new IndexRecoveryMonitoringDoc(clusterUUID, timestamp, intervalMillis, sourceNode, new RecoveryResponse());
}
private List<MonitoringDoc> newRandomMonitoringDocs(int nb) {

View File

@ -19,6 +19,7 @@ import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
@ -67,6 +68,8 @@ public class MonitoringIT extends ESRestTestCase {
private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", TEST_PASSWORD_SECURE_STRING);
private final TimeValue collectionInterval = TimeValue.timeValueSeconds(3);
@Override
protected Settings restClientSettings() {
return Settings.builder()
@ -140,11 +143,12 @@ public class MonitoringIT extends ESRestTestCase {
public void testMonitoringBulk() throws Exception {
whenExportersAreReady(() -> {
final MonitoredSystem system = randomSystem();
final String interval = randomIntBetween(1, 20) + "s";
final TimeValue interval = TimeValue.timeValueSeconds(randomIntBetween(1, 20));
// Use Monitoring Bulk API to index 3 documents
Response bulkResponse = client().performRequest("POST", "/_xpack/monitoring/_bulk",
parameters(system.getSystem(), TEMPLATE_VERSION, interval), createBulkEntity());
parameters(system.getSystem(), TEMPLATE_VERSION, interval.getStringRep()),
createBulkEntity());
assertThat(bulkResponse.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_OK));
assertThat(toMap(bulkResponse.getEntity()).get("errors"), equalTo(false));
@ -172,7 +176,7 @@ public class MonitoringIT extends ESRestTestCase {
1, searchHits.stream().map(map -> extractValue("_source.source_node.timestamp", map)).distinct().count());
for (Map<String,Object> searchHit : searchHits) {
assertMonitoringDoc(searchHit, system, "test");
assertMonitoringDoc(searchHit, system, "test", interval);
}
});
}
@ -204,17 +208,17 @@ public class MonitoringIT extends ESRestTestCase {
final String type = (String) extractValue("_source.type", searchHit);
if (ClusterStatsMonitoringDoc.TYPE.equals(type)) {
assertClusterStatsMonitoringDoc(searchHit);
assertClusterStatsMonitoringDoc(searchHit, collectionInterval);
} else if (IndexRecoveryMonitoringDoc.TYPE.equals(type)) {
assertIndexRecoveryMonitoringDoc(searchHit);
assertIndexRecoveryMonitoringDoc(searchHit, collectionInterval);
} else if (IndicesStatsMonitoringDoc.TYPE.equals(type)) {
assertIndicesStatsMonitoringDoc(searchHit);
assertIndicesStatsMonitoringDoc(searchHit, collectionInterval);
} else if (IndexStatsMonitoringDoc.TYPE.equals(type)) {
assertIndexStatsMonitoringDoc(searchHit);
assertIndexStatsMonitoringDoc(searchHit, collectionInterval);
} else if (NodeStatsMonitoringDoc.TYPE.equals(type)) {
assertNodeStatsMonitoringDoc(searchHit);
assertNodeStatsMonitoringDoc(searchHit, collectionInterval);
} else if (ShardMonitoringDoc.TYPE.equals(type)) {
assertShardMonitoringDoc(searchHit);
assertShardMonitoringDoc(searchHit, collectionInterval);
} else {
fail("Monitoring document of type [" + type + "] is not supported by this test");
}
@ -229,7 +233,8 @@ public class MonitoringIT extends ESRestTestCase {
@SuppressWarnings("unchecked")
private static void assertMonitoringDoc(final Map<String, Object> document,
final MonitoredSystem expectedSystem,
final String expectedType) throws Exception {
final String expectedType,
final TimeValue interval) throws Exception {
assertEquals(5, document.size());
final String index = (String) document.get("_index");
@ -245,6 +250,8 @@ public class MonitoringIT extends ESRestTestCase {
final String timestamp = (String) source.get("timestamp");
assertThat(timestamp, not(isEmptyOrNullString()));
assertThat(((Number) source.get("interval_ms")).longValue(), equalTo(interval.getMillis()));
assertThat(index, equalTo(MonitoringTemplateUtils.indexName(DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(),
expectedSystem,
ISODateTimeFormat.dateTime().parseMillis(timestamp))));
@ -286,11 +293,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link ClusterStatsMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertClusterStatsMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, ClusterStatsMonitoringDoc.TYPE);
private static void assertClusterStatsMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, ClusterStatsMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(10, source.size());
assertEquals(11, source.size());
assertThat((String) source.get("cluster_name"), not(isEmptyOrNullString()));
assertThat(source.get("version"), equalTo(Version.CURRENT.toString()));
@ -349,11 +356,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link IndexRecoveryMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertIndexRecoveryMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndexRecoveryMonitoringDoc.TYPE);
private static void assertIndexRecoveryMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndexRecoveryMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(5, source.size());
assertEquals(6, source.size());
final Map<String, Object> indexRecovery = (Map<String, Object>) source.get(IndexRecoveryMonitoringDoc.TYPE);
assertEquals(1, indexRecovery.size());
@ -366,11 +373,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link IndicesStatsMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertIndicesStatsMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndicesStatsMonitoringDoc.TYPE);
private static void assertIndicesStatsMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndicesStatsMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(5, source.size());
assertEquals(6, source.size());
final Map<String, Object> indicesStats = (Map<String, Object>) source.get(IndicesStatsMonitoringDoc.TYPE);
assertEquals(1, indicesStats.size());
@ -383,11 +390,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link IndexStatsMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertIndexStatsMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndexStatsMonitoringDoc.TYPE);
private static void assertIndexStatsMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, IndexStatsMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(5, source.size());
assertEquals(6, source.size());
final Map<String, Object> indexStats = (Map<String, Object>) source.get(IndexStatsMonitoringDoc.TYPE);
assertEquals(3, indexStats.size());
@ -403,11 +410,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link NodeStatsMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertNodeStatsMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, NodeStatsMonitoringDoc.TYPE);
private static void assertNodeStatsMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, NodeStatsMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(5, source.size());
assertEquals(6, source.size());
NodeStatsMonitoringDoc.XCONTENT_FILTERS.forEach(filter -> {
if (Constants.WINDOWS && filter.startsWith("node_stats.os.cpu.load_average")) {
@ -434,11 +441,11 @@ public class MonitoringIT extends ESRestTestCase {
* Assert that a {@link ShardMonitoringDoc} contains the expected information
*/
@SuppressWarnings("unchecked")
private static void assertShardMonitoringDoc(final Map<String, Object> document) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, ShardMonitoringDoc.TYPE);
private static void assertShardMonitoringDoc(final Map<String, Object> document, final TimeValue interval) throws Exception {
assertMonitoringDoc(document, MonitoredSystem.ES, ShardMonitoringDoc.TYPE, interval);
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(6, source.size());
assertEquals(7, source.size());
assertThat(source.get("state_uuid"), notNullValue());
final Map<String, Object> shard = (Map<String, Object>) source.get("shard");
@ -470,9 +477,9 @@ public class MonitoringIT extends ESRestTestCase {
* Executes the given {@link Runnable} once the monitoring exporters are ready and functional. Ensure that
* the exporters and the monitoring service are shut down after the runnable has been executed.
*/
private static void whenExportersAreReady(final CheckedRunnable<Exception> runnable) throws Exception {
private void whenExportersAreReady(final CheckedRunnable<Exception> runnable) throws Exception {
try {
enableMonitoring();
enableMonitoring(collectionInterval);
runnable.run();
} finally {
disableMonitoring();
@ -483,14 +490,14 @@ public class MonitoringIT extends ESRestTestCase {
* Enable the monitoring service and the Local exporter, waiting for some monitoring documents
* to be indexed before it returns.
*/
public static void enableMonitoring() throws Exception {
public static void enableMonitoring(final TimeValue interval) throws Exception {
final Map<String, Object> exporters = callRestApi("GET", "/_xpack/usage?filter_path=monitoring.enabled_exporters", 200);
assertNotNull("List of monitoring exporters must not be null", exporters);
assertThat("List of enabled exporters must be empty before enabling monitoring",
XContentMapValues.extractRawValues("monitoring.enabled_exporters", exporters), hasSize(0));
final Settings settings = Settings.builder()
.put("transient.xpack.monitoring.collection.interval", "3s")
.put("transient.xpack.monitoring.collection.interval", interval.getStringRep())
.put("transient.xpack.monitoring.exporters._local.enabled", true)
.build();

View File

@ -40,7 +40,7 @@
xpack.monitoring.bulk:
system_id: "kibana"
system_api_version: "6"
interval: "10000ms"
interval: "123456ms"
type: "default_type"
body:
- '{"index": {}}'
@ -63,6 +63,8 @@
body: { "query": { "term" : { "type": "default_type" } } }
- match: { hits.total: 2 }
- match: { hits.hits.0._source.interval_ms: 123456 }
- match: { hits.hits.1._source.interval_ms: 123456 }
- do:
search:
@ -70,6 +72,7 @@
body: { "query": { "term" : { "type": "custom_type" } } }
- match: { hits.total: 1 }
- match: { hits.hits.0._source.interval_ms: 123456 }
# We actively ignore indexing requests made to the _data index starting with 5.5
- do: