Skip to content

Commit 7290824

Browse files
author
dubious90
authored
Refactor filter configuration to make the different test server filters independent (#855)
This is a followup to #852. In that change, we duplicated ResponseOptions onto separate DynamicDelayConfiguration and TimeTrackingConfiguration protos. However, this resulted in many fields on those protos that were not relevant to each filter. In this PR, we make it so that only the relevant fields exist on each proto. Resulting changes: 1. Moved DynamicDelayConfiguration and TimeTrackingConfiguration into their own files, and moved their fields into those protos directly. 2. In order to make request headers still work, there is now manual logic for taking in a ResponseOptions proto via json and cherrypicking the fields relevant to each filter. 3. The generic method computeEffectiveConfiguration was moved to each filter's anonymous namespace. 4. All configs, tests, and markdown files updated to use the new protos. 5. Some tests have been removed that are no longer necessary, or never provided additional coverage, including some that are less feasible now. - HeaderMerge was removed, but everything it tested for was moved into new unit tests of MergeJsonConfig. Signed-off-by: Nathan Perry <[email protected]>
1 parent 28955cd commit 7290824

30 files changed

+540
-260
lines changed

CHANGELOG.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Changelog
2+
3+
All breaking changes to this project will be documented in this file, most
4+
recent changes at the top.
5+
6+
## 0.5.0
7+
8+
In an effort to clean up the previous change and improve it, we re-modified the
9+
dynamic-delay and time-tracking filters to extricate their configuration
10+
entirely from
11+
[nighthawk.server.ResponseOptions](https://github.com/envoyproxy/nighthawk/blob/main/api/server/response_options.proto). The new configurations are:
12+
13+
- [nighthawk.server.DynamicDelayConfiguration](https://github.com/envoyproxy/nighthawk/blob/main/api/server/dynamic_delay.proto)
14+
- [nighthawk.server.TimeTrackingConfiguration](https://github.com/envoyproxy/nighthawk/blob/main/api/server/time_tracking.proto)
15+
16+
If you are converting from the previous configuration with
17+
`experimental_response_options`, such as:
18+
19+
```
20+
http_filters:
21+
- name: time-tracking
22+
typed_config:
23+
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
24+
experimental_response_options:
25+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
26+
- name: dynamic-delay
27+
typed_config:
28+
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
29+
experimental_response_options:
30+
static_delay: 1.33s
31+
- name: test-server
32+
typed_config:
33+
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
34+
response_body_size: 10
35+
static_delay: 1.33s
36+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
37+
v3_response_headers:
38+
- { header: { key: "x-nh", value: "1"}}
39+
```
40+
41+
You should now specify only fields related to each filter in their
42+
configuration, and you can do so at the top-level of those protos:
43+
44+
```
45+
http_filters:
46+
- name: time-tracking
47+
typed_config:
48+
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
49+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
50+
- name: dynamic-delay
51+
typed_config:
52+
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
53+
static_delay: 1.33s
54+
- name: test-server
55+
typed_config:
56+
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
57+
response_body_size: 10
58+
v3_response_headers:
59+
- { header: { key: "x-nh", value: "1"}}
60+
```
61+
62+
This change does NOT affect how headers update the base configurations.
63+
64+
## 0.4.0
65+
66+
Due to
67+
[upstream envoy change](https://github.com/envoyproxy/nighthawk/commit/4919c54202329adc3875eb1bce074af33d54e26d),
68+
we modified the dynamic-delay and time-tracking filters' configuration protos
69+
to have their own configuration protos wrapping
70+
[nighthawk.server.ResponseOptions]([nighthawk.server.ResponseOptions](https://github.com/envoyproxy/nighthawk/blob/0.4.0/api/server/response_options.proto)).
71+
DynamicDelayConfiguration and TimeTrackingConfiguration definitions can be
72+
found at the bottom of that file as well.
73+
.
74+
75+
For yaml bootstrap configuration files that defined
76+
[filter configuration](https://github.com/envoyproxy/nighthawk/blob/main/source/server/README.md#nighthawk-test-server)
77+
for the `test-server`, `dynamic-delay`, or `time-tracking` filters, if you
78+
previously had:
79+
80+
```
81+
http_filters:
82+
- name: time-tracking
83+
- name: dynamic-delay
84+
- name: test-server
85+
typed_config:
86+
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
87+
response_body_size: 10
88+
static_delay: 1.33s
89+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
90+
v3_response_headers:
91+
- { header: { key: "x-nh", value: "1"}}
92+
```
93+
94+
You should now explicitly specify the types and values of the protos as such,
95+
wrapping the `dynamic-delay` and `time-tracking` configurations in a new field,
96+
`experimental_response_options`:
97+
98+
```
99+
http_filters:
100+
- name: time-tracking
101+
typed_config:
102+
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
103+
experimental_response_options:
104+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
105+
- name: dynamic-delay
106+
typed_config:
107+
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
108+
experimental_response_options:
109+
static_delay: 1.33s
110+
- name: test-server
111+
typed_config:
112+
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
113+
response_body_size: 10
114+
static_delay: 1.33s
115+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
116+
v3_response_headers:
117+
- { header: { key: "x-nh", value: "1"}}
118+
```
119+
120+
This change does NOT affect how headers update the base configurations.

api/server/BUILD

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ envoy_package()
1010

1111
api_cc_py_proto_library(
1212
name = "response_options_proto",
13-
srcs = ["response_options.proto"],
13+
srcs = [
14+
"dynamic_delay.proto",
15+
"response_options.proto",
16+
"time_tracking.proto",
17+
],
1418
deps = [
1519
"@envoy_api//envoy/api/v2/core:pkg",
1620
"@envoy_api//envoy/config/core/v3:pkg",

api/server/dynamic_delay.proto

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Proto file supporting any configuration related to the dynamic delay filter.
2+
syntax = "proto3";
3+
4+
import "api/server/response_options.proto";
5+
import "google/protobuf/duration.proto";
6+
import "validate/validate.proto";
7+
8+
package nighthawk.server;
9+
10+
// Configures the dynamic-delay filter.
11+
message DynamicDelayConfiguration {
12+
oneof oneof_delay_options {
13+
// Static delay duration.
14+
google.protobuf.Duration static_delay = 2 [(validate.rules).duration.gte.nanos = 0];
15+
// Concurrency based linear delay configuration.
16+
ConcurrencyBasedLinearDelay concurrency_based_linear_delay = 3;
17+
}
18+
19+
reserved 1;
20+
}

api/server/response_options.proto

+9-14
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,25 @@ message ResponseOptions {
3535
// If true, then echo request headers in the response body.
3636
bool echo_request_headers = 3;
3737

38+
// IMPORTANT:
39+
// The below fields are only for use in the x-nighthawk-test-server-config header.
40+
// They do not have any behavior on the test server filter, but rather the dynamic-delay
41+
// and time-tracking filters. For server-level configuration, please provide the
42+
// configuration in the appropriate configuration proto.
43+
44+
// Provides request-level configuration that overrides DynamicDelayConfiguration.
3845
oneof oneof_delay_options {
3946
// Static delay duration.
4047
google.protobuf.Duration static_delay = 4 [(validate.rules).duration.gte.nanos = 0];
4148
// Concurrency based linear delay configuration.
4249
ConcurrencyBasedLinearDelay concurrency_based_linear_delay = 5;
4350
}
51+
52+
// Provides request-level configuration that overrides TimeTrackingConfiguration.
4453
// If set, makes the extension include timing data in the supplied response header name.
4554
// For example, when set to "x-abc", and 3 requests are performed, the test server will respond
4655
// with: Response 1: No x-abc header because there's no previous response. Response 2: Header
4756
// x-abc: <ns elapsed between responses 2 and 1>. Response 3: Header x-abc: <ns elapsed between
4857
// responses 3 and 2>.
4958
string emit_previous_request_delta_in_response_header = 6;
5059
}
51-
52-
// Configures the dynamic-delay test filter.
53-
message DynamicDelayConfiguration {
54-
// This is a temporary solution to allow this functionality to continue, but will likely be
55-
// reconfigured soon.
56-
ResponseOptions experimental_response_options = 1;
57-
}
58-
59-
// Configures the time-tracking test filter
60-
message TimeTrackingConfiguration {
61-
// This is a temporary solution to allow this functionality to continue, but will likely be
62-
// reconfigured soon.
63-
ResponseOptions experimental_response_options = 1;
64-
}

api/server/time_tracking.proto

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Proto file supporting any configuration related to the time tracking filter.
2+
syntax = "proto3";
3+
4+
package nighthawk.server;
5+
6+
// Configures the time-tracking filter.
7+
message TimeTrackingConfiguration {
8+
// If set, makes the extension include timing data in the supplied response header name.
9+
// For example, when set to "x-abc", and 3 requests are performed, the test server will respond
10+
// with: Response 1: No x-abc header because there's no previous response. Response 2: Header
11+
// x-abc: <ns elapsed between responses 2 and 1>. Response 3: Header x-abc: <ns elapsed between
12+
// responses 3 and 2>.
13+
string emit_previous_request_delta_in_response_header = 2;
14+
15+
reserved 1;
16+
}

docs/root/examples/HEADER_BASED_LATENCY.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Another use-case is tracking request-arrival time deltas using a feature of the
2424
- name: time-tracking
2525
typed_config:
2626
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
27-
experimental_response_options:
28-
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
27+
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
2928
- name: test-server
3029
typed_config:
3130
"@type": type.googleapis.com/nighthawk.server.ResponseOptions

source/server/BUILD

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ envoy_cc_library(
5050
deps = [
5151
":configuration_lib",
5252
"//api/server:response_options_proto_cc_proto",
53+
"@envoy//source/common/common:statusor_lib_with_external_headers",
5354
"@envoy//source/exe:envoy_common_lib_with_external_headers",
5455
],
5556
)
@@ -63,6 +64,7 @@ envoy_cc_library(
6364
":configuration_lib",
6465
"//api/server:response_options_proto_cc_proto",
6566
"//source/common:thread_safe_monotonic_time_stopwatch_lib",
67+
"@envoy//source/common/common:statusor_lib_with_external_headers",
6668
"@envoy//source/exe:envoy_common_lib_with_external_headers",
6769
"@envoy//source/extensions/filters/http/common:pass_through_filter_lib_with_external_headers",
6870
],
@@ -76,6 +78,7 @@ envoy_cc_library(
7678
deps = [
7779
":configuration_lib",
7880
"//api/server:response_options_proto_cc_proto",
81+
"@envoy//source/common/common:statusor_lib_with_external_headers",
7982
"@envoy//source/exe:envoy_common_lib_with_external_headers",
8083
"@envoy//source/extensions/filters/http/fault:fault_filter_lib_with_external_headers",
8184
],

source/server/README.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ static_resources:
5050
- name: dynamic-delay
5151
typed_config:
5252
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
53-
experimental_response_options:
54-
static_delay: 0.5s
53+
static_delay: 0.5s
5554
- name: test-server # before envoy.router because order matters!
5655
typed_config:
5756
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
@@ -75,13 +74,19 @@ admin:
7574
port_value: 8081
7675
```
7776
78-
## Response Options config
77+
## Nighthawk Test Server Filter Configurations
7978
80-
The [ResponseOptions proto](/api/server/response_options.proto) is shared by
81-
the `Test Server` and `Dynamic Delay` filter extensions. Each filter will
82-
interpret the parts that are relevant to it. This allows specifying what
83-
a response should look like in a single message, which can be done at request
84-
time via the optional `x-nighthawk-test-server-config` request-header.
79+
The [ResponseOptions proto](/api/server/response_options.proto) used to be
80+
shared by the `Test Server`, `Dynamic Delay`, and `Time Tracking` filter
81+
extensions. Now, each of these filters has its own primary configuration, respectively:
82+
83+
- [ResponseOptions](/api/server/response_options.proto) for `Test Server`
84+
- [DynamicDelayConfiguration](/api/server/dynamic_delay.proto) for `Dynamic Delay`
85+
- [TimeTrackingConfiguration](/api/server/time_tracking.proto) for `Time Tracking`
86+
87+
However, currently, each filter still uses the same `x-nighthawk-test-server-config`
88+
request-header, which is a ResponseOptions proto. When this header is provided, each
89+
filter will interpret only the parts that are relevant to it.
8590

8691
### Test Server
8792

@@ -135,7 +140,9 @@ This example shows that intermediate proxy has added `x-forwarded-proto` and
135140

136141
### Dynamic Delay
137142

138-
The Dynamic Delay interprets the `oneof_delay_options` part in the [ResponseOptions proto](/api/server/response_options.proto). If specified, it can be used to:
143+
The Dynamic Delay interprets the `DynamicDelayConfiguration` for startup configuration, and the
144+
`oneof_delay_options` part in the [ResponseOptions proto](/api/server/response_options.proto) for
145+
`x-nighthawk-test-server-config`. If specified, it can be used to:
139146

140147
- Configure a static delay via `static_delay`.
141148
- Configure a delay which linearly increase as the number of active requests grows, representing a simplified model of an overloaded server, via `concurrency_based_linear_delay`.

0 commit comments

Comments
 (0)