1
#pragma once
2

            
3
#include <chrono>
4
#include <cstdint>
5
#include <string>
6

            
7
#include "envoy/common/pure.h"
8
#include "envoy/common/time.h"
9
#include "envoy/config/core/v3/base.pb.h"
10
#include "envoy/http/header_map.h"
11
#include "envoy/http/protocol.h"
12
#include "envoy/network/socket.h"
13
#include "envoy/ssl/connection.h"
14
#include "envoy/stream_info/filter_state.h"
15
#include "envoy/stream_info/stream_id_provider.h"
16
#include "envoy/tracing/trace_reason.h"
17
#include "envoy/upstream/host_description.h"
18

            
19
#include "source/common/common/assert.h"
20
#include "source/common/protobuf/protobuf.h"
21
#include "source/common/singleton/const_singleton.h"
22

            
23
#include "absl/types/optional.h"
24

            
25
namespace Envoy {
26

            
27
namespace Router {
28
class Route;
29
using RouteConstSharedPtr = std::shared_ptr<const Route>;
30
class VirtualHost;
31
using VirtualHostConstSharedPtr = std::shared_ptr<const VirtualHost>;
32
} // namespace Router
33

            
34
namespace Upstream {
35
class ClusterInfo;
36
using ClusterInfoConstSharedPtr = std::shared_ptr<const ClusterInfo>;
37
} // namespace Upstream
38

            
39
namespace StreamInfo {
40

            
41
enum CoreResponseFlag : uint16_t {
42
  // Local server healthcheck failed.
43
  FailedLocalHealthCheck,
44
  // No healthy upstream.
45
  NoHealthyUpstream,
46
  // Request timeout on upstream.
47
  UpstreamRequestTimeout,
48
  // Local codec level reset was sent on the stream.
49
  LocalReset,
50
  // Remote codec level reset was received on the stream.
51
  UpstreamRemoteReset,
52
  // Local reset by a connection pool due to an initial connection failure.
53
  UpstreamConnectionFailure,
54
  // If the stream was locally reset due to connection termination.
55
  UpstreamConnectionTermination,
56
  // The stream was reset because of a resource overflow.
57
  UpstreamOverflow,
58
  // No route found for a given request.
59
  NoRouteFound,
60
  // Request was delayed before proxying.
61
  DelayInjected,
62
  // Abort with error code was injected.
63
  FaultInjected,
64
  // Request was ratelimited locally by rate limit filter.
65
  RateLimited,
66
  // Request was unauthorized by external authorization service.
67
  UnauthorizedExternalService,
68
  // Unable to call Ratelimit service.
69
  RateLimitServiceError,
70
  // If the stream was reset due to a downstream connection termination.
71
  DownstreamConnectionTermination,
72
  // Exceeded upstream retry limit.
73
  UpstreamRetryLimitExceeded,
74
  // Request hit the stream idle timeout, triggering a 408.
75
  StreamIdleTimeout,
76
  // Request specified x-envoy-* header values that failed strict header checks.
77
  InvalidEnvoyRequestHeaders,
78
  // Downstream request had an HTTP protocol error
79
  DownstreamProtocolError,
80
  // Upstream request reached to user defined max stream duration.
81
  UpstreamMaxStreamDurationReached,
82
  // True if the response was served from an Envoy cache filter.
83
  ResponseFromCacheFilter,
84
  // Filter config was not received within the permitted warming deadline.
85
  NoFilterConfigFound,
86
  // Request or connection exceeded the downstream connection duration.
87
  DurationTimeout,
88
  // Upstream response had an HTTP protocol error
89
  UpstreamProtocolError,
90
  // No cluster found for a given request.
91
  NoClusterFound,
92
  // Overload Manager terminated the stream.
93
  OverloadManager,
94
  // DNS resolution failed.
95
  DnsResolutionFailed,
96
  // Drop certain percentage of overloaded traffic.
97
  DropOverLoad,
98
  // Downstream remote codec level reset was received on the stream.
99
  DownstreamRemoteReset,
100
  // Unconditionally drop all traffic due to drop_overload is set to 100%.
101
  UnconditionalDropOverload,
102
  // ATTENTION: MAKE SURE THIS REMAINS EQUAL TO THE LAST FLAG.
103
  LastFlag = UnconditionalDropOverload,
104
};
105

            
106
class ResponseFlagUtils;
107

            
108
class ResponseFlag {
109
public:
110
12721
  constexpr ResponseFlag() = default;
111

            
112
  /**
113
   * Construct a response flag from the core response flag enum. The integer
114
   * value of the enum is used as the raw integer value of the flag.
115
   * @param flag the core response flag enum.
116
   */
117
101005
  constexpr ResponseFlag(CoreResponseFlag flag) : value_(flag) {}
118

            
119
  /**
120
   * Get the raw integer value of the flag.
121
   * @return uint16_t the raw integer value.
122
   */
123
76212
  uint16_t value() const { return value_; }
124

            
125
38314
  bool operator==(const ResponseFlag& other) const { return value_ == other.value_; }
126

            
127
private:
128
  friend class ResponseFlagUtils;
129

            
130
  // This private constructor is used to create extended response flags from
131
  // uint16_t values. This can only be used by ResponseFlagUtils to ensure
132
  // only validated values are used.
133
8
  ResponseFlag(uint16_t value) : value_(value) {}
134

            
135
  uint16_t value_{};
136
};
137

            
138
/**
139
 * Constants for the response code details field of StreamInfo for details sent
140
 * by core (non-extension) code.
141
 *
142
 * These provide details about the stream state such as whether the
143
 * response is from the upstream or from envoy (in case of a local reply).
144
 * Custom extensions can define additional values provided they are appropriately
145
 * scoped to avoid collisions.
146
 */
147
struct ResponseCodeDetailValues {
148
  // Response code was set by the upstream.
149
  const std::string ViaUpstream = "via_upstream";
150
  // Envoy is doing non-streaming proxying, and the request payload exceeded
151
  // configured limits.
152
  const std::string RequestPayloadTooLarge = "request_payload_too_large";
153
  // Envoy is doing non-streaming proxying, and the response payload exceeded
154
  // configured limits.
155
  const std::string ResponsePayloadTooLarge = "response_payload_too_large";
156
  // Envoy is doing streaming proxying, but too much data arrived while waiting
157
  // to attempt a retry.
158
  const std::string RequestPayloadExceededRetryBufferLimit =
159
      "request_payload_exceeded_retry_buffer_limit";
160
  // The per-stream keepalive timeout was exceeded.
161
  const std::string StreamIdleTimeout = "stream_idle_timeout";
162
  // The per-stream max duration timeout was exceeded.
163
  const std::string MaxDurationTimeout = "max_duration_timeout";
164
  // The per-stream total request timeout was exceeded.
165
  const std::string RequestOverallTimeout = "request_overall_timeout";
166
  // The per-stream request header timeout was exceeded.
167
  const std::string RequestHeaderTimeout = "request_header_timeout";
168
  // The request was rejected due to the Overload Manager reaching configured resource limits.
169
  const std::string Overload = "overload";
170
  // The HTTP/1.0 or HTTP/0.9 request was rejected due to HTTP/1.0 support not being configured.
171
  const std::string LowVersion = "low_version";
172
  // The request was rejected due to a missing Host: or :authority field.
173
  const std::string MissingHost = "missing_host_header";
174
  // The request was rejected due to x-envoy-* headers failing strict header validation.
175
  const std::string InvalidEnvoyRequestHeaders = "request_headers_failed_strict_check";
176
  // The request was rejected due to a missing Path or :path header field.
177
  const std::string MissingPath = "missing_path_rejected";
178
  // The request was rejected due to an invalid Path or :path header field.
179
  const std::string InvalidPath = "invalid_path";
180
  // The request was rejected due to using an absolute path on a route not supporting them.
181
  const std::string AbsolutePath = "absolute_path_rejected";
182
  // The request was rejected because path normalization was configured on and failed, probably due
183
  // to an invalid path.
184
  const std::string PathNormalizationFailed = "path_normalization_failed";
185
  // The request was rejected because it attempted an unsupported upgrade.
186
  const std::string UpgradeFailed = "upgrade_failed";
187
  // The websocket handshake is unsuccessful and only SwitchingProtocols is considering successful.
188
  const std::string WebsocketHandshakeUnsuccessful = "websocket_handshake_unsuccessful";
189

            
190
  // The request was rejected by the HCM because there was no route configuration found.
191
  const std::string RouteConfigurationNotFound = "route_configuration_not_found";
192
  // The request was rejected by the router filter because there was no route found.
193
  const std::string RouteNotFound = "route_not_found";
194
  // A direct response was generated by the router filter.
195
  const std::string DirectResponse = "direct_response";
196
  // The request was rejected by the router filter because there was no cluster found for the
197
  // selected route.
198
  const std::string ClusterNotFound = "cluster_not_found";
199
  // The request was rejected by the router filter because the cluster was in maintenance mode.
200
  const std::string MaintenanceMode = "maintenance_mode";
201
  // The request was rejected by the router filter because the DROP_OVERLOAD configuration.
202
  const std::string DropOverload = "drop_overload";
203
  // The request was rejected by the router filter because the DROP_OVERLOAD configuration is set to
204
  // 100%.
205
  const std::string UnconditionalDropOverload = "unconditional_drop_overload";
206
  // The request was rejected by the router filter because there was no healthy upstream found.
207
  const std::string NoHealthyUpstream = "no_healthy_upstream";
208
  // The request was forwarded upstream but the response timed out.
209
  const std::string ResponseTimeout = "response_timeout";
210
  // The final upstream try timed out.
211
  const std::string UpstreamPerTryTimeout = "upstream_per_try_timeout";
212
  // The final upstream try idle timed out.
213
  const std::string UpstreamPerTryIdleTimeout = "upstream_per_try_idle_timeout";
214
  // The request was destroyed because of user defined max stream duration.
215
  const std::string UpstreamMaxStreamDurationReached = "upstream_max_stream_duration_reached";
216
  // The upstream connection was reset before a response was started. This
217
  // will generally be accompanied by details about why the reset occurred.
218
  const std::string EarlyUpstreamReset = "upstream_reset_before_response_started";
219
  // The upstream connection was reset after a response was started. This
220
  // will generally be accompanied by details about why the reset occurred but
221
  // indicates that original "success" headers may have been sent downstream
222
  // despite the subsequent failure.
223
  const std::string LateUpstreamReset = "upstream_reset_after_response_started";
224
  // The request was rejected due to no matching filter chain.
225
  const std::string FilterChainNotFound = "filter_chain_not_found";
226
  // The client disconnected unexpectedly.
227
  const std::string DownstreamRemoteDisconnect = "downstream_remote_disconnect";
228
  // The client connection was locally closed for the given reason.
229
  const std::string DownstreamLocalDisconnect = "downstream_local_disconnect({})";
230
  // The max connection duration was exceeded.
231
  const std::string DurationTimeout = "duration_timeout";
232
  // The max request downstream header duration was exceeded.
233
  const std::string DownstreamHeaderTimeout = "downstream_header_timeout";
234
  // The response was generated by the admin filter.
235
  const std::string AdminFilterResponse = "admin_filter_response";
236
  // The original stream was replaced with an internal redirect.
237
  const std::string InternalRedirect = "internal_redirect";
238
  // The request was rejected because configured filters erroneously removed required request
239
  // headers.
240
  const std::string FilterRemovedRequiredRequestHeaders = "filter_removed_required_request_headers";
241
  // The request was rejected because configured filters erroneously removed required response
242
  // headers.
243
  const std::string FilterRemovedRequiredResponseHeaders =
244
      "filter_removed_required_response_headers";
245
  // The request was rejected because the original IP couldn't be detected.
246
  const std::string OriginalIPDetectionFailed = "rejecting_because_detection_failed";
247
  // A filter called addDecodedData at the wrong point in the filter chain.
248
  const std::string FilterAddedInvalidRequestData = "filter_added_invalid_request_data";
249
  // A filter called addDecodedData at the wrong point in the filter chain.
250
  const std::string FilterAddedInvalidResponseData = "filter_added_invalid_response_data";
251
  // Data was received for a CONNECT request before 200 response headers were sent.
252
  const std::string EarlyConnectData = "early_connect_data";
253
  // Changes or additions to details should be reflected in
254
  // docs/root/configuration/http/http_conn_man/response_code_details.rst
255
};
256

            
257
using ResponseCodeDetails = ConstSingleton<ResponseCodeDetailValues>;
258

            
259
/**
260
 * Type of connection close which is detected from the socket.
261
 */
262
enum class DetectedCloseType {
263
  Normal,      // The normal socket close from Envoy's connection perspective.
264
  LocalReset,  // The local reset initiated from Envoy.
265
  RemoteReset, // The peer reset detected by the connection.
266
};
267

            
268
/**
269
 * Constants for the locally closing a connection. This is used in response code
270
 * details field of StreamInfo for details sent by core (non-extension) code.
271
 * This is incomplete as some details may be
272
 *
273
 * Custom extensions can define additional values provided they are appropriately
274
 * scoped to avoid collisions.
275
 */
276
struct LocalCloseReasonValues {
277
  const std::string DeferredCloseOnDrainedConnection = "deferred_close_on_drained_connection";
278
  const std::string IdleTimeoutOnConnection = "on_idle_timeout";
279
  const std::string CloseForConnectRequestOrTcpTunneling =
280
      "close_for_connect_request_or_tcp_tunneling";
281
  const std::string Http2PingTimeout = "http2_ping_timeout";
282
  const std::string Http2ConnectionProtocolViolation = "http2_connection_protocol_violation";
283
  const std::string TransportSocketTimeout = "transport_socket_timeout";
284
  const std::string TriggeredDelayedCloseTimeout = "triggered_delayed_close_timeout";
285
  const std::string TcpProxyInitializationFailure = "tcp_initializion_failure:";
286
  const std::string TcpSessionIdleTimeout = "tcp_session_idle_timeout";
287
  const std::string MaxConnectionDurationReached = "max_connection_duration_reached";
288
  const std::string ClosingUpstreamTcpDueToDownstreamRemoteClose =
289
      "closing_upstream_tcp_connection_due_to_downstream_remote_close";
290
  const std::string ClosingUpstreamTcpDueToDownstreamLocalClose =
291
      "closing_upstream_tcp_connection_due_to_downstream_local_close";
292
  const std::string ClosingUpstreamTcpDueToDownstreamResetClose =
293
      "closing_upstream_tcp_connection_due_to_downstream_reset_close";
294
  const std::string NonPooledTcpConnectionHostHealthFailure =
295
      "non_pooled_tcp_connection_host_health_failure";
296
  const std::string BufferHighWatermarkTimeout = "buffer_high_watermark_timeout_reached";
297
};
298

            
299
using LocalCloseReasons = ConstSingleton<LocalCloseReasonValues>;
300

            
301
struct UpstreamTiming {
302
  /**
303
   * Records the latency from when the upstream request was created to when the
304
   * connection pool callbacks (either success of failure were triggered).
305
   */
306
49208
  void recordConnectionPoolCallbackLatency(MonotonicTime start, TimeSource& time_source) {
307
49208
    ASSERT(!connection_pool_callback_latency_);
308
49208
    connection_pool_callback_latency_ =
309
49208
        std::chrono::duration_cast<std::chrono::nanoseconds>(time_source.monotonicTime() - start);
310
49208
  }
311

            
312
  /**
313
   * Sets the time when the first byte of the request was sent upstream.
314
   */
315
46241
  void onFirstUpstreamTxByteSent(TimeSource& time_source) {
316
46241
    ASSERT(!first_upstream_tx_byte_sent_);
317
46241
    first_upstream_tx_byte_sent_ = time_source.monotonicTime();
318
46241
  }
319

            
320
  /**
321
   * Sets the time when the last byte of the request was sent upstream.
322
   */
323
39431
  void onLastUpstreamTxByteSent(TimeSource& time_source) {
324
39431
    ASSERT(!last_upstream_tx_byte_sent_);
325
39431
    last_upstream_tx_byte_sent_ = time_source.monotonicTime();
326
39431
  }
327

            
328
  /**
329
   * Sets the time when the first byte of the response is received from upstream.
330
   */
331
40373
  void onFirstUpstreamRxByteReceived(TimeSource& time_source) {
332
40373
    ASSERT(!first_upstream_rx_byte_received_);
333
40373
    first_upstream_rx_byte_received_ = time_source.monotonicTime();
334
40373
  }
335

            
336
  /**
337
   * Sets the time when the last byte of the response is received from upstream.
338
   */
339
37795
  void onLastUpstreamRxByteReceived(TimeSource& time_source) {
340
37795
    ASSERT(!last_upstream_rx_byte_received_);
341
37795
    last_upstream_rx_byte_received_ = time_source.monotonicTime();
342
37795
  }
343

            
344
  /**
345
   * Sets the time when the first byte of the response body is received from upstream.
346
   */
347
15447
  void onFirstUpstreamRxBodyByteReceived(TimeSource& time_source) {
348
15447
    ASSERT(!first_upstream_rx_body_byte_received_);
349
15447
    first_upstream_rx_body_byte_received_ = time_source.monotonicTime();
350
15447
  }
351

            
352
56711
  void onUpstreamConnectStart(TimeSource& time_source) {
353
56711
    ASSERT(!upstream_connect_start_);
354
56711
    upstream_connect_start_ = time_source.monotonicTime();
355
56711
  }
356

            
357
56243
  void onUpstreamConnectComplete(TimeSource& time_source) {
358
56243
    upstream_connect_complete_ = time_source.monotonicTime();
359
56243
  }
360

            
361
4019
  void onUpstreamHandshakeComplete(TimeSource& time_source) {
362
4019
    upstream_handshake_complete_ = time_source.monotonicTime();
363
4019
  }
364

            
365
2
  absl::optional<MonotonicTime> upstreamHandshakeComplete() const {
366
2
    return upstream_handshake_complete_;
367
2
  }
368

            
369
2988
  absl::optional<std::chrono::nanoseconds> connectionPoolCallbackLatency() const {
370
2988
    return connection_pool_callback_latency_;
371
2988
  }
372

            
373
  absl::optional<std::chrono::nanoseconds> connection_pool_callback_latency_;
374
  absl::optional<MonotonicTime> first_upstream_tx_byte_sent_;
375
  absl::optional<MonotonicTime> last_upstream_tx_byte_sent_;
376
  absl::optional<MonotonicTime> first_upstream_rx_byte_received_;
377
  absl::optional<MonotonicTime> last_upstream_rx_byte_received_;
378
  absl::optional<MonotonicTime> first_upstream_rx_body_byte_received_;
379

            
380
  absl::optional<MonotonicTime> upstream_connect_start_;
381
  absl::optional<MonotonicTime> upstream_connect_complete_;
382
  absl::optional<MonotonicTime> upstream_handshake_complete_;
383
};
384

            
385
struct DownstreamTiming {
386
95165
  void setValue(absl::string_view key, MonotonicTime value) { timings_[key] = value; }
387

            
388
1734
  absl::optional<MonotonicTime> getValue(absl::string_view value) const {
389
1734
    auto ret = timings_.find(value);
390
1734
    if (ret == timings_.end()) {
391
152
      return {};
392
152
    }
393
1582
    return ret->second;
394
1734
  }
395

            
396
229097
  absl::optional<MonotonicTime> lastDownstreamRxByteReceived() const {
397
229097
    return last_downstream_rx_byte_received_;
398
229097
  }
399
352
  absl::optional<MonotonicTime> firstDownstreamTxByteSent() const {
400
352
    return first_downstream_tx_byte_sent_;
401
352
  }
402
371
  absl::optional<MonotonicTime> lastDownstreamTxByteSent() const {
403
371
    return last_downstream_tx_byte_sent_;
404
371
  }
405
24
  absl::optional<MonotonicTime> downstreamHandshakeComplete() const {
406
24
    return downstream_handshake_complete_;
407
24
  }
408
24
  absl::optional<MonotonicTime> lastDownstreamAckReceived() const {
409
24
    return last_downstream_ack_received_;
410
24
  }
411
3
  absl::optional<MonotonicTime> lastDownstreamHeaderRxByteReceived() const {
412
3
    return last_downstream_header_rx_byte_received_;
413
3
  }
414

            
415
85049
  void onLastDownstreamRxByteReceived(TimeSource& time_source) {
416
85049
    ASSERT(!last_downstream_rx_byte_received_);
417
85049
    last_downstream_rx_byte_received_ = time_source.monotonicTime();
418
85049
  }
419
47306
  void onFirstDownstreamTxByteSent(TimeSource& time_source) {
420
47306
    ASSERT(!first_downstream_tx_byte_sent_);
421
47306
    first_downstream_tx_byte_sent_ = time_source.monotonicTime();
422
47306
  }
423
46178
  void onLastDownstreamTxByteSent(TimeSource& time_source) {
424
46178
    ASSERT(!last_downstream_tx_byte_sent_);
425
46178
    last_downstream_tx_byte_sent_ = time_source.monotonicTime();
426
46178
  }
427
3831
  void onDownstreamHandshakeComplete(TimeSource& time_source) {
428
    // An existing value can be overwritten, e.g. in resumption case.
429
3831
    downstream_handshake_complete_ = time_source.monotonicTime();
430
3831
  }
431
1474
  void onLastDownstreamAckReceived(TimeSource& time_source) {
432
1474
    ASSERT(!last_downstream_ack_received_);
433
1474
    last_downstream_ack_received_ = time_source.monotonicTime();
434
1474
  }
435
91201
  void onLastDownstreamHeaderRxByteReceived(TimeSource& time_source) {
436
91201
    ASSERT(!last_downstream_header_rx_byte_received_);
437
91201
    last_downstream_header_rx_byte_received_ = time_source.monotonicTime();
438
91201
  }
439

            
440
  absl::flat_hash_map<std::string, MonotonicTime> timings_;
441
  // The time when the last byte of the request was received.
442
  absl::optional<MonotonicTime> last_downstream_rx_byte_received_;
443
  // The time when the first byte of the response was sent downstream.
444
  absl::optional<MonotonicTime> first_downstream_tx_byte_sent_;
445
  // The time when the last byte of the response was sent downstream.
446
  absl::optional<MonotonicTime> last_downstream_tx_byte_sent_;
447
  // The time the TLS handshake completed. Set at connection level.
448
  absl::optional<MonotonicTime> downstream_handshake_complete_;
449
  // The time the final ack was received from the client.
450
  absl::optional<MonotonicTime> last_downstream_ack_received_;
451
  // The time when the last header byte was received.
452
  absl::optional<MonotonicTime> last_downstream_header_rx_byte_received_;
453
};
454

            
455
// Measure the number of bytes sent and received for a stream.
456
struct BytesMeter {
457
524606
  BytesMeter() = default;
458
4179
  uint64_t wireBytesSent() const { return wire_bytes_sent_; }
459
790079
  uint64_t wireBytesReceived() const { return wire_bytes_received_; }
460
590
  uint64_t headerBytesSent() const { return header_bytes_sent_; }
461
83528
  uint64_t headerBytesReceived() const { return header_bytes_received_; }
462
16
  uint64_t decompressedHeaderBytesSent() const { return decompressed_header_bytes_sent_; }
463
13
  uint64_t decompressedHeaderBytesReceived() const { return decompressed_header_bytes_received_; }
464

            
465
504512
  void addHeaderBytesSent(uint64_t added_bytes) { header_bytes_sent_ += added_bytes; }
466
1276660
  void addHeaderBytesReceived(uint64_t added_bytes) { header_bytes_received_ += added_bytes; }
467
509487
  void addDecompressedHeaderBytesSent(uint64_t added_bytes) {
468
509487
    decompressed_header_bytes_sent_ += added_bytes;
469
509487
  }
470
854187
  void addDecompressedHeaderBytesReceived(uint64_t added_bytes) {
471
854187
    decompressed_header_bytes_received_ += added_bytes;
472
854187
  }
473
1341384
  void addWireBytesSent(uint64_t added_bytes) { wire_bytes_sent_ += added_bytes; }
474
1315531
  void addWireBytesReceived(uint64_t added_bytes) { wire_bytes_received_ += added_bytes; }
475

            
476
  struct BytesSnapshot {
477
    SystemTime snapshot_time;
478
    uint64_t header_bytes_sent{};
479
    uint64_t header_bytes_received{};
480
    uint64_t decompressed_header_bytes_sent{};
481
    uint64_t decompressed_header_bytes_received{};
482
    uint64_t wire_bytes_sent{};
483
    uint64_t wire_bytes_received{};
484
  };
485
36
  void takeDownstreamPeriodicLoggingSnapshot(const SystemTime& snapshot_time) {
486
36
    downstream_periodic_logging_bytes_snapshot_ = std::make_unique<BytesSnapshot>();
487

            
488
36
    downstream_periodic_logging_bytes_snapshot_->snapshot_time = snapshot_time;
489
36
    downstream_periodic_logging_bytes_snapshot_->header_bytes_sent = header_bytes_sent_;
490
36
    downstream_periodic_logging_bytes_snapshot_->header_bytes_received = header_bytes_received_;
491
36
    downstream_periodic_logging_bytes_snapshot_->decompressed_header_bytes_sent =
492
36
        decompressed_header_bytes_sent_;
493
36
    downstream_periodic_logging_bytes_snapshot_->decompressed_header_bytes_received =
494
36
        decompressed_header_bytes_received_;
495
36
    downstream_periodic_logging_bytes_snapshot_->wire_bytes_sent = wire_bytes_sent_;
496
36
    downstream_periodic_logging_bytes_snapshot_->wire_bytes_received = wire_bytes_received_;
497
36
  }
498
6
  void takeUpstreamPeriodicLoggingSnapshot(const SystemTime& snapshot_time) {
499
6
    upstream_periodic_logging_bytes_snapshot_ = std::make_unique<BytesSnapshot>();
500

            
501
6
    upstream_periodic_logging_bytes_snapshot_->snapshot_time = snapshot_time;
502
6
    upstream_periodic_logging_bytes_snapshot_->header_bytes_sent = header_bytes_sent_;
503
6
    upstream_periodic_logging_bytes_snapshot_->header_bytes_received = header_bytes_received_;
504
6
    upstream_periodic_logging_bytes_snapshot_->decompressed_header_bytes_sent =
505
6
        decompressed_header_bytes_sent_;
506
6
    upstream_periodic_logging_bytes_snapshot_->decompressed_header_bytes_received =
507
6
        decompressed_header_bytes_received_;
508
6
    upstream_periodic_logging_bytes_snapshot_->wire_bytes_sent = wire_bytes_sent_;
509
6
    upstream_periodic_logging_bytes_snapshot_->wire_bytes_received = wire_bytes_received_;
510
6
  }
511
7
  const BytesSnapshot* bytesAtLastDownstreamPeriodicLog() const {
512
7
    return downstream_periodic_logging_bytes_snapshot_.get();
513
7
  }
514
6
  const BytesSnapshot* bytesAtLastUpstreamPeriodicLog() const {
515
6
    return upstream_periodic_logging_bytes_snapshot_.get();
516
6
  }
517
  // Adds the bytes from `existing` to `this`.
518
  // Additionally, captures the snapshots on `existing` and adds them to `this`.
519
93961
  void captureExistingBytesMeter(BytesMeter& existing) {
520
    // Add bytes accumulated on `this` to the pre-existing periodic bytes collectors.
521
93961
    if (existing.downstream_periodic_logging_bytes_snapshot_) {
522
      downstream_periodic_logging_bytes_snapshot_ =
523
          std::move(existing.downstream_periodic_logging_bytes_snapshot_);
524
      existing.downstream_periodic_logging_bytes_snapshot_ = nullptr;
525
    }
526
93961
    if (existing.upstream_periodic_logging_bytes_snapshot_) {
527
      upstream_periodic_logging_bytes_snapshot_ =
528
          std::move(existing.upstream_periodic_logging_bytes_snapshot_);
529
      existing.upstream_periodic_logging_bytes_snapshot_ = nullptr;
530
    }
531

            
532
    // Accumulate existing bytes.
533
93961
    header_bytes_sent_ += existing.header_bytes_sent_;
534
93961
    header_bytes_received_ += existing.header_bytes_received_;
535
93961
    decompressed_header_bytes_sent_ += existing.decompressed_header_bytes_sent_;
536
93961
    decompressed_header_bytes_received_ += existing.decompressed_header_bytes_received_;
537
93961
    wire_bytes_sent_ += existing.wire_bytes_sent_;
538
93961
    wire_bytes_received_ += existing.wire_bytes_received_;
539
93961
  }
540

            
541
private:
542
  uint64_t header_bytes_sent_{};
543
  uint64_t header_bytes_received_{};
544
  uint64_t decompressed_header_bytes_sent_{};
545
  uint64_t decompressed_header_bytes_received_{};
546
  uint64_t wire_bytes_sent_{};
547
  uint64_t wire_bytes_received_{};
548
  std::unique_ptr<BytesSnapshot> downstream_periodic_logging_bytes_snapshot_;
549
  std::unique_ptr<BytesSnapshot> upstream_periodic_logging_bytes_snapshot_;
550
};
551

            
552
using BytesMeterSharedPtr = std::shared_ptr<BytesMeter>;
553

            
554
class UpstreamInfo {
555
public:
556
130202
  virtual ~UpstreamInfo() = default;
557

            
558
  /**
559
   * Dump the upstream info to the specified ostream.
560
   *
561
   * @param os the ostream to dump state to
562
   * @param indent_level the depth, for pretty-printing.
563
   *
564
   * This function is called on Envoy fatal errors so should avoid memory allocation.
565
   */
566
  virtual void dumpState(std::ostream& os, int indent_level = 0) const PURE;
567

            
568
  /**
569
   * @param connection ID of the upstream connection.
570
   */
571
  virtual void setUpstreamConnectionId(uint64_t id) PURE;
572

            
573
  /**
574
   * @return the ID of the upstream connection, or absl::nullopt if not available.
575
   */
576
  virtual absl::optional<uint64_t> upstreamConnectionId() const PURE;
577

            
578
  /**
579
   * @param interface name of the upstream connection's local socket.
580
   */
581
  virtual void setUpstreamInterfaceName(absl::string_view interface_name) PURE;
582

            
583
  /**
584
   * @return interface name of the upstream connection's local socket, or absl::nullopt if not
585
   * available.
586
   */
587
  virtual absl::optional<absl::string_view> upstreamInterfaceName() const PURE;
588

            
589
  /**
590
   * @param connection_info sets the upstream ssl connection.
591
   */
592
  virtual void
593
  setUpstreamSslConnection(const Ssl::ConnectionInfoConstSharedPtr& ssl_connection_info) PURE;
594

            
595
  /**
596
   * @return the upstream SSL connection. This will be nullptr if the upstream
597
   * connection does not use SSL.
598
   */
599
  virtual Ssl::ConnectionInfoConstSharedPtr upstreamSslConnection() const PURE;
600

            
601
  /*
602
   * @return the upstream timing for this stream
603
   * */
604
  virtual UpstreamTiming& upstreamTiming() PURE;
605
  virtual const UpstreamTiming& upstreamTiming() const PURE;
606

            
607
  /**
608
   * @param upstream_local_address sets the local address of the upstream connection. Note that it
609
   * can be different than the local address of the downstream connection.
610
   */
611
  virtual void setUpstreamLocalAddress(
612
      const Network::Address::InstanceConstSharedPtr& upstream_local_address) PURE;
613

            
614
  /**
615
   * @return the upstream local address.
616
   */
617
  virtual const Network::Address::InstanceConstSharedPtr& upstreamLocalAddress() const PURE;
618

            
619
  /**
620
   * @param upstream_remote_address sets the remote address of the upstream connection.
621
   */
622
  virtual void setUpstreamRemoteAddress(
623
      const Network::Address::InstanceConstSharedPtr& upstream_remote_address) PURE;
624

            
625
  /**
626
   * @return the upstream remote address.
627
   */
628
  virtual const Network::Address::InstanceConstSharedPtr& upstreamRemoteAddress() const PURE;
629

            
630
  /**
631
   * @param failure_reason the upstream transport failure reason.
632
   */
633
  virtual void setUpstreamTransportFailureReason(absl::string_view failure_reason) PURE;
634

            
635
  /**
636
   * @return const std::string& the upstream transport failure reason, e.g. certificate validation
637
   *         failed.
638
   */
639
  virtual const std::string& upstreamTransportFailureReason() const PURE;
640

            
641
  /**
642
   * @param close_type the upstream detected close type.
643
   */
644
  virtual void setUpstreamDetectedCloseType(DetectedCloseType close_type) PURE;
645

            
646
  /**
647
   * @return StreamInfo::DetectedCloseType the upstream detected close type.
648
   */
649
  virtual DetectedCloseType upstreamDetectedCloseType() const PURE;
650

            
651
  /**
652
   * @param reason the upstream local close reason.
653
   */
654
  virtual void setUpstreamLocalCloseReason(absl::string_view reason) PURE;
655

            
656
  /**
657
   * @return absl::string_view the upstream local close reason, if local close did not occur an
658
   * empty string view is returned.
659
   */
660
  virtual absl::string_view upstreamLocalCloseReason() const PURE;
661

            
662
  /**
663
   * @param host the selected upstream host for the request.
664
   */
665
  virtual void setUpstreamHost(Upstream::HostDescriptionConstSharedPtr host) PURE;
666

            
667
  /**
668
   * @return upstream host description.
669
   */
670
  virtual Upstream::HostDescriptionConstSharedPtr upstreamHost() const PURE;
671

            
672
  /**
673
   * Filter State object to be shared between upstream and downstream filters.
674
   * @param pointer to upstream connections filter state.
675
   * @return pointer to filter state to be used by upstream connections.
676
   */
677
  virtual const FilterStateSharedPtr& upstreamFilterState() const PURE;
678
  virtual void setUpstreamFilterState(const FilterStateSharedPtr& filter_state) PURE;
679

            
680
  /**
681
   * Getters and setters for the number of streams started on this connection.
682
   * For upstream connections this is updated as streams are created.
683
   * For downstream connections this is latched at the time the upstream stream
684
   * is assigned.
685
   */
686
  virtual void setUpstreamNumStreams(uint64_t num_streams) PURE;
687
  virtual uint64_t upstreamNumStreams() const PURE;
688

            
689
  virtual void setUpstreamProtocol(Http::Protocol protocol) PURE;
690
  virtual absl::optional<Http::Protocol> upstreamProtocol() const PURE;
691

            
692
  /**
693
   * Add a host to the list of upstream hosts that were attempted for this request.
694
   * This is useful for tracking retry behavior in access logs.
695
   * @param host the host description that was attempted.
696
   */
697
  virtual void addUpstreamHostAttempted(Upstream::HostDescriptionConstSharedPtr host) PURE;
698

            
699
  /**
700
   * @return the list of all upstream hosts that were attempted for this request,
701
   * in the order they were attempted. This includes both successful and failed attempts.
702
   */
703
  virtual const std::vector<Upstream::HostDescriptionConstSharedPtr>&
704
  upstreamHostsAttempted() const PURE;
705

            
706
  /**
707
   * @return the list of all upstream connection IDs that were attempted for this request,
708
   * in the order they were attempted. This helps identify connection reuse patterns.
709
   */
710
  virtual const std::vector<uint64_t>& upstreamConnectionIdsAttempted() const PURE;
711
};
712

            
713
/**
714
 * Additional information about a completed request for logging.
715
 */
716
class StreamInfo {
717
public:
718
290983
  virtual ~StreamInfo() = default;
719

            
720
  /**
721
   * @param response_flag the response flag. Each filter can set independent response flags. The
722
   * flags are accumulated.
723
   */
724
  virtual void setResponseFlag(ResponseFlag response_flag) PURE;
725

            
726
  /**
727
   * @param code the HTTP response code to set for this request.
728
   */
729
  virtual void setResponseCode(uint32_t code) PURE;
730

            
731
  /**
732
   * @param rc_details the response code details string to set for this request. It should not
733
   * contain any empty or space characters (' ', '\t', '\f', '\v', '\n', '\r'). See
734
   * ResponseCodeDetailValues above for well-known constants.
735
   */
736
  virtual void setResponseCodeDetails(absl::string_view rc_details) PURE;
737

            
738
  /**
739
   * @param connection_termination_details the termination details string to set for this
740
   * connection.
741
   */
742
  virtual void
743
  setConnectionTerminationDetails(absl::string_view connection_termination_details) PURE;
744

            
745
  /*
746
   * @param short string type flag to indicate the noteworthy event of this stream. Mutliple flags
747
   * could be added and will be concatenated with comma. It should not contain any empty or space
748
   * characters (' ', '\t', '\f', '\v', '\n', '\r').
749
   *
750
   * The short string should not duplicate with the any registered response flags.
751
   */
752
  virtual void addCustomFlag(absl::string_view) PURE;
753

            
754
  /**
755
   * @return std::string& the name of the route. The name is get from the route() and it is
756
   *         empty if there is no route.
757
   */
758
  virtual const std::string& getRouteName() const PURE;
759

            
760
  /**
761
   * @param std::string name denotes the name of the virtual cluster.
762
   */
763
  virtual void setVirtualClusterName(const absl::optional<std::string>& name) PURE;
764

            
765
  /**
766
   * @return std::string& the name of the virtual cluster which got matched.
767
   */
768
  virtual const absl::optional<std::string>& virtualClusterName() const PURE;
769

            
770
  /**
771
   * @param bytes_received denotes number of bytes to add to total received bytes.
772
   */
773
  virtual void addBytesReceived(uint64_t bytes_received) PURE;
774

            
775
  /**
776
   * @return the number of body bytes received by the stream.
777
   */
778
  virtual uint64_t bytesReceived() const PURE;
779

            
780
  /**
781
   * @param bytes_retransmitted denotes number of bytes to add to total retransmitted bytes.
782
   */
783
  virtual void addBytesRetransmitted(uint64_t bytes_retransmitted) PURE;
784

            
785
  /**
786
   * @return the number of bytes retransmitted by the stream.
787
   */
788
  virtual uint64_t bytesRetransmitted() const PURE;
789

            
790
  /**
791
   * @param packets_retransmitted denotes number of packets to add to total retransmitted packets.
792
   */
793
  virtual void addPacketsRetransmitted(uint64_t packets_retransmitted) PURE;
794

            
795
  /**
796
   * @return the number of packets retransmitted by the stream.
797
   */
798
  virtual uint64_t packetsRetransmitted() const PURE;
799

            
800
  /**
801
   * @return the protocol of the request.
802
   */
803
  virtual absl::optional<Http::Protocol> protocol() const PURE;
804

            
805
  /**
806
   * @param protocol the request's protocol.
807
   */
808
  virtual void protocol(Http::Protocol protocol) PURE;
809

            
810
  /**
811
   * @return the response code.
812
   */
813
  virtual absl::optional<uint32_t> responseCode() const PURE;
814

            
815
  /**
816
   * @return the response code details.
817
   */
818
  virtual const absl::optional<std::string>& responseCodeDetails() const PURE;
819

            
820
  /**
821
   * @return the termination details of the connection.
822
   */
823
  virtual const absl::optional<std::string>& connectionTerminationDetails() const PURE;
824

            
825
  /**
826
   * @return the time that the first byte of the request was received.
827
   */
828
  virtual SystemTime startTime() const PURE;
829

            
830
  /**
831
   * @return the monotonic time that the first byte of the request was received. Duration
832
   * calculations should be made relative to this value.
833
   */
834
  virtual MonotonicTime startTimeMonotonic() const PURE;
835

            
836
  /**
837
   * @return returns the time source.
838
   */
839
  virtual TimeSource& timeSource() const PURE;
840

            
841
  /**
842
   * Sets the upstream information for this stream.
843
   */
844
  virtual void setUpstreamInfo(std::shared_ptr<UpstreamInfo>) PURE;
845

            
846
  /**
847
   * Returns the upstream information for this stream.
848
   */
849
  virtual std::shared_ptr<UpstreamInfo> upstreamInfo() PURE;
850
  virtual OptRef<const UpstreamInfo> upstreamInfo() const PURE;
851

            
852
  /**
853
   * @return the current duration of the request, or the total duration of the request, if ended.
854
   */
855
  virtual absl::optional<std::chrono::nanoseconds> currentDuration() const PURE;
856

            
857
  /**
858
   * @return the total duration of the request (i.e., when the request's ActiveStream is destroyed)
859
   * and may be longer than lastDownstreamTxByteSent.
860
   */
861
  virtual absl::optional<std::chrono::nanoseconds> requestComplete() const PURE;
862

            
863
  /**
864
   * Sets the end time for the request. This method is called once the request has been fully
865
   * completed (i.e., when the request's ActiveStream is destroyed).
866
   */
867
  virtual void onRequestComplete() PURE;
868

            
869
  /**
870
   * @return the downstream timing information.
871
   */
872
  virtual DownstreamTiming& downstreamTiming() PURE;
873
  virtual OptRef<const DownstreamTiming> downstreamTiming() const PURE;
874

            
875
  /**
876
   * @param bytes_sent denotes the number of bytes to add to total sent bytes.
877
   */
878
  virtual void addBytesSent(uint64_t bytes_sent) PURE;
879

            
880
  /**
881
   * @return the number of body bytes sent in the response.
882
   */
883
  virtual uint64_t bytesSent() const PURE;
884

            
885
  /**
886
   * @return whether response flag is set or not.
887
   */
888
  virtual bool hasResponseFlag(ResponseFlag response_flag) const PURE;
889

            
890
  /**
891
   * @return whether any response flag is set or not.
892
   */
893
  virtual bool hasAnyResponseFlag() const PURE;
894

            
895
  /**
896
   * @return all response flags that are set.
897
   */
898
  virtual absl::Span<const ResponseFlag> responseFlags() const PURE;
899

            
900
  /**
901
   * @return response flags encoded as an integer. Every bit of the integer is used to represent a
902
   * flag. Only flags that are declared in the enum CoreResponseFlag type are supported.
903
   */
904
  virtual uint64_t legacyResponseFlags() const PURE;
905

            
906
  /**
907
   * @return all stream flags that are added.
908
   */
909
  virtual absl::string_view customFlags() const PURE;
910

            
911
  /**
912
   * @return whether the request is a health check request or not.
913
   */
914
  virtual bool healthCheck() const PURE;
915

            
916
  /**
917
   * @param is_health_check whether the request is a health check request or not.
918
   */
919
  virtual void healthCheck(bool is_health_check) PURE;
920

            
921
  /**
922
   * @return the downstream connection info provider.
923
   */
924
  virtual const Network::ConnectionInfoProvider& downstreamAddressProvider() const PURE;
925

            
926
  /**
927
   * @return const Router::RouteConstSharedPtr Get the route selected for this request.
928
   */
929
  virtual Router::RouteConstSharedPtr route() const PURE;
930

            
931
  /**
932
   * @return const Router::VirtualHostConstSharedPtr& Get the virtual host selected for this
933
   * request.
934
   */
935
  virtual const Router::VirtualHostConstSharedPtr& virtualHost() const PURE;
936

            
937
  /**
938
   * @return const envoy::config::core::v3::Metadata& the dynamic metadata associated with this
939
   * request
940
   */
941
  virtual envoy::config::core::v3::Metadata& dynamicMetadata() PURE;
942
  virtual const envoy::config::core::v3::Metadata& dynamicMetadata() const PURE;
943

            
944
  /**
945
   * @param name the namespace used in the metadata in reverse DNS format, for example:
946
   * envoy.test.my_filter.
947
   * @param value the struct to set on the namespace. A merge will be performed with new values for
948
   * the same key overriding existing.
949
   */
950
  virtual void setDynamicMetadata(const std::string& name, const Protobuf::Struct& value) PURE;
951

            
952
  /**
953
   * @param name the namespace used in the metadata in reverse DNS format, for example:
954
   * envoy.test.my_filter.
955
   * @param value of type protobuf any to set on the namespace.
956
   */
957
  virtual void setDynamicTypedMetadata(const std::string& name, const Protobuf::Any& value) PURE;
958

            
959
  /**
960
   * Object on which filters can share data on a per-request basis. For singleton data objects, only
961
   * one filter can produce a named data object. List data objects can be updated by multiple
962
   * filters (append only). Both object types can be consumed by multiple filters.
963
   * @return the filter state associated with this request.
964
   */
965
  virtual const FilterStateSharedPtr& filterState() PURE;
966
  virtual const FilterState& filterState() const PURE;
967

            
968
  /**
969
   * @param headers request headers.
970
   */
971
  virtual void setRequestHeaders(const Http::RequestHeaderMap& headers) PURE;
972

            
973
  /**
974
   * @return request headers.
975
   */
976
  virtual const Http::RequestHeaderMap* getRequestHeaders() const PURE;
977

            
978
  /**
979
   * @param Upstream Connection's ClusterInfo.
980
   */
981
  virtual void
982
  setUpstreamClusterInfo(const Upstream::ClusterInfoConstSharedPtr& upstream_cluster_info) PURE;
983

            
984
  /**
985
   * @return Upstream Connection's ClusterInfo.
986
   * This returns an optional to differentiate between unset(absl::nullopt),
987
   * no route or cluster does not exist(nullptr), and set to a valid cluster(not nullptr).
988
   */
989
  virtual absl::optional<Upstream::ClusterInfoConstSharedPtr> upstreamClusterInfo() const PURE;
990

            
991
  /**
992
   * @param provider The unique id implementation this stream uses.
993
   */
994
  virtual void setStreamIdProvider(StreamIdProviderSharedPtr provider) PURE;
995

            
996
  /**
997
   * @return the unique id for this stream if available.
998
   */
999
  virtual OptRef<const StreamIdProvider> getStreamIdProvider() const PURE;
  /**
   * Set the trace reason for the stream.
   */
  virtual void setTraceReason(Tracing::Reason reason) PURE;
  /**
   * @return the trace reason for the stream.
   */
  virtual Tracing::Reason traceReason() const PURE;
  /**
   * @param attempt_count, the number of times the request was attempted upstream.
   */
  virtual void setAttemptCount(uint32_t attempt_count) PURE;
  /**
   * @return the number of times the request was attempted upstream, absl::nullopt if the request
   * was never attempted upstream.
   */
  virtual absl::optional<uint32_t> attemptCount() const PURE;
  /**
   * @return the bytes meter for upstream http stream.
   */
  virtual const BytesMeterSharedPtr& getUpstreamBytesMeter() const PURE;
  /**
   * @return the bytes meter for downstream http stream.
   */
  virtual const BytesMeterSharedPtr& getDownstreamBytesMeter() const PURE;
  /**
   * @param upstream_bytes_meter, the bytes meter for upstream http stream.
   */
  virtual void setUpstreamBytesMeter(const BytesMeterSharedPtr& upstream_bytes_meter) PURE;
  /**
   * @param downstream_bytes_meter, the bytes meter for downstream http stream.
   */
  virtual void setDownstreamBytesMeter(const BytesMeterSharedPtr& downstream_bytes_meter) PURE;
  virtual bool isShadow() const PURE;
  static void syncUpstreamAndDownstreamBytesMeter(StreamInfo& downstream_info,
46858
                                                  StreamInfo& upstream_info) {
46858
    downstream_info.setUpstreamBytesMeter(upstream_info.getUpstreamBytesMeter());
46858
    upstream_info.setDownstreamBytesMeter(downstream_info.getDownstreamBytesMeter());
46858
  }
  /**
   * Dump the info to the specified ostream.
   *
   * @param os the ostream to dump state to
   * @param indent_level the depth, for pretty-printing.
   *
   * This function is called on Envoy fatal errors so should avoid memory allocation.
   */
  virtual void dumpState(std::ostream& os, int indent_level = 0) const PURE;
  /**
   * @return absl::string_view the downstream transport failure reason,
   *         e.g. certificate validation failed.
   */
  virtual absl::string_view downstreamTransportFailureReason() const PURE;
  /**
   * @param failure_reason the downstream transport failure reason.
   */
  virtual void setDownstreamTransportFailureReason(absl::string_view failure_reason) PURE;
  /**
   * @param reason the downstream local close reason.
   */
  virtual void setDownstreamLocalCloseReason(absl::string_view reason) PURE;
  /**
   * @return absl::string_view the downstream local close reason, if local close did not occur an
   * empty string view is returned.
   */
  virtual absl::string_view downstreamLocalCloseReason() const PURE;
  /**
   * @param close_type the downstream detected close type.
   */
  virtual void setDownstreamDetectedCloseType(DetectedCloseType close_type) PURE;
  /**
   * @return DetectedCloseType the downstream detected close type.
   */
  virtual DetectedCloseType downstreamDetectedCloseType() const PURE;
  /**
   * Checked by routing filters before forwarding a request upstream.
   * @return to override the scheme header to match the upstream transport
   * protocol at routing filters.
   */
  virtual bool shouldSchemeMatchUpstream() const PURE;
  /**
   * Called if a filter decides that the scheme should match the upstream transport protocol
   * @param should_match_upstream true to hint to routing filters to override the scheme header
   * to match the upstream transport protocol.
   */
  virtual void setShouldSchemeMatchUpstream(bool should_match_upstream) PURE;
  /**
   * Checked by streams after finishing serving the request.
   * @return bool true if the connection should be drained once this stream has
   * finished sending and receiving.
   */
  virtual bool shouldDrainConnectionUponCompletion() const PURE;
  /**
   * Set the parent for this StreamInfo. This is used to associate the
   * stream info of an async client with the stream info of the downstream
   * connection.
   */
  virtual void setParentStreamInfo(const StreamInfo& parent_stream_info) PURE;
  /**
   * Get the parent for this StreamInfo, if available.
   */
  virtual OptRef<const StreamInfo> parentStreamInfo() const PURE;
  /**
   * Clear the parent for this StreamInfo.
   */
  virtual void clearParentStreamInfo() PURE;
  /**
   * Called if the connection decides to drain itself after serving this request.
   * @param should_drain true to close the connection once this stream has
   * finished sending and receiving.
   */
  virtual void setShouldDrainConnectionUponCompletion(bool should_drain) PURE;
  /**
   * @return the codec level stream ID for the associated stream.
   * This should be implemented to call the codecStreamId() method on the
   * associated Http::Stream object.
   */
  virtual absl::optional<uint32_t> codecStreamId() const PURE;
  /**
   * @param id the codec level stream ID for the associated stream.
   */
  virtual void setCodecStreamId(absl::optional<uint32_t> id) PURE;
};
// An enum representation of the Proxy-Status error space.
enum class ProxyStatusError {
  DnsTimeout,
  DnsError,
  DestinationNotFound,
  DestinationUnavailable,
  DestinationIpProhibited,
  DestinationIpUnroutable,
  ConnectionRefused,
  ConnectionTerminated,
  ConnectionTimeout,
  ConnectionReadTimeout,
  ConnectionWriteTimeout,
  ConnectionLimitReached,
  TlsProtocolError,
  TlsCertificateError,
  TlsAlertReceived,
  HttpRequestError,
  HttpRequestDenied,
  HttpResponseIncomplete,
  HttpResponseHeaderSectionSize,
  HttpResponseHeaderSize,
  HttpResponseBodySize,
  HttpResponseTrailerSectionSize,
  HttpResponseTrailerSize,
  HttpResponseTransferCoding,
  HttpResponseContentCoding,
  HttpResponseTimeout,
  HttpUpgradeFailed,
  HttpProtocolError,
  ProxyInternalResponse,
  ProxyInternalError,
  ProxyConfigurationError,
  ProxyLoopDetected,
  // ATTENTION: MAKE SURE THAT THIS REMAINS EQUAL TO THE LAST FLAG.
  LastProxyStatus = ProxyLoopDetected,
};
} // namespace StreamInfo
} // namespace Envoy