- Notifications
You must be signed in to change notification settings - Fork 25.6k
New HTTP info (/_info/http) endpoint #96198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits Select commit Hold shift + click to select a range
74f6e1f new simple endpoint exposing http stats
8f98cf7 add rest api spec for http.stats
b5ea1ad test new http.stats endpoint
50f89ac add documentation
ca86477 Update docs/changelog/96198.yaml
HiDAl 756170f Update docs/changelog/96198.yaml
HiDAl 34a6b3b fix min test version
7131af1 add new doc to the sidebar
634b4f6 rename from `stats` to `info`
9633b3c reword doc
a2a39cc add some tests to httpStats
223fe18 add tests to RestHttpInfoAction
4ddb7ef Merge remote-tracking branch 'elastic/main' into new-http-stats
88f1906 fix wording on documentation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 96198 | ||
| summary: New HTTP info endpoint | ||
| area: Stats | ||
| type: feature | ||
| issues: | ||
| - 95391 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| [[cluster-info-http]] | ||
| === Cluster Info HTTP API | ||
| ++++ | ||
| <titleabbrev>Cluster HTTP Info</titleabbrev> | ||
| ++++ | ||
| | ||
| Returns cluster HTTP information. | ||
| | ||
| [[cluster-info-http-api-request]] | ||
| ==== {api-request-title} | ||
| | ||
| `GET /_info/http` + | ||
| | ||
| [[cluster-info-http-api-prereqs]] | ||
| ==== {api-prereq-title} | ||
| | ||
| * If the {es} {security-features} are enabled, you must have the `monitor` or | ||
| `manage` <<privileges-list-cluster,cluster privilege>> to use this API. | ||
| | ||
| | ||
| [[cluster-info-http-api-desc]] | ||
| ==== {api-description-title} | ||
| | ||
| You can use the Cluster Info HTTP API to retrieve http information in a cluster. | ||
| | ||
| [role="child_attributes"] | ||
| [[cluster-info-http-api-response-body]] | ||
| ==== {api-response-body-title} | ||
| | ||
| `cluster_name`:: | ||
| (string) | ||
| Name of the cluster. Based on the <<cluster-name>> setting. | ||
| | ||
| | ||
| [[cluster-info-http-api-response-body-http]] | ||
| `http`:: | ||
| (object) | ||
| Contains http statistics for the cluster. | ||
| + | ||
| .Properties of `http` | ||
| [%collapsible%open] | ||
| ====== | ||
| `current_open`:: | ||
| (integer) | ||
| Current number of open HTTP connections for the cluster. | ||
| | ||
| `total_opened`:: | ||
| (integer) | ||
| Total number of HTTP connections opened for the cluster. | ||
| | ||
| `clients`:: | ||
| (array of objects) | ||
| Information on current and recently-closed HTTP client connections. | ||
| Clients that have been closed longer than the <<http-settings,http.client_stats.closed_channels.max_age>> | ||
| setting will not be represented here. | ||
| + | ||
| .Properties of `clients` | ||
| [%collapsible%open] | ||
| ======= | ||
| `id`:: | ||
| (integer) | ||
| Unique ID for the HTTP client. | ||
| | ||
| `agent`:: | ||
| (string) | ||
| Reported agent for the HTTP client. If unavailable, this property is not | ||
| included in the response. | ||
| | ||
| `local_address`:: | ||
| (string) | ||
| Local address for the HTTP connection. | ||
| | ||
| `remote_address`:: | ||
| (string) | ||
| Remote address for the HTTP connection. | ||
| | ||
| `last_uri`:: | ||
| (string) | ||
| The URI of the client's most recent request. | ||
| | ||
| `x_forwarded_for`:: | ||
| (string) | ||
| Value from the client's `x-forwarded-for` HTTP header. If unavailable, this | ||
| property is not included in the response. | ||
| | ||
| `x_opaque_id`:: | ||
| (string) | ||
| Value from the client's `x-opaque-id` HTTP header. If unavailable, this property | ||
| is not included in the response. | ||
| | ||
| `opened_time_millis`:: | ||
| (integer) | ||
| Time at which the client opened the connection. | ||
| | ||
| `closed_time_millis`:: | ||
| (integer) | ||
| Time at which the client closed the connection if the connection is closed. | ||
| | ||
| `last_request_time_millis`:: | ||
| (integer) | ||
| Time of the most recent request from this client. | ||
| | ||
| `request_count`:: | ||
| (integer) | ||
| Number of requests from this client. | ||
| | ||
| `request_size_bytes`:: | ||
| (integer) | ||
| Cumulative size in bytes of all requests from this client. | ||
| ======= | ||
| ====== | ||
| | ||
| | ||
| [[cluster-info-http-api-example]] | ||
| ==== {api-examples-title} | ||
| | ||
| [source,console] | ||
| ---- | ||
| # returns the http info of the cluster | ||
| GET /_info/http | ||
| ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions 22 rest-api-spec/src/main/resources/rest-api-spec/api/info.http.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "info.http": { | ||
| "documentation": { | ||
| "url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-info-http.html", | ||
| "description": "Returns statistical information about http status in the cluster." | ||
| }, | ||
| "stability": "stable", | ||
| "visibility": "public", | ||
| "headers": { | ||
| "accept": ["application/json"] | ||
| }, | ||
| "url": { | ||
| "paths": [ | ||
| { | ||
| "path": "/_info/http", | ||
| "methods": ["GET"] | ||
| } | ||
| ] | ||
| }, | ||
| "params": {} | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions 24 rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/info.http/10_info_http.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| "HTTP Stats": | ||
| - skip: | ||
| version: " - 8.8.99" | ||
| reason: "/_info/http only available from v8.9" | ||
| | ||
| - do: | ||
| info.http: {} | ||
| | ||
| - is_true: cluster_name | ||
| - gte: { http.current_open: 0 } | ||
| - gte: { http.total_opened: 1 } | ||
| - is_true: http.clients | ||
| - gte: { http.clients.0.id: 1 } | ||
| - match: { http.clients.0.agent: "/.*/" } | ||
| - match: { http.clients.0.local_address: "/.*/" } | ||
| - match: { http.clients.0.remote_address: "/.*/" } | ||
| - is_true: http.clients.0.last_uri | ||
| - gte: { http.clients.0.opened_time_millis: 1684328268000 } # 2023-05-17 | ||
| - gte: { http.clients.0.last_request_time_millis: 1684328268000 } | ||
| - gte: { http.clients.0.request_count: 1 } | ||
| - gte: { http.clients.0.request_size_bytes: 0 } | ||
| # values for clients.0.closed_time_millis, clients.0.x_forwarded_for, and clients.0.x_opaque_id are often | ||
| # null and cannot be tested here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions 57 server/src/main/java/org/elasticsearch/rest/action/info/AbstractInfoAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
| | ||
| package org.elasticsearch.rest.action.info; | ||
| | ||
| import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; | ||
| import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; | ||
| import org.elasticsearch.client.internal.node.NodeClient; | ||
| import org.elasticsearch.common.collect.Iterators; | ||
| import org.elasticsearch.common.xcontent.ChunkedToXContent; | ||
| import org.elasticsearch.common.xcontent.ChunkedToXContentHelper; | ||
| import org.elasticsearch.rest.BaseRestHandler; | ||
| import org.elasticsearch.rest.ChunkedRestResponseBody; | ||
| import org.elasticsearch.rest.RestRequest; | ||
| import org.elasticsearch.rest.RestResponse; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.rest.action.RestResponseListener; | ||
| | ||
| import java.io.IOException; | ||
| | ||
| import static org.elasticsearch.xcontent.ToXContent.EMPTY_PARAMS; | ||
| | ||
| public abstract class AbstractInfoAction extends BaseRestHandler { | ||
| | ||
| public abstract NodesStatsRequest buildNodeStatsRequest(); | ||
| | ||
| public abstract ChunkedToXContent xContentChunks(NodesStatsResponse nodesStatsResponse); | ||
| | ||
| @Override | ||
| protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
| return channel -> client.admin().cluster().nodesStats(buildNodeStatsRequest(), new RestResponseListener<>(channel) { | ||
| @Override | ||
| public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception { | ||
| return new RestResponse( | ||
| RestStatus.OK, | ||
| ChunkedRestResponseBody.fromXContent( | ||
| outerParams -> Iterators.concat( | ||
| ChunkedToXContentHelper.startObject(), | ||
| Iterators.single( | ||
| (builder, params) -> builder.field("cluster_name", nodesStatsResponse.getClusterName().value()) | ||
| ), | ||
| xContentChunks(nodesStatsResponse).toXContentChunked(outerParams), | ||
| ChunkedToXContentHelper.endObject() | ||
| ), | ||
| EMPTY_PARAMS, | ||
| channel | ||
| ) | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions 44 server/src/main/java/org/elasticsearch/rest/action/info/RestHttpInfoAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
| | ||
| package org.elasticsearch.rest.action.info; | ||
| | ||
| 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; | ||
| import org.elasticsearch.common.xcontent.ChunkedToXContent; | ||
| import org.elasticsearch.http.HttpStats; | ||
| import org.elasticsearch.rest.RestRequest; | ||
| | ||
| import java.util.List; | ||
| | ||
| public class RestHttpInfoAction extends AbstractInfoAction { | ||
| | ||
| public static final NodesStatsRequest NODES_STATS_REQUEST = new NodesStatsRequest().clear() | ||
| .addMetric(NodesStatsRequest.Metric.HTTP.metricName()); | ||
| | ||
| @Override | ||
| public String getName() { | ||
| return "http_info_action"; | ||
| } | ||
| | ||
| @Override | ||
| public List<Route> routes() { | ||
| return List.of(new Route(RestRequest.Method.GET, "/_info/http")); | ||
| } | ||
| | ||
| @Override | ||
| public NodesStatsRequest buildNodeStatsRequest() { | ||
| return NODES_STATS_REQUEST; | ||
| } | ||
| | ||
| @Override | ||
| public ChunkedToXContent xContentChunks(NodesStatsResponse nodesStatsResponse) { | ||
| return nodesStatsResponse.getNodes().stream().map(NodeStats::getHttp).reduce(HttpStats.IDENTITY, HttpStats::merge); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.