Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d179e90
Allow non ws requests on WS route
Oct 2, 2017
6e84e55
More tests for WebSockets
Oct 3, 2017
2cedf44
Fix test for Non WS on WS route
Oct 3, 2017
84f2aab
Merge remote-tracking branch 'upstream/master'
Oct 3, 2017
37af80d
fix
Oct 3, 2017
1645eaf
connect timeout test
Oct 3, 2017
928272d
format
Oct 3, 2017
6ee6657
fix timeout test
Oct 3, 2017
d7a4188
Merge remote-tracking branch 'upstream/master'
Oct 3, 2017
8599956
formatting
Oct 3, 2017
d2a10c2
Merge remote-tracking branch 'upstream/master'
Oct 4, 2017
75ef074
fix auto host rewrite check
Oct 4, 2017
baf1ee1
compile fix
Oct 4, 2017
dd4b8aa
connectionfailure test
Oct 4, 2017
c9a9fa4
update docs
Oct 4, 2017
dce2ce1
Merge remote-tracking branch 'upstream/master'
Oct 13, 2017
cd70037
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
659e793
configurable cluster name length
Oct 16, 2017
b51a666
formatting
Oct 16, 2017
9d0366e
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
a724473
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
c5d6e8f
remove CLI option
Oct 17, 2017
644b05c
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
d6caed2
fix
Oct 17, 2017
3092c06
rds/lds/cds tests
Oct 17, 2017
0fd0ba7
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
03c9b31
rename var
Oct 17, 2017
7a9e602
format
Oct 17, 2017
9ae3160
change CLI option name
Oct 17, 2017
98518c0
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
503eecf
feedback
Oct 17, 2017
aad79de
sweeping renames
Oct 17, 2017
2925163
fix
Oct 17, 2017
4507c10
test fix
Oct 17, 2017
2527ed1
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
cae08f0
long string to fix hot_restart_test
Oct 17, 2017
5afd3ba
remove stray comment
Oct 17, 2017
d4de240
docs and nits
Oct 18, 2017
65debb2
max len limit for vhosts
Oct 18, 2017
fa2d91b
review comments
Oct 18, 2017
9ec016c
nits
Oct 18, 2017
e9b0dce
Merge remote-tracking branch 'upstream/master'
Oct 18, 2017
b534be9
Merge remote-tracking branch 'upstream/master'
Oct 18, 2017
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
11 changes: 7 additions & 4 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ on the Bazel command line.

## Stats Tunables

The default maximum number of stats in shared memory, and the default maximum length of a stat name,
can be overriden at compile-time by defining `ENVOY_DEFAULT_MAX_STATS` and `ENVOY_DEFAULT_MAX_STAT_NAME_LENGTH`,
respectively, to the desired value. For example:
The default maximum number of stats in shared memory, and the default
maximum length of a cluster/route config/listener name, can be
overriden at compile-time by defining `ENVOY_DEFAULT_MAX_STATS` and
`ENVOY_DEFAULT_MAX_OBJ_NAME_LENGTH`, respectively, to the desired
value. For example:

```
bazel build --copts=-DENVOY_DEFAULT_MAX_STATS=32768 //source/exe:envoy-static
bazel build --copts=-DENVOY_DEFAULT_MAX_STATS=32768 --copts=-DENVOY_DEFAULT_MAX_OBJ_NAME_LENGTH=150 //source/exe:envoy-static
```


Expand Down
3 changes: 2 additions & 1 deletion docs/configuration/cluster_manager/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Cluster
name
*(required, string)* Supplies the name of the cluster which must be unique across all clusters.
The cluster name is used when emitting :ref:`statistics <config_cluster_manager_cluster_stats>`.
The cluster name can be at most 60 characters long.
By default, the maximum length of a cluster name is limited to 60 characters. This limit can be
increased by setting the :option:`--max-obj-name-len` command line argument to the desired value.

.. _config_cluster_manager_type:

Expand Down
4 changes: 3 additions & 1 deletion docs/configuration/http_conn_man/rds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ route_config_name
*(required, string)* The name of the route configuration. This name will be passed to the
:ref:`RDS HTTP API <config_http_conn_man_rds_api>`. This allows an Envoy configuration with
multiple HTTP listeners (and associated HTTP connection manager filters) to use different route
configurations.
configurations. By default, the maximum length of the name is limited to 60 characters. This
limit can be increased by setting the :option:`--max-obj-name-len` command line argument to the
desired value.

refresh_delay_ms
*(optional, integer)* The delay, in milliseconds, between fetches to the RDS API. Envoy will add
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration/http_conn_man/route_config/vhost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ upstream cluster to route to or whether to perform a redirect.

name
*(required, string)* The logical name of the virtual host. This is used when emitting certain
statistics but is not relevant for forwarding.
statistics but is not relevant for forwarding. By default, the maximum length of the name is
limited to 60 characters. This limit can be increased by setting the
:option:`--max-obj-name-len` command line argument to the desired value.

domains
*(required, array)* A list of domains (host/authority header) that will be matched to this
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/listeners/listeners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ name
*(optional, string)* The unique name by which this listener is known. If no name is provided,
Envoy will allocate an internal UUID for the listener. If the listener is to be dynamically
updated or removed via :ref:`LDS <config_listeners_lds>` a unique name must be provided.
By default, the maximum length of a listener's name is limited to 60 characters. This limit can be
increased by setting the :option:`--max-obj-name-len` command line argument to the desired value.

address
*(required, string)* The address that the listener should listen on. Currently only TCP
Expand Down
13 changes: 10 additions & 3 deletions docs/operations/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,17 @@ following are the command line options that Envoy supports.
during a hot restart. See the :ref:`hot restart overview <arch_overview_hot_restart>` for more
information. Defaults to 900 seconds (15 minutes).

.. option:: --max-stat-name-len <uint64_t>
.. option:: --max-obj-name-len <uint64_t>

*(optional)* The maximum name length (in bytes) for a stat. This setting affects the output
of :option:`--hot-restart-version`; the same value must be used to hot restart. Defaults to 127.
*(optional)* The maximum name length (in bytes) of the name field in a cluster/route_config/listener.
This setting is typically used in scenarios where the cluster names are auto generated, and often exceed
the built-in limit of 60 characters. Defaults to 60.

.. attention::

This setting affects the output of :option:`--hot-restart-version`. If you started envoy with this
option set to a non default value, you should use the same option (and same value) for subsequent hot
restarts.

.. option:: --max-stats <uint64_t>

Expand Down
5 changes: 3 additions & 2 deletions include/envoy/server/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ class Options {
virtual uint64_t maxStats() PURE;

/**
* @return uint64_t the maximum name length of a stat.
* @return uint64_t the maximum name length of the name field in
* router/cluster/listener.
*/
virtual uint64_t maxStatNameLength() PURE;
virtual uint64_t maxObjNameLength() PURE;
};

} // namespace Server
Expand Down
3 changes: 3 additions & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ envoy_cc_library(
":address_json_lib",
":json_utility_lib",
":tls_context_json_lib",
":utility_lib",
":well_known_names",
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
Expand Down Expand Up @@ -231,6 +232,7 @@ envoy_cc_library(
":well_known_names",
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/config:utility_lib",
"//source/common/json:config_schemas_lib",
],
)
Expand Down Expand Up @@ -290,6 +292,7 @@ envoy_cc_library(
"//source/common/json:config_schemas_lib",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
"//source/common/stats:stats_lib",
],
)

Expand Down
6 changes: 5 additions & 1 deletion source/common/config/cds_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ void CdsJson::translateCluster(const Json::Object& json_cluster,
const Optional<envoy::api::v2::ConfigSource>& eds_config,
envoy::api::v2::Cluster& cluster) {
json_cluster.validateSchema(Json::Schema::CLUSTER_SCHEMA);
cluster.set_name(json_cluster.getString("name"));

const std::string name = json_cluster.getString("name");
Utility::checkObjNameLength("Invalid cluster name", name);
cluster.set_name(name);

const std::string string_type = json_cluster.getString("type");
auto set_dns_hosts = [&json_cluster, &cluster] {
const auto hosts = json_cluster.getObjectArray("hosts");
Expand Down
10 changes: 6 additions & 4 deletions source/common/config/lds_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common/config/address_json.h"
#include "common/config/json_utility.h"
#include "common/config/tls_context_json.h"
#include "common/config/utility.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"
#include "common/network/utility.h"
Expand All @@ -15,6 +16,10 @@ void LdsJson::translateListener(const Json::Object& json_listener,
envoy::api::v2::Listener& listener) {
json_listener.validateSchema(Json::Schema::LISTENER_SCHEMA);

const std::string name = json_listener.getString("name", "");
Utility::checkObjNameLength("Invalid listener name", name);
listener.set_name(name);

AddressJson::translateAddress(json_listener.getString("address"), true, true,
*listener.mutable_address());

Expand Down Expand Up @@ -42,12 +47,9 @@ void LdsJson::translateListener(const Json::Object& json_listener,
}

JSON_UTIL_SET_BOOL(json_listener, *filter_chain, use_proxy_proto);

JSON_UTIL_SET_BOOL(json_listener, listener, use_original_dst);
JSON_UTIL_SET_INTEGER(json_listener, listener, per_connection_buffer_limit_bytes);
JSON_UTIL_SET_STRING(json_listener, listener, name);

JSON_UTIL_SET_BOOL(json_listener, *listener.mutable_deprecated_v1(), bind_to_port);
JSON_UTIL_SET_INTEGER(json_listener, listener, per_connection_buffer_limit_bytes);
}

} // namespace Config
Expand Down
6 changes: 5 additions & 1 deletion source/common/config/rds_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "common/config/base_json.h"
#include "common/config/json_utility.h"
#include "common/config/metadata.h"
#include "common/config/utility.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"

Expand Down Expand Up @@ -130,7 +131,10 @@ void RdsJson::translateRouteConfiguration(const Json::Object& json_route_config,
void RdsJson::translateVirtualHost(const Json::Object& json_virtual_host,
envoy::api::v2::VirtualHost& virtual_host) {
json_virtual_host.validateSchema(Json::Schema::VIRTUAL_HOST_CONFIGURATION_SCHEMA);
JSON_UTIL_SET_STRING(json_virtual_host, virtual_host, name);

const std::string name = json_virtual_host.getString("name", "");
Utility::checkObjNameLength("Invalid virtual host name", name);
virtual_host.set_name(name);

for (const std::string& domain : json_virtual_host.getStringArray("domains", true)) {
virtual_host.add_domains(domain);
Expand Down
15 changes: 14 additions & 1 deletion source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/json/config_schemas.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"
#include "common/stats/stats_impl.h"

#include "fmt/format.h"

Expand Down Expand Up @@ -86,11 +87,15 @@ void Utility::translateCdsConfig(const Json::Object& json_config,

void Utility::translateRdsConfig(const Json::Object& json_rds, envoy::api::v2::filter::Rds& rds) {
json_rds.validateSchema(Json::Schema::RDS_CONFIGURATION_SCHEMA);

const std::string name = json_rds.getString("route_config_name", "");
checkObjNameLength("Invalid route_config name", name);
rds.set_route_config_name(name);

translateApiConfigSource(json_rds.getString("cluster"),
json_rds.getInteger("refresh_delay_ms", 30000),
json_rds.getString("api_type", ApiType::get().RestLegacy),
*rds.mutable_config_source()->mutable_api_config_source());
JSON_UTIL_SET_STRING(json_rds, rds, route_config_name);
}

void Utility::translateLdsConfig(const Json::Object& json_lds,
Expand Down Expand Up @@ -119,5 +124,13 @@ std::string Utility::resourceName(const ProtobufWkt::Any& resource) {
fmt::format("Unknown type URL {} in DiscoveryResponse", resource.type_url()));
}

void Utility::checkObjNameLength(const std::string& error_prefix, const std::string& name) {
if (name.length() > Stats::RawStatData::maxObjNameLength()) {
throw EnvoyException(fmt::format("{}: Length of {} ({}) exceeds allowed maximum length ({})",
error_prefix, name, name.length(),
Stats::RawStatData::maxObjNameLength()));
}
}

} // namespace Config
} // namespace Envoy
8 changes: 8 additions & 0 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ class Utility {
* @return std::string resource name.
*/
static std::string resourceName(const ProtobufWkt::Any& resource);

/**
* Check user supplied name in RDS/CDS/LDS for sanity.
* It should be within the configured length limit. Throws on error.
* @param error_prefix supplies the prefix to use in error messages.
* @param name supplies the name to check for length limits.
*/
static void checkObjNameLength(const std::string& error_prefix, const std::string& name);
};

} // namespace Config
Expand Down
3 changes: 1 addition & 2 deletions source/common/json/config_schemas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,7 @@ const std::string Json::Schema::CLUSTER_SCHEMA(R"EOF(
"properties" : {
"name" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 60
"minLength" : 1
},
"type" : {
"type" : "string",
Expand Down
12 changes: 6 additions & 6 deletions source/common/stats/stats_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ size_t RawStatData::size() {
return roundUpMultipleNaturalAlignment(sizeof(RawStatData) + nameSize());
}

size_t& RawStatData::initializeAndGetMutableMaxNameLength(size_t configured_size) {
size_t& RawStatData::initializeAndGetMutableMaxObjNameLength(size_t configured_size) {
// Like CONSTRUCT_ON_FIRST_USE, but non-const so that the value can be changed by tests
static size_t size = configured_size;
return size;
}

void RawStatData::configure(Server::Options& options) {
const size_t configured = options.maxStatNameLength();
const size_t configured = options.maxObjNameLength();
RELEASE_ASSERT(configured > 0);
size_t max_name_length = initializeAndGetMutableMaxNameLength(configured);
size_t max_obj_name_length = initializeAndGetMutableMaxObjNameLength(configured);

// If this fails, it means that this function was called too late during
// startup because things were already using this size before it was set.
RELEASE_ASSERT(max_name_length == configured);
RELEASE_ASSERT(max_obj_name_length == configured);
}

void RawStatData::configureForTestsOnly(Server::Options& options) {
const size_t configured = options.maxStatNameLength();
initializeAndGetMutableMaxNameLength(configured) = configured;
const size_t configured = options.maxObjNameLength();
initializeAndGetMutableMaxObjNameLength(configured) = configured;
}

std::string Utility::sanitizeStatsName(const std::string& name) {
Expand Down
35 changes: 30 additions & 5 deletions source/common/stats/stats_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ struct RawStatData {
* Returns the maximum length of the name of a stat. This length
* does not include a trailing NULL-terminator.
*/
static size_t maxNameLength() {
return initializeAndGetMutableMaxNameLength(DEFAULT_MAX_NAME_SIZE);
static size_t maxNameLength() { return maxObjNameLength() + MAX_STAT_SUFFIX_LENGTH; }

/**
* Returns the maximum length of a user supplied object (route/cluster/listener)
* name field in a stat. This length does not include a trailing NULL-terminator.
*/
static size_t maxObjNameLength() {
return initializeAndGetMutableMaxObjNameLength(DEFAULT_MAX_OBJ_NAME_LENGTH);
}

/**
* Returns the maximum length of a stat suffix that Envoy generates (over the user supplied name).
* This length does not include a trailing NULL-terminator.
*/
static size_t maxStatSuffixLength() { return MAX_STAT_SUFFIX_LENGTH; }

/**
* size in bytes of name_
*/
Expand Down Expand Up @@ -102,9 +114,22 @@ struct RawStatData {
char name_[];

private:
static const size_t DEFAULT_MAX_NAME_SIZE = 127;

static size_t& initializeAndGetMutableMaxNameLength(size_t configured_size);
// The max name length is based on current set of stats.
// As of now, the longest stat is
// cluster.<cluster_name>.outlier_detection.ejections_consecutive_5xx
// which is 52 characters long without the cluster name.
// The max stat name length is 127 (default). So, in order to give room
// for growth to both the envoy generated stat characters
// (e.g., outlier_detection...) and user supplied names (e.g., cluster name),
// we set the max user supplied name length to 60, and the max internally
// generated stat suffixes to 67 (15 more characters to grow).
// If you want to increase the max user supplied name length, use the compiler
// option ENVOY_DEFAULT_MAX_OBJ_NAME_LENGTH or the CLI option
// max-obj-name-len
static const size_t DEFAULT_MAX_OBJ_NAME_LENGTH = 60;
static const size_t MAX_STAT_SUFFIX_LENGTH = 67;

static size_t& initializeAndGetMutableMaxObjNameLength(size_t configured_size);
};

/**
Expand Down
1 change: 1 addition & 0 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ envoy_cc_library(
"//include/envoy/server:options_interface",
"//source/common/common:macros",
"//source/common/common:version_lib",
"//source/common/stats:stats_lib",
],
)

Expand Down
Loading