Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baggage: allow propagation #4326

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions source/extensions/filters/http/connect_baggage/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ syntax = "proto3";

package io.istio.http.connect_baggage;

// Computes and stores the downstream peer metadata from the "baggage" header.
message Config {}
// Computes or propagates the downstream peer metadata using the "baggage"
// header.
message Config {
// Write "baggage" header from downstream peer metadata, instead of reading
// it.
bool propagate = 1;
}
24 changes: 20 additions & 4 deletions source/extensions/filters/http/connect_baggage/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ namespace Extensions {
namespace HttpFilters {
namespace ConnectBaggage {

constexpr absl::string_view Baggage = "baggage";
constexpr absl::string_view DownstreamPeerKey = "wasm.downstream_peer";

Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
bool) {
if (propagate_) {
const auto* object = decoder_callbacks_->streamInfo()
.filterState()
->getDataReadOnly<Filters::Common::Expr::CelState>(
DownstreamPeerKey);
if (object) {
const auto peer = Istio::Common::convertFlatNodeToWorkloadMetadata(
*flatbuffers::GetRoot<Wasm::Common::FlatNode>(
object->value().data()));
headers.addCopy(Http::LowerCaseString(Baggage), peer.baggage());
}
return Http::FilterHeadersStatus::Continue;
}
const auto header_string = Http::HeaderUtility::getAllOfHeaderAsString(
headers, Http::LowerCaseString("baggage"));
headers, Http::LowerCaseString(Baggage));
const auto result = header_string.result();
if (result) {
const auto metadata_object =
Expand Down Expand Up @@ -67,10 +83,10 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
}

Http::FilterFactoryCb FilterConfigFactory::createFilterFactoryFromProtoTyped(
const io::istio::http::connect_baggage::Config&, const std::string&,
const io::istio::http::connect_baggage::Config& config, const std::string&,
Server::Configuration::FactoryContext&) {
return [](Http::FilterChainFactoryCallbacks& callbacks) {
auto filter = std::make_shared<Filter>();
return [config](Http::FilterChainFactoryCallbacks& callbacks) {
auto filter = std::make_shared<Filter>(config.propagate());
callbacks.addStreamFilter(filter);
};
}
Expand Down
4 changes: 4 additions & 0 deletions source/extensions/filters/http/connect_baggage/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ namespace ConnectBaggage {

class Filter : public Http::PassThroughFilter {
public:
Filter(bool propagate) : propagate_(propagate) {}
Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap&,
bool) override;

private:
bool propagate_;
};

class FilterConfigFactory
Expand Down