Skip to content

Commit

Permalink
admin: Add node object to /server_info response (envoyproxy#13252)
Browse files Browse the repository at this point in the history
This patch adds node object information to GET /server_info response.

Risk Level: Low
Testing: Added
Docs Changes: Updated
Release Notes: Added

Fixes envoyproxy#9684

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
  • Loading branch information
dio authored Sep 29, 2020
1 parent b63855d commit 41e65e2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 20 deletions.
7 changes: 6 additions & 1 deletion api/envoy/admin/v3/server_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion api/envoy/admin/v4alpha/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions docs/root/operations/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <logger_name> to change the log level.
will show a list of file paths, and the specific path should be used as <logger_name> to change the log level.

.. http:get:: /memory
Expand All @@ -276,19 +276,19 @@ modify different aspects of the server:
.. _operations_admin_interface_drain:

.. http:post:: /drain_listeners
:ref:`Drains <arch_overview_draining>` all listeners.

.. http:post:: /drain_listeners?inboundonly
:ref:`Drains <arch_overview_draining>` all inbound listeners. `traffic_direction` field in
:ref:`Listener <envoy_v3_api_msg_config.listener.v3.Listener>` is used to determine whether a listener
:ref:`Drains <arch_overview_draining>` all inbound listeners. `traffic_direction` field in
:ref:`Listener <envoy_v3_api_msg_config.listener.v3.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::
Expand Down Expand Up @@ -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 <envoy_v3_api_msg_admin.v3.ServerInfo>` for an
Expand Down
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ New Features
* access log: added support for :ref:`%DOWNSTREAM_PEER_FINGERPRINT_1% <config_access_log_format_response_flags>` as a response flag.
* access log: added support for nested objects in :ref:`JSON logging mode <config_access_log_format_dictionaries>`.
* access log: added :ref:`omit_empty_values<envoy_v3_api_field_config.core.v3.SubstitutionFormatString.omit_empty_values>` option to omit unset value from formatted log.
* admin: added :ref:`node <envoy_v3_api_msg_config.core.v3.Node>` information to GET /server_info :ref:`response object <envoy_v3_api_msg_admin.v3.ServerInfo>`.
* admin: added the ability to dump init manager unready targets information :ref:`/init_dump <operations_admin_interface_init_dump>` and :ref:`/init_dump?mask={} <operations_admin_interface_init_dump_by_mask>`.
* build: enable building envoy :ref:`arm64 images <arm_binaries>` by buildx tool in x86 CI platform.
* cluster: added new :ref:`connection_pool_per_downstream_connection <envoy_v3_api_field_config.cluster.v3.Cluster.connection_pool_per_downstream_connection>` flag, which enable creation of a new connection pool for each downstream connection.
Expand Down
7 changes: 6 additions & 1 deletion generated_api_shadow/envoy/admin/v3/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion generated_api_shadow/envoy/admin/v4alpha/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions include/envoy/local_info/local_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions source/server/admin/server_info_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 25 additions & 5 deletions test/server/admin/server_info_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ TEST_P(AdminInstanceTest, GetReadyRequest) {
}

TEST_P(AdminInstanceTest, GetRequest) {
EXPECT_CALL(server_.options_, toCommandLineOptions()).WillRepeatedly(Invoke([] {
NiceMock<LocalInfo::MockLocalInfo> 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<envoy::admin::v3::CommandLineOptions>();
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<Init::MockManager> initManager;
Expand All @@ -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());
}

{
Expand All @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 41e65e2

Please sign in to comment.