Skip to content
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

stats: Capture all the strings used to accumulate http stats in an object, plumbed through the system. #4997

Merged
merged 35 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d70cb18
Make a class for Http::CodeUtility::chargeResponseTiming et al, plumb…
jmarantz Nov 8, 2018
9c49dec
Use join() rather than fmt::format, and hold static strings in string…
jmarantz Nov 8, 2018
df7d7a1
fix router test (empty prefix) and use const string_view for member v…
jmarantz Nov 8, 2018
da648b3
add speed-test.
jmarantz Nov 8, 2018
ec66aaf
Remove libraries not needed by speed test.
jmarantz Nov 8, 2018
d509154
Merge branch 'master' into http-code-stats-as-object
jmarantz Nov 9, 2018
cf7565d
Merge branch 'master' into http-code-stats-as-object
jmarantz Nov 16, 2018
9cd564e
Merge branch 'master' into http-code-stats-as-object
jmarantz Nov 21, 2018
255c51b
format
jmarantz Nov 21, 2018
cca3bc9
Move the CodeStats instance out of the server and into listener_manag…
jmarantz Nov 25, 2018
bdea1d7
Add HTTP Context object.
jmarantz Nov 26, 2018
e7d59b2
Merge branch 'master' into http-code-stats-as-object
jmarantz Nov 26, 2018
60d7454
Merge branch 'master' into htp-context
jmarantz Nov 27, 2018
eb0be50
mostly working; need to commit to sync.
jmarantz Nov 27, 2018
60c4a73
Merge branch 'master' into htp-context
jmarantz Nov 27, 2018
4edb9cd
all tests building; one failure
jmarantz Nov 27, 2018
b8fc8da
all tests working.
jmarantz Nov 27, 2018
228c52d
Merge branch 'htp-context' into http-code-stats-as-object
jmarantz Nov 27, 2018
c257d69
Clean up comments and add tests.
jmarantz Nov 28, 2018
2cc92ec
clang-tidy fixes.
jmarantz Nov 28, 2018
aea8630
Add comments to internal function descriptions.
jmarantz Nov 29, 2018
30e0c15
Merge branch 'master' into http-code-stats-as-object
jmarantz Nov 29, 2018
47e014e
Merge branch 'master' into http-code-stats-as-object
jmarantz Dec 2, 2018
21e5a34
Update comment and remove empty ctors/dtors from cc files.
jmarantz Dec 2, 2018
3a2cef0
Remove superfluous include.
jmarantz Dec 2, 2018
dcf800b
Back out the changes to make config_ a direct object in server objects.
jmarantz Dec 2, 2018
72e6dd3
Contain ConfigurationImpl directly in the servers, simplifying a few …
jmarantz Dec 2, 2018
522e235
Fix dereference.
jmarantz Dec 2, 2018
01bd77a
all tests working.
jmarantz Dec 2, 2018
7802653
Merge branch 'master' into config-impl-contained
jmarantz Dec 3, 2018
c3508fa
Reword comment.
jmarantz Dec 3, 2018
0c8ac51
Merge branch 'config-impl-contained' into http-code-stats-as-object
jmarantz Dec 3, 2018
4b32611
Merge branch 'master' into http-code-stats-as-object
jmarantz Dec 3, 2018
4f0ebb5
Remove commented-out code.
jmarantz Dec 3, 2018
d08fc60
attempt to fix clang-tidy errors.
jmarantz Dec 4, 2018
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
10 changes: 10 additions & 0 deletions include/envoy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ envoy_cc_library(
envoy_cc_library(
name = "codes_interface",
hdrs = ["codes.h"],
deps = ["//include/envoy/stats:stats_interface"],
)

envoy_cc_library(
Expand All @@ -44,6 +45,15 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "context_interface",
hdrs = ["context.h"],
deps = [
":codes_interface",
"//include/envoy/tracing:http_tracer_interface",
],
)

envoy_cc_library(
name = "filter_interface",
hdrs = ["filter.h"],
Expand Down
58 changes: 58 additions & 0 deletions include/envoy/http/codes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include <chrono>

#include "envoy/stats/scope.h"

namespace Envoy {
namespace Http {

Expand Down Expand Up @@ -73,5 +77,59 @@ enum class Code {
// clang-format on
};

/**
* Manages updating of statistics for HTTP Status Codes. Sets up string-tokens
* for fast combining of tokens based on scope, status-code buckets (2xx,
* 4xx...), and exact status code.
*/
class CodeStats {
public:
virtual ~CodeStats() = default;

struct ResponseStatInfo {
Stats::Scope& global_scope_;
Stats::Scope& cluster_scope_;
const std::string& prefix_;
uint64_t response_status_code_;
bool internal_request_;
const std::string& request_vhost_name_;
const std::string& request_vcluster_name_;
const std::string& from_zone_;
const std::string& to_zone_;
bool upstream_canary_;
};

struct ResponseTimingInfo {
Stats::Scope& global_scope_;
Stats::Scope& cluster_scope_;
const std::string& prefix_;
std::chrono::milliseconds response_time_;
bool upstream_canary_;
bool internal_request_;
const std::string& request_vhost_name_;
const std::string& request_vcluster_name_;
const std::string& from_zone_;
const std::string& to_zone_;
};

/**
* Charge a simple response stat to an upstream.
*/
virtual void chargeBasicResponseStat(Stats::Scope& scope, const std::string& prefix,
Code response_code) const PURE;

/**
* Charge a response stat to both agg counters (*xx) as well as code specific counters. This
* routine also looks for the x-envoy-upstream-canary header and if it is set, also charges
* canary stats.
*/
virtual void chargeResponseStat(const ResponseStatInfo& info) const PURE;

/**
* Charge a response timing to the various dynamic stat postfixes.
*/
virtual void chargeResponseTiming(const ResponseTimingInfo& info) const PURE;
};

} // namespace Http
} // namespace Envoy
24 changes: 24 additions & 0 deletions include/envoy/http/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <memory>

#include "envoy/http/codes.h"
#include "envoy/tracing/http_tracer.h"

namespace Envoy {
namespace Http {

/**
* Captures http-related structures with cardinality of one per server.
*/
class Context {
public:
virtual ~Context() = default;
virtual Tracing::HttpTracer& tracer() PURE;
virtual CodeStats& codeStats() PURE;
};

using ContextPtr = std::unique_ptr<Context>;

} // namespace Http
} // namespace Envoy
5 changes: 4 additions & 1 deletion include/envoy/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ envoy_cc_library(
deps = [
":config_tracker_interface",
"//include/envoy/buffer:buffer_interface",
"//include/envoy/http:codes_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/http:query_params_interface",
Expand All @@ -37,6 +36,7 @@ envoy_cc_library(
hdrs = ["configuration.h"],
external_deps = ["abseil_optional"],
deps = [
"//include/envoy/http:context_interface",
"//include/envoy/ratelimit:ratelimit_interface",
"//include/envoy/tracing:http_tracer_interface",
"//include/envoy/upstream:cluster_manager_interface",
Expand Down Expand Up @@ -95,6 +95,7 @@ envoy_cc_library(
"//include/envoy/api:api_interface",
"//include/envoy/common:mutex_tracer",
"//include/envoy/event:timer_interface",
"//include/envoy/http:context_interface",
"//include/envoy/http:query_params_interface",
"//include/envoy/init:init_interface",
"//include/envoy/local_info:local_info_interface",
Expand Down Expand Up @@ -143,6 +144,8 @@ envoy_cc_library(
deps = [
":admin_interface",
"//include/envoy/access_log:access_log_interface",
"//include/envoy/http:codes_interface",
"//include/envoy/http:context_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/init:init_interface",
"//include/envoy/json:json_object_interface",
Expand Down
7 changes: 7 additions & 0 deletions include/envoy/server/filter_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "envoy/access_log/access_log.h"
#include "envoy/api/v2/core/base.pb.h"
#include "envoy/http/codes.h"
#include "envoy/http/context.h"
#include "envoy/http/filter.h"
#include "envoy/init/init.h"
#include "envoy/json/json_object.h"
Expand Down Expand Up @@ -140,6 +142,11 @@ class FactoryContext {
* @return OverloadManager& the overload manager for the server.
*/
virtual OverloadManager& overloadManager() PURE;

/**
* @return Http::Context& a reference to the http context.
*/
virtual Http::Context& httpContext() PURE;
};

class ListenerFactoryContext : public FactoryContext {
Expand Down
5 changes: 3 additions & 2 deletions include/envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "envoy/api/api.h"
#include "envoy/common/mutex_tracer.h"
#include "envoy/event/timer.h"
#include "envoy/http/context.h"
#include "envoy/init/init.h"
#include "envoy/local_info/local_info.h"
#include "envoy/network/listen_socket.h"
Expand Down Expand Up @@ -189,9 +190,9 @@ class Instance {
virtual Stats::Store& stats() PURE;

/**
* @return the server-wide http tracer.
* @return the server-wide http context.
*/
virtual Tracing::HttpTracer& httpTracer() PURE;
virtual Http::Context& httpContext() PURE;

/**
* @return ThreadLocal::Instance& the thread local storage engine for the server. This is used to
Expand Down
14 changes: 13 additions & 1 deletion source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ envoy_cc_library(
"//include/envoy/event:dispatcher_interface",
"//include/envoy/http:async_client_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/http:context_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/http:message_interface",
"//include/envoy/router:router_interface",
Expand Down Expand Up @@ -92,6 +93,17 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "context_lib",
srcs = ["context_impl.cc"],
hdrs = ["context_impl.h"],
deps = [
":codes_lib",
"//include/envoy/http:context_interface",
"//source/common/tracing:http_tracer_lib",
],
)

envoy_cc_library(
name = "conn_pool_base_lib",
srcs = ["conn_pool_base.cc"],
Expand Down Expand Up @@ -137,6 +149,7 @@ envoy_cc_library(
"//include/envoy/event:deferred_deletable",
"//include/envoy/event:dispatcher_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/http:context_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/local_info:local_info_interface",
Expand All @@ -150,7 +163,6 @@ envoy_cc_library(
"//include/envoy/stats:stats_interface",
"//include/envoy/stats:stats_macros",
"//include/envoy/stats:timespan",
"//include/envoy/tracing:http_tracer_interface",
"//include/envoy/upstream:upstream_interface",
"//source/common/access_log:access_log_formatter_lib",
"//source/common/buffer:buffer_lib",
Expand Down
5 changes: 3 additions & 2 deletions source/common/http/async_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ AsyncClientImpl::AsyncClientImpl(Upstream::ClusterInfoConstSharedPtr cluster,
const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cm, Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
Router::ShadowWriterPtr&& shadow_writer)
Router::ShadowWriterPtr&& shadow_writer,
Http::Context& http_context)
: cluster_(cluster),
config_("http.async-client.", local_info, stats_store, cm, runtime, random,
std::move(shadow_writer), true, false, false, dispatcher.timeSystem()),
std::move(shadow_writer), true, false, false, dispatcher.timeSystem(), http_context),
dispatcher_(dispatcher) {}

AsyncClientImpl::~AsyncClientImpl() {
Expand Down
4 changes: 3 additions & 1 deletion source/common/http/async_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "envoy/event/dispatcher.h"
#include "envoy/http/async_client.h"
#include "envoy/http/codec.h"
#include "envoy/http/context.h"
#include "envoy/http/header_map.h"
#include "envoy/http/message.h"
#include "envoy/router/router.h"
Expand Down Expand Up @@ -42,7 +43,8 @@ class AsyncClientImpl final : public AsyncClient {
AsyncClientImpl(Upstream::ClusterInfoConstSharedPtr cluster, Stats::Store& stats_store,
Event::Dispatcher& dispatcher, const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cm, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, Router::ShadowWriterPtr&& shadow_writer);
Runtime::RandomGenerator& random, Router::ShadowWriterPtr&& shadow_writer,
Http::Context& http_context);
~AsyncClientImpl();

// Http::AsyncClient
Expand Down
Loading