@@ -19,7 +19,7 @@ struct RcDetailsValues {
19
19
};
20
20
typedef ConstSingleton<RcDetailsValues> RcDetails;
21
21
22
- TransformationFilter::TransformationFilter () {}
22
+ TransformationFilter::TransformationFilter (FilterConfigSharedPtr config) : filter_config_(config ) {}
23
23
24
24
TransformationFilter::~TransformationFilter () {}
25
25
@@ -41,6 +41,7 @@ TransformationFilter::decodeHeaders(Http::HeaderMap &header_map,
41
41
request_headers_ = &header_map;
42
42
43
43
if (end_stream || request_transformation_->passthrough_body ()) {
44
+ filter_config_->stats ().request_header_transformations_ .inc ();
44
45
transformRequest ();
45
46
46
47
return is_error () ? Http::FilterHeadersStatus::StopIteration
@@ -65,6 +66,7 @@ Http::FilterDataStatus TransformationFilter::decodeData(Buffer::Instance &data,
65
66
}
66
67
67
68
if (end_stream) {
69
+ filter_config_->stats ().request_body_transformations_ .inc ();
68
70
transformRequest ();
69
71
return is_error () ? Http::FilterDataStatus::StopIterationNoBuffer
70
72
: Http::FilterDataStatus::Continue;
@@ -76,6 +78,7 @@ Http::FilterDataStatus TransformationFilter::decodeData(Buffer::Instance &data,
76
78
Http::FilterTrailersStatus
77
79
TransformationFilter::decodeTrailers (Http::HeaderMap &) {
78
80
if (requestActive ()) {
81
+ filter_config_->stats ().request_body_transformations_ .inc ();
79
82
transformRequest ();
80
83
}
81
84
return is_error () ? Http::FilterTrailersStatus::StopIteration
@@ -96,6 +99,7 @@ TransformationFilter::encodeHeaders(Http::HeaderMap &header_map,
96
99
response_headers_ = &header_map;
97
100
98
101
if (end_stream || response_transformation_->passthrough_body ()) {
102
+ filter_config_->stats ().response_header_transformations_ .inc ();
99
103
transformResponse ();
100
104
return Http::FilterHeadersStatus::Continue;
101
105
}
@@ -113,6 +117,7 @@ Http::FilterDataStatus TransformationFilter::encodeData(Buffer::Instance &data,
113
117
if ((encoder_buffer_limit_ != 0 ) &&
114
118
(response_body_.length () > encoder_buffer_limit_)) {
115
119
error (Error::PayloadTooLarge);
120
+ filter_config_->stats ().response_body_transformations_ .inc ();
116
121
responseError ();
117
122
return Http::FilterDataStatus::Continue;
118
123
}
@@ -128,6 +133,7 @@ Http::FilterDataStatus TransformationFilter::encodeData(Buffer::Instance &data,
128
133
Http::FilterTrailersStatus
129
134
TransformationFilter::encodeTrailers (Http::HeaderMap &) {
130
135
if (responseActive ()) {
136
+ filter_config_->stats ().response_body_transformations_ .inc ();
131
137
transformResponse ();
132
138
}
133
139
return Http::FilterTrailersStatus::Continue;
@@ -151,24 +157,28 @@ TransformerConstSharedPtr TransformationFilter::getTransformFromRoute(
151
157
return nullptr ;
152
158
}
153
159
154
- const auto *config = Http::Utility::resolveMostSpecificPerFilterConfig<
155
- RouteTransformationFilterConfig>(
156
- SoloHttpFilterNames::get ().Transformation , route_);
157
-
158
- if (config != nullptr ) {
159
- switch (direction) {
160
+ const auto *route_config = Http::Utility::resolveMostSpecificPerFilterConfig<
161
+ RouteTransformationFilterConfig>(filter_config_->name (), route_);
162
+
163
+ switch (direction) {
160
164
case TransformationFilter::Direction::Request: {
161
- should_clear_cache_ = config->shouldClearCache ();
162
- return config->getRequestTranformation ();
165
+ should_clear_cache_ = filter_config_->shouldClearCache ();
166
+ if (route_config != nullptr && route_config->getRequestTranformation () != nullptr ) {
167
+ should_clear_cache_ = route_config->shouldClearCache ();
168
+ return route_config->getRequestTranformation ();
169
+ } else {
170
+ return filter_config_->getRequestTranformation ();
171
+ }
163
172
}
164
173
case TransformationFilter::Direction::Response: {
165
- return config ->getResponseTranformation ();
166
- }
167
- default :
168
- // TODO(yuval-k): should this be a warning log?
169
- NOT_REACHED_GCOVR_EXCL_LINE;
174
+ if (route_config != nullptr && route_config ->getResponseTranformation () != nullptr ) {
175
+ return route_config-> getResponseTranformation ();
176
+ } else {
177
+ return filter_config_-> getResponseTranformation ();
178
+ }
170
179
}
171
180
}
181
+
172
182
return nullptr ;
173
183
}
174
184
@@ -227,13 +237,15 @@ void TransformationFilter::transformSomething(
227
237
228
238
void TransformationFilter::requestError () {
229
239
ASSERT (is_error ());
240
+ filter_config_->stats ().request_error_ .inc ();
230
241
decoder_callbacks_->sendLocalReply (error_code_, error_messgae_, nullptr ,
231
242
absl::nullopt,
232
243
RcDetails::get ().TransformError );
233
244
}
234
245
235
246
void TransformationFilter::responseError () {
236
247
ASSERT (is_error ());
248
+ filter_config_->stats ().response_error_ .inc ();
237
249
response_headers_->Status ()->value (enumToInt (error_code_));
238
250
Buffer::OwnedImpl data (error_messgae_);
239
251
response_headers_->removeContentType ();
0 commit comments