Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public RestNoopBulkAction(Settings settings, RestController controller) {
controller.registerHandler(PUT, "/{index}/{type}/_noop_bulk", this);
}

@Override
public String getName() {
return "noop_bulk_action";
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
BulkRequest bulkRequest = Requests.bulkRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public RestNoopSearchAction(Settings settings, RestController controller) {
controller.registerHandler(POST, "/{index}/{type}/_noop_search", this);
}

@Override
public String getName() {
return "noop_search_action";
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
SearchRequest searchRequest = new SearchRequest();
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.elasticsearch.action.admin.cluster.node.tasks.get.TransportGetTaskAction;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
import org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.TransportNodesUsageAction;
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoAction;
import org.elasticsearch.action.admin.cluster.remote.TransportRemoteInfoAction;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction;
Expand Down Expand Up @@ -234,6 +236,7 @@
import org.elasticsearch.rest.action.admin.cluster.RestNodesHotThreadsAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesInfoAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction;
Expand Down Expand Up @@ -310,6 +313,7 @@
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.usage.UsageService;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -346,7 +350,7 @@ public class ActionModule extends AbstractModule {
public ActionModule(boolean transportClient, Settings settings, IndexNameExpressionResolver indexNameExpressionResolver,
IndexScopedSettings indexScopedSettings, ClusterSettings clusterSettings, SettingsFilter settingsFilter,
ThreadPool threadPool, List<ActionPlugin> actionPlugins, NodeClient nodeClient,
CircuitBreakerService circuitBreakerService) {
CircuitBreakerService circuitBreakerService, UsageService usageService) {
this.transportClient = transportClient;
this.settings = settings;
this.indexNameExpressionResolver = indexNameExpressionResolver;
Expand All @@ -373,7 +377,7 @@ public ActionModule(boolean transportClient, Settings settings, IndexNameExpress
if (transportClient) {
restController = null;
} else {
restController = new RestController(settings, headers, restWrapper, nodeClient, circuitBreakerService);
restController = new RestController(settings, headers, restWrapper, nodeClient, circuitBreakerService, usageService);
}
}

Expand Down Expand Up @@ -405,6 +409,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class);
actions.register(RemoteInfoAction.INSTANCE, TransportRemoteInfoAction.class);
actions.register(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class);
actions.register(NodesUsageAction.INSTANCE, TransportNodesUsageAction.class);
actions.register(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class);
actions.register(ListTasksAction.INSTANCE, TransportListTasksAction.class);
actions.register(GetTaskAction.INSTANCE, TransportGetTaskAction.class);
Expand Down Expand Up @@ -515,6 +520,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestNodesInfoAction(settings, restController, settingsFilter));
registerHandler.accept(new RestRemoteClusterInfoAction(settings, restController));
registerHandler.accept(new RestNodesStatsAction(settings, restController));
registerHandler.accept(new RestNodesUsageAction(settings, restController));
registerHandler.accept(new RestNodesHotThreadsAction(settings, restController));
registerHandler.accept(new RestClusterAllocationExplainAction(settings, restController));
registerHandler.accept(new RestClusterStatsAction(settings, restController));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.node.usage;

import org.elasticsearch.action.support.nodes.BaseNodeResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

public class NodeUsage extends BaseNodeResponse implements ToXContent {

private long timestamp;
private long sinceTime;
private Map<String, Long> restUsage;

NodeUsage() {
}

public static NodeUsage readNodeStats(StreamInput in) throws IOException {
NodeUsage nodeInfo = new NodeUsage();
nodeInfo.readFrom(in);
return nodeInfo;
}

/**
* @param node
* the node these statistics were collected from
* @param timestamp
* the timestamp for when these statistics were collected
* @param sinceTime
* the timestamp for when the collection of these statistics
* started
* @param restUsage
* a map containing the counts of the number of times each REST
* endpoint has been called
*/
public NodeUsage(DiscoveryNode node, long timestamp, long sinceTime, Map<String, Long> restUsage) {
super(node);
this.timestamp = timestamp;
this.sinceTime = sinceTime;
this.restUsage = restUsage;
}

/**
* @return the timestamp for when these statistics were collected
*/
public long getTimestamp() {
return timestamp;
}

/**
* @return the timestamp for when the collection of these statistics started
*/
public long getSinceTime() {
return sinceTime;
}

/**
* @return a map containing the counts of the number of times each REST
* endpoint has been called
*/
public Map<String, Long> getRestUsage() {
return restUsage;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("since", sinceTime);
if (restUsage != null) {
builder.field("rest_actions");
builder.map(restUsage);
}
return builder;
}

@SuppressWarnings("unchecked")
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
timestamp = in.readLong();
sinceTime = in.readLong();
restUsage = (Map<String, Long>) in.readGenericValue();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(timestamp);
out.writeLong(sinceTime);
out.writeGenericValue(restUsage);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.node.usage;

import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;

public class NodesUsageAction extends Action<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> {

public static final NodesUsageAction INSTANCE = new NodesUsageAction();
public static final String NAME = "cluster:monitor/nodes/usage";

protected NodesUsageAction() {
super(NAME);
}

@Override
public NodesUsageRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new NodesUsageRequestBuilder(client, this);
}

@Override
public NodesUsageResponse newResponse() {
return new NodesUsageResponse();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.node.usage;

import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class NodesUsageRequest extends BaseNodesRequest<NodesUsageRequest> {

private boolean restActions;

public NodesUsageRequest() {
super();
}

/**
* Get usage from nodes based on the nodes ids specified. If none are
* passed, usage for all nodes will be returned.
*/
public NodesUsageRequest(String... nodesIds) {
super(nodesIds);
}

/**
* Sets all the request flags.
*/
public NodesUsageRequest all() {
this.restActions = true;
return this;
}

/**
* Clears all the request flags.
*/
public NodesUsageRequest clear() {
this.restActions = false;
return this;
}

/**
* Should the node rest actions usage statistics be returned.
*/
public boolean restActions() {
return this.restActions;
}

/**
* Should the node rest actions usage statistics be returned.
*/
public NodesUsageRequest restActions(boolean restActions) {
this.restActions = restActions;
return this;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
this.restActions = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(restActions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@
* under the License.
*/

/**
* Infrastructure for actions that modify documents based on the results of a scrolling query
* like reindex, update by query or delete by query.
*/
package org.elasticsearch.index.reindex;
package org.elasticsearch.action.admin.cluster.node.usage;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;

public class NodesUsageRequestBuilder
extends NodesOperationRequestBuilder<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> {

public NodesUsageRequestBuilder(ElasticsearchClient client,
Action<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> action) {
super(client, action, new NodesUsageRequest());
}

}
Loading