feat(context): add response.grpc_status#9693
Conversation
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
|
@kyessenov would you have some time to take a first pass at this? Thanks. |
|
@htuch I believe @kyessenov is on vacation, so it will be a little while until he can take a look. |
|
@PiotrSikora can you take a look? |
mattklein123
left a comment
There was a problem hiding this comment.
LGTM with a small test question, thanks.
/wait
| return CelValue::CreateInt64(status); | ||
| } | ||
| } | ||
| return {}; |
There was a problem hiding this comment.
Do you have a test case that covers no headers/trailers and/or bad header/trailer values? (Optimally you could use Common::getGrpcStatus but not sure if it's worth it or not.
There was a problem hiding this comment.
Thanks for the pointer to the Common:getGrpcStatus bit. I did not know that existed. That led me to look at the access log code that uses it, which ultimately led me to expand the fallbacks.
Now, after looking in trailers and headers, this will attempt to look at http response code and finally return Unknown if not found.
Matching the logging behavior seemed important.
I added a bunch of test cases for this updated behavior to match. Please let me know what you think.
There was a problem hiding this comment.
Thanks, is there is any reasonable way to unify this logic and the access log logic so they don't fall out of sync? I agree they should be the same.
/wait-any
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
| if (code.has_value()) { | ||
| return CelValue::CreateInt64(Grpc::Utility::httpToGrpcStatus(code.value())); | ||
| } | ||
| return CelValue::CreateInt64(Grpc::Status::WellKnownGrpcStatus::Unknown); |
There was a problem hiding this comment.
I don't think that returning grpc-status: 2 (unknown) when it wasn't present in the response is a correct thing to do.
There was a problem hiding this comment.
@PiotrSikora I was trying to match:
envoy/source/common/access_log/access_log_impl.cc
Lines 231 to 261 in 5248a4f
If not UNKNOWN, what status would you expect as a return value?
There was a problem hiding this comment.
@douglas-reid fair point wrt being consistent with the access loggers, but I don't think any status should be returned as a value if there was no status sent on the wire...
Can't the return value by {}, absl::nullopt, or something else in that style?
There was a problem hiding this comment.
It can definitely return {}. That was the way I had it originally.
I guess we need to decide on exactly what to do.
BTW, it looks like choosing "Unknown" has some prior art:
https://github.com/grpc/grpc-go/blob/master/internal/transport/http_util.go#L281-L288
There was a problem hiding this comment.
I think it should be {}. There is quite a difference between missing field and grpc-status: 2.
There was a problem hiding this comment.
I think it should be {}. Otherwise, we run the risk of confusing the consumer for a non-gRPC request.
| } else if (value == Flags) { | ||
| return CelValue::CreateInt64(info_.responseFlags()); | ||
| } else if (value == GrpcStatus) { | ||
| for (const auto wrapper : ((HeadersWrapper[]){trailers_, headers_})) { |
There was a problem hiding this comment.
I'm not happy about the linear performance here. Maybe add a TODO to cache the computed value?
Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
|
@mattklein123 @PiotrSikora @kyessenov please take another look. I've updated the PR to extract the fallback logic to the Common lib. Additionally, this PR should preserve the access_logger |
…#377) Signed-off-by: Douglas Reid <douglas-reid@users.noreply.github.com>
Description:
This PR allows access to the gRPC status codes via the extensions common filter context. This will make it possible to report gRPC status codes in metrics and logs. This is a part of the work from: https://tinyurl.com/yy2cwmv5. A companion PR that hopes to use this code is istio/proxy#2624.
Risk Level: low
Testing: unit
Docs Changes: Updated RBAC filter attributes doc
Release Notes: none
Signed-off-by: Douglas Reid douglas-reid@users.noreply.github.com