diff --git a/api/envoy/admin/v3/server_info.proto b/api/envoy/admin/v3/server_info.proto index c62324a2ee5b..5e3765a8586f 100644 --- a/api/envoy/admin/v3/server_info.proto +++ b/api/envoy/admin/v3/server_info.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package envoy.admin.v3; +import "envoy/config/core/v3/base.proto"; + import "google/protobuf/duration.proto"; import "envoy/annotations/deprecation.proto"; @@ -17,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // Proto representation of the value returned by /server_info, containing // server version/server status information. -// [#next-free-field: 7] +// [#next-free-field: 8] message ServerInfo { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v2alpha.ServerInfo"; @@ -52,6 +54,9 @@ message ServerInfo { // Command line options the server is currently running with. CommandLineOptions command_line_options = 6; + + // Populated node identity of this server. + config.core.v3.Node node = 7; } // [#next-free-field: 37] diff --git a/api/envoy/admin/v4alpha/server_info.proto b/api/envoy/admin/v4alpha/server_info.proto index eb680ce365e3..6f56978d49fe 100644 --- a/api/envoy/admin/v4alpha/server_info.proto +++ b/api/envoy/admin/v4alpha/server_info.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package envoy.admin.v4alpha; +import "envoy/config/core/v4alpha/base.proto"; + import "google/protobuf/duration.proto"; import "envoy/annotations/deprecation.proto"; @@ -17,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = NEXT_MAJOR_VERSIO // Proto representation of the value returned by /server_info, containing // server version/server status information. -// [#next-free-field: 7] +// [#next-free-field: 8] message ServerInfo { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v3.ServerInfo"; @@ -52,6 +54,9 @@ message ServerInfo { // Command line options the server is currently running with. CommandLineOptions command_line_options = 6; + + // Populated node identity of this server. + config.core.v4alpha.Node node = 7; } // [#next-free-field: 37] diff --git a/docs/root/operations/admin.rst b/docs/root/operations/admin.rst index 15d518f4418f..de2e678c2569 100644 --- a/docs/root/operations/admin.rst +++ b/docs/root/operations/admin.rst @@ -257,7 +257,7 @@ modify different aspects of the server: Generally only used during development. With `--enable-fine-grain-logging` being set, the logger is represented by the path of the file it belongs to (to be specific, the path determined by `__FILE__`), so the logger list - will show a list of file paths, and the specific path should be used as to change the log level. + will show a list of file paths, and the specific path should be used as to change the log level. .. http:get:: /memory @@ -276,19 +276,19 @@ modify different aspects of the server: .. _operations_admin_interface_drain: .. http:post:: /drain_listeners - + :ref:`Drains ` all listeners. .. http:post:: /drain_listeners?inboundonly - :ref:`Drains ` all inbound listeners. `traffic_direction` field in - :ref:`Listener ` is used to determine whether a listener + :ref:`Drains ` all inbound listeners. `traffic_direction` field in + :ref:`Listener ` is used to determine whether a listener is inbound or outbound. .. http:post:: /drain_listeners?graceful - When draining listeners, enter a graceful drain period prior to closing listeners. - This behaviour and duration is configurable via server options or CLI + When draining listeners, enter a graceful drain period prior to closing listeners. + This behaviour and duration is configurable via server options or CLI (:option:`--drain-time-s` and :option:`--drain-strategy`). .. attention:: @@ -334,7 +334,23 @@ modify different aspects of the server: "cpuset_threads": false }, "uptime_current_epoch": "6s", - "uptime_all_epochs": "6s" + "uptime_all_epochs": "6s", + "node": { + "id": "node1", + "cluster": "cluster1", + "user_agent_name": "envoy", + "user_agent_build_version": { + "version": { + "major_number": 1, + "minor_number": 15, + "patch": 0 + } + }, + "metadata": {}, + "extensions": [], + "client_features": [], + "listening_addresses": [] + } } See the :ref:`ServerInfo proto ` for an diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index a3f5429ee511..fbce93a253e2 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -76,6 +76,7 @@ New Features * access log: added support for :ref:`%DOWNSTREAM_PEER_FINGERPRINT_1% ` as a response flag. * access log: added support for nested objects in :ref:`JSON logging mode `. * access log: added :ref:`omit_empty_values` option to omit unset value from formatted log. +* admin: added :ref:`node ` information to GET /server_info :ref:`response object `. * admin: added the ability to dump init manager unready targets information :ref:`/init_dump ` and :ref:`/init_dump?mask={} `. * build: enable building envoy :ref:`arm64 images ` by buildx tool in x86 CI platform. * cluster: added new :ref:`connection_pool_per_downstream_connection ` flag, which enable creation of a new connection pool for each downstream connection. diff --git a/generated_api_shadow/envoy/admin/v3/server_info.proto b/generated_api_shadow/envoy/admin/v3/server_info.proto index 4b63fcfc7428..c7a19453b882 100644 --- a/generated_api_shadow/envoy/admin/v3/server_info.proto +++ b/generated_api_shadow/envoy/admin/v3/server_info.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package envoy.admin.v3; +import "envoy/config/core/v3/base.proto"; + import "google/protobuf/duration.proto"; import "envoy/annotations/deprecation.proto"; @@ -17,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // Proto representation of the value returned by /server_info, containing // server version/server status information. -// [#next-free-field: 7] +// [#next-free-field: 8] message ServerInfo { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v2alpha.ServerInfo"; @@ -52,6 +54,9 @@ message ServerInfo { // Command line options the server is currently running with. CommandLineOptions command_line_options = 6; + + // Populated node identity of this server. + config.core.v3.Node node = 7; } // [#next-free-field: 37] diff --git a/generated_api_shadow/envoy/admin/v4alpha/server_info.proto b/generated_api_shadow/envoy/admin/v4alpha/server_info.proto index eb680ce365e3..6f56978d49fe 100644 --- a/generated_api_shadow/envoy/admin/v4alpha/server_info.proto +++ b/generated_api_shadow/envoy/admin/v4alpha/server_info.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package envoy.admin.v4alpha; +import "envoy/config/core/v4alpha/base.proto"; + import "google/protobuf/duration.proto"; import "envoy/annotations/deprecation.proto"; @@ -17,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = NEXT_MAJOR_VERSIO // Proto representation of the value returned by /server_info, containing // server version/server status information. -// [#next-free-field: 7] +// [#next-free-field: 8] message ServerInfo { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v3.ServerInfo"; @@ -52,6 +54,9 @@ message ServerInfo { // Command line options the server is currently running with. CommandLineOptions command_line_options = 6; + + // Populated node identity of this server. + config.core.v4alpha.Node node = 7; } // [#next-free-field: 37] diff --git a/include/envoy/local_info/local_info.h b/include/envoy/local_info/local_info.h index 379db4c4de0b..7c4a0f5b4795 100644 --- a/include/envoy/local_info/local_info.h +++ b/include/envoy/local_info/local_info.h @@ -22,22 +22,22 @@ class LocalInfo { virtual Network::Address::InstanceConstSharedPtr address() const PURE; /** - * Human readable zone name. E.g., "us-east-1a". + * @return the human readable zone name. E.g., "us-east-1a". */ virtual const std::string& zoneName() const PURE; /** - * Human readable cluster name. E.g., "eta". + * @return the human readable cluster name. E.g., "eta". */ virtual const std::string& clusterName() const PURE; /** - * Human readable individual node name. E.g., "i-123456". + * @return the human readable individual node name. E.g., "i-123456". */ virtual const std::string& nodeName() const PURE; /** - * v2 API Node protobuf. This is the full node identity presented to management servers. + * @return the full node identity presented to management servers. */ virtual const envoy::config::core::v3::Node& node() const PURE; }; diff --git a/source/server/admin/server_info_handler.cc b/source/server/admin/server_info_handler.cc index d668dac83992..86669949d288 100644 --- a/source/server/admin/server_info_handler.cc +++ b/source/server/admin/server_info_handler.cc @@ -88,6 +88,7 @@ Http::Code ServerInfoHandler::handlerServerInfo(absl::string_view, Http::Respons envoy::admin::v3::CommandLineOptions* command_line_options = server_info.mutable_command_line_options(); *command_line_options = *server_.options().toCommandLineOptions(); + server_info.mutable_node()->MergeFrom(server_.localInfo().node()); response.add(MessageUtil::getJsonStringFromMessage(server_info, true, true)); headers.setReferenceContentType(Http::Headers::get().ContentTypeValues.Json); return Http::Code::OK; diff --git a/test/server/admin/server_info_handler_test.cc b/test/server/admin/server_info_handler_test.cc index d9ef53339f95..65b253d0615d 100644 --- a/test/server/admin/server_info_handler_test.cc +++ b/test/server/admin/server_info_handler_test.cc @@ -96,11 +96,13 @@ TEST_P(AdminInstanceTest, GetReadyRequest) { } TEST_P(AdminInstanceTest, GetRequest) { - EXPECT_CALL(server_.options_, toCommandLineOptions()).WillRepeatedly(Invoke([] { + NiceMock local_info; + EXPECT_CALL(server_, localInfo()).WillRepeatedly(ReturnRef(local_info)); + EXPECT_CALL(server_.options_, toCommandLineOptions()).WillRepeatedly(Invoke([&local_info] { Server::CommandLineOptionsPtr command_line_options = std::make_unique(); command_line_options->set_restart_epoch(2); - command_line_options->set_service_cluster("cluster"); + command_line_options->set_service_cluster(local_info.clusterName()); return command_line_options; })); NiceMock initManager; @@ -122,7 +124,13 @@ TEST_P(AdminInstanceTest, GetRequest) { EXPECT_EQ(server_info_proto.state(), envoy::admin::v3::ServerInfo::LIVE); EXPECT_EQ(server_info_proto.hot_restart_version(), "foo_version"); EXPECT_EQ(server_info_proto.command_line_options().restart_epoch(), 2); - EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), "cluster"); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), local_info.clusterName()); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), + server_info_proto.node().cluster()); + EXPECT_EQ(server_info_proto.command_line_options().service_node(), ""); + EXPECT_EQ(server_info_proto.command_line_options().service_zone(), ""); + EXPECT_EQ(server_info_proto.node().id(), local_info.nodeName()); + EXPECT_EQ(server_info_proto.node().locality().zone(), local_info.zoneName()); } { @@ -139,7 +147,13 @@ TEST_P(AdminInstanceTest, GetRequest) { TestUtility::loadFromJson(body, server_info_proto); EXPECT_EQ(server_info_proto.state(), envoy::admin::v3::ServerInfo::PRE_INITIALIZING); EXPECT_EQ(server_info_proto.command_line_options().restart_epoch(), 2); - EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), "cluster"); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), local_info.clusterName()); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), + server_info_proto.node().cluster()); + EXPECT_EQ(server_info_proto.command_line_options().service_node(), ""); + EXPECT_EQ(server_info_proto.command_line_options().service_zone(), ""); + EXPECT_EQ(server_info_proto.node().id(), local_info.nodeName()); + EXPECT_EQ(server_info_proto.node().locality().zone(), local_info.zoneName()); } Http::TestResponseHeaderMapImpl response_headers; @@ -155,7 +169,13 @@ TEST_P(AdminInstanceTest, GetRequest) { TestUtility::loadFromJson(body, server_info_proto); EXPECT_EQ(server_info_proto.state(), envoy::admin::v3::ServerInfo::INITIALIZING); EXPECT_EQ(server_info_proto.command_line_options().restart_epoch(), 2); - EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), "cluster"); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), local_info.clusterName()); + EXPECT_EQ(server_info_proto.command_line_options().service_cluster(), + server_info_proto.node().cluster()); + EXPECT_EQ(server_info_proto.command_line_options().service_node(), ""); + EXPECT_EQ(server_info_proto.command_line_options().service_zone(), ""); + EXPECT_EQ(server_info_proto.node().id(), local_info.nodeName()); + EXPECT_EQ(server_info_proto.node().locality().zone(), local_info.zoneName()); } TEST_P(AdminInstanceTest, PostRequest) {