Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Perry <[email protected]>
  • Loading branch information
Nathan Perry committed Jun 6, 2022
1 parent 713ef14 commit d0d52be
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 11 deletions.
99 changes: 99 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Changelog

All breaking changes to this project will be documented in this file, most recent changes at the top.

## 0.5.0

In an effort to clean up the previous change and improve it, we re-modified the dynamic-delay and time-tracking filters to extricate their configuration entirely from nighthawk.server.ResponseOptions.

If you are converting from the previous configuration with `experimental_response_options`, such as:

```
http_filters:
- name: time-tracking
typed_config:
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
experimental_response_options:
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
- name: dynamic-delay
typed_config:
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
experimental_response_options:
static_delay: 1.33s
- name: test-server
typed_config:
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
response_body_size: 10
static_delay: 1.33s
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
v3_response_headers:
- { header: { key: "x-nh", value: "1"}}
```

You should now specify only fields related to each filter in their configuration, and you can do so at the top-level of those protos:

```
http_filters:
- name: time-tracking
typed_config:
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
- name: dynamic-delay
typed_config:
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
static_delay: 1.33s
- name: test-server
typed_config:
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
response_body_size: 10
v3_response_headers:
- { header: { key: "x-nh", value: "1"}}
```

This change does NOT affect how headers update the base configurations.

## 0.4.0

Due to [upstream envoy change](https://github.com/envoyproxy/nighthawk/commit/4919c54202329adc3875eb1bce074af33d54e26d), we modified the dynamic-delay and time-tracking filters' configuration protos to have their own configuration protos wrapping nighthawk.server.ResponseOptions.

For base yaml configuration files, if you previously had:

```
http_filters:
- name: time-tracking
- name: dynamic-delay
- name: test-server
typed_config:
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
response_body_size: 10
static_delay: 1.33s
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
v3_response_headers:
- { header: { key: "x-nh", value: "1"}}
```

You should now explicitly specify the types and values of the protos as such:

```
http_filters:
- name: time-tracking
typed_config:
"@type": type.googleapis.com/nighthawk.server.TimeTrackingConfiguration
experimental_response_options:
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
- name: dynamic-delay
typed_config:
"@type": type.googleapis.com/nighthawk.server.DynamicDelayConfiguration
experimental_response_options:
static_delay: 1.33s
- name: test-server
typed_config:
"@type": type.googleapis.com/nighthawk.server.ResponseOptions
response_body_size: 10
static_delay: 1.33s
emit_previous_request_delta_in_response_header: x-origin-request-receipt-delta
v3_response_headers:
- { header: { key: "x-nh", value: "1"}}
```

This change does NOT affect how headers update the base configurations.
1 change: 1 addition & 0 deletions api/server/dynamic_delay.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Proto file supporting any configuration related to the dynamic delay filter.
syntax = "proto3";

import "api/server/response_options.proto";
Expand Down
3 changes: 1 addition & 2 deletions api/server/time_tracking.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Proto file supporting any configuration related to the time tracking filter.
syntax = "proto3";

import "api/server/response_options.proto";

package nighthawk.server;

// Configures the time-tracking filter.
Expand Down
4 changes: 2 additions & 2 deletions source/server/http_dynamic_delay_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ HttpDynamicDelayDecoderFilterConfig::HttpDynamicDelayDecoderFilterConfig(
server_config_(std::make_shared<DynamicDelayConfiguration>(proto_config)) {}

std::shared_ptr<const DynamicDelayConfiguration>
HttpDynamicDelayDecoderFilterConfig::getServerConfig() {
HttpDynamicDelayDecoderFilterConfig::getStartupFilterConfiguration() {
return server_config_;
}

Expand All @@ -105,7 +105,7 @@ void HttpDynamicDelayDecoderFilter::onDestroy() {
Envoy::Http::FilterHeadersStatus
HttpDynamicDelayDecoderFilter::decodeHeaders(Envoy::Http::RequestHeaderMap& headers,
bool end_stream) {
effective_config_ = computeEffectiveConfiguration(config_->getServerConfig(), headers);
effective_config_ = computeEffectiveConfiguration(config_->getStartupFilterConfiguration(), headers);
if (effective_config_.ok()) {
const absl::optional<int64_t> delay_ms =
computeDelayMs(*effective_config_.value(), config_->approximateFilterInstances());
Expand Down
2 changes: 1 addition & 1 deletion source/server/http_dynamic_delay_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class HttpDynamicDelayDecoderFilterConfig : public FilterConfigurationBase {
* @return std::shared_ptr<const nighthawk::server::DynamicDelayConfiguration> the base
* configuration for this filter.
*/
std::shared_ptr<const nighthawk::server::DynamicDelayConfiguration> getServerConfig();
std::shared_ptr<const nighthawk::server::DynamicDelayConfiguration> getStartupFilterConfiguration();

private:
static std::atomic<uint64_t>& instances() {
Expand Down
4 changes: 2 additions & 2 deletions source/server/http_test_server_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ HttpTestServerDecoderFilterConfig::HttpTestServerDecoderFilterConfig(
: FilterConfigurationBase("test-server"),
server_config_(std::make_shared<ResponseOptions>(proto_config)) {}

std::shared_ptr<const ResponseOptions> HttpTestServerDecoderFilterConfig::getServerConfig() {
std::shared_ptr<const ResponseOptions> HttpTestServerDecoderFilterConfig::getStartupFilterConfiguration() {
return server_config_;
}

Expand All @@ -74,7 +74,7 @@ void HttpTestServerDecoderFilter::sendReply(const ResponseOptions& options) {
Envoy::Http::FilterHeadersStatus
HttpTestServerDecoderFilter::decodeHeaders(Envoy::Http::RequestHeaderMap& headers,
bool end_stream) {
effective_config_ = computeEffectiveConfiguration(config_->getServerConfig(), headers);
effective_config_ = computeEffectiveConfiguration(config_->getStartupFilterConfiguration(), headers);
if (end_stream) {
if (!config_->validateOrSendError(effective_config_.status(), *decoder_callbacks_)) {
if (effective_config_.value()->echo_request_headers()) {
Expand Down
6 changes: 5 additions & 1 deletion source/server/http_test_server_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class HttpTestServerDecoderFilterConfig : public FilterConfigurationBase {
public:
HttpTestServerDecoderFilterConfig(const nighthawk::server::ResponseOptions& proto_config);

std::shared_ptr<const nighthawk::server::ResponseOptions> getServerConfig();
/**
* @return std::shared_ptr<const nighthawk::server::TimeTrackingConfiguration> the base
* configuration for this filter.
*/
std::shared_ptr<const nighthawk::server::ResponseOptions> getStartupFilterConfiguration();

private:
std::shared_ptr<const nighthawk::server::ResponseOptions> server_config_;
Expand Down
4 changes: 2 additions & 2 deletions source/server/http_time_tracking_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ HttpTimeTrackingFilterConfig::getElapsedNanosSinceLastRequest(Envoy::TimeSource&
return stopwatch_->getElapsedNsAndReset(time_source);
}

std::shared_ptr<const TimeTrackingConfiguration> HttpTimeTrackingFilterConfig::getServerConfig() {
std::shared_ptr<const TimeTrackingConfiguration> HttpTimeTrackingFilterConfig::getStartupFilterConfiguration() {
return server_config_;
}

Expand All @@ -91,7 +91,7 @@ HttpTimeTrackingFilter::HttpTimeTrackingFilter(HttpTimeTrackingFilterConfigShare

Envoy::Http::FilterHeadersStatus
HttpTimeTrackingFilter::decodeHeaders(Envoy::Http::RequestHeaderMap& headers, bool end_stream) {
effective_config_ = computeEffectiveConfiguration(config_->getServerConfig(), headers);
effective_config_ = computeEffectiveConfiguration(config_->getStartupFilterConfiguration(), headers);
if (end_stream && config_->validateOrSendError(effective_config_.status(), *decoder_callbacks_)) {
return Envoy::Http::FilterHeadersStatus::StopIteration;
}
Expand Down
2 changes: 1 addition & 1 deletion source/server/http_time_tracking_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class HttpTimeTrackingFilterConfig : public FilterConfigurationBase {
* @return std::shared_ptr<const nighthawk::server::TimeTrackingConfiguration> the base
* configuration for this filter.
*/
std::shared_ptr<const nighthawk::server::TimeTrackingConfiguration> getServerConfig();
std::shared_ptr<const nighthawk::server::TimeTrackingConfiguration> getStartupFilterConfiguration();

private:
std::unique_ptr<Stopwatch> stopwatch_;
Expand Down

0 comments on commit d0d52be

Please sign in to comment.