From f3ba46b6751d64b347ff89c4903d618c1f158b43 Mon Sep 17 00:00:00 2001 From: Kuat Yessenov Date: Fri, 11 Aug 2023 18:48:26 +0000 Subject: [PATCH] build: remove wasm metadata exchange Signed-off-by: Kuat Yessenov --- BUILD | 1 - Makefile.core.mk | 11 +- extensions/BUILD | 58 ----- extensions/metadata_exchange/BUILD | 50 ---- extensions/metadata_exchange/config.cc | 34 --- extensions/metadata_exchange/config.pb.html | 66 ----- extensions/metadata_exchange/config.proto | 36 --- .../declare_property.pb.html | 127 ---------- .../metadata_exchange/declare_property.proto | 42 ---- extensions/metadata_exchange/plugin.cc | 236 ------------------ extensions/metadata_exchange/plugin.h | 94 ------- scripts/release-binary.sh | 35 --- .../http_metadata_exchange/exchange_test.go | 49 ---- test/envoye2e/otel/otel_test.go | 4 +- testdata/filters/mx_inbound.yaml.tmpl | 23 -- testdata/filters/mx_outbound.yaml.tmpl | 23 -- 16 files changed, 4 insertions(+), 885 deletions(-) delete mode 100644 extensions/BUILD delete mode 100644 extensions/metadata_exchange/BUILD delete mode 100644 extensions/metadata_exchange/config.cc delete mode 100644 extensions/metadata_exchange/config.pb.html delete mode 100644 extensions/metadata_exchange/config.proto delete mode 100644 extensions/metadata_exchange/declare_property.pb.html delete mode 100644 extensions/metadata_exchange/declare_property.proto delete mode 100644 extensions/metadata_exchange/plugin.cc delete mode 100644 extensions/metadata_exchange/plugin.h delete mode 100644 testdata/filters/mx_inbound.yaml.tmpl delete mode 100644 testdata/filters/mx_outbound.yaml.tmpl diff --git a/BUILD b/BUILD index 70445c1da5d..046d5d84f54 100644 --- a/BUILD +++ b/BUILD @@ -36,7 +36,6 @@ envoy_cc_binary( visibility = ["//visibility:public"], deps = [ "//extensions/access_log_policy:access_log_policy_lib", - "//extensions/metadata_exchange:metadata_exchange_lib", "//extensions/stackdriver:stackdriver_plugin", "//source/extensions/common/workload_discovery:api_lib", # Experimental: WIP "//source/extensions/filters/http/alpn:config_lib", diff --git a/Makefile.core.mk b/Makefile.core.mk index b1c0e61a063..2bfe6a4496a 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -17,7 +17,7 @@ TOP := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) SHELL := /bin/bash BAZEL_STARTUP_ARGS ?= BAZEL_BUILD_ARGS ?= -BAZEL_TARGETS ?= //... -extensions:metadata_exchange.wasm +BAZEL_TARGETS ?= //... # Don't build Debian packages and Docker images in tests. BAZEL_TEST_TARGETS ?= ${BAZEL_TARGETS} E2E_TEST_TARGETS ?= $$(go list ./...) @@ -83,14 +83,7 @@ build_envoy_asan: BAZEL_CONFIG_CURRENT = $(BAZEL_CONFIG_ASAN) build_envoy_asan: BAZEL_TARGETS = //:envoy build_envoy_asan: build -build_wasm: - export PATH=$(PATH) CC=$(CC) CXX=$(CXX) && bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_CONFIG_REL) //extensions:metadata_exchange.wasm - export PATH=$(PATH) CC=$(CC) CXX=$(CXX) && bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_CONFIG_REL) @envoy//test/tools/wee8_compile:wee8_compile_tool - bazel-bin/external/envoy/test/tools/wee8_compile/wee8_compile_tool bazel-bin/extensions/metadata_exchange.wasm bazel-bin/extensions/metadata_exchange.compiled.wasm - -# NOTE: build_wasm has to happen before build_envoy, since the integration test references bazel-bin symbol link for envoy binary, -# which will be overwritten if wasm build happens after envoy. -check_wasm: build_wasm build_envoy +check_wasm: @true clean: diff --git a/extensions/BUILD b/extensions/BUILD deleted file mode 100644 index d30da001bbb..00000000000 --- a/extensions/BUILD +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2019 Istio Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# - -load( - "@envoy//bazel/wasm:wasm.bzl", - "envoy_wasm_cc_binary", -) -load( - "@envoy//bazel:envoy_build_system.bzl", - "envoy_package", -) - -envoy_package() - -WASM_LINKOPTS = [ - "-s INITIAL_MEMORY=8MB", -] - -envoy_wasm_cc_binary( - name = "metadata_exchange.wasm", - srcs = [ - "//extensions/common:context.cc", - "//extensions/common:context.h", - "//extensions/common:proto_util.cc", - "//extensions/common:proto_util.h", - "//extensions/common:util.cc", - "//extensions/common:util.h", - "//extensions/common/wasm:base64.h", - "//extensions/metadata_exchange:plugin.cc", - "//extensions/metadata_exchange:plugin.h", - ], - copts = ["-UNULL_PLUGIN"], - linkopts = WASM_LINKOPTS, - tags = ["manual"], - deps = [ - "//extensions/common:node_info_fb_cc", - "//extensions/common/wasm:json_util", - "//extensions/metadata_exchange:declare_property_proto_cc", - "//external:abseil_strings", - "//external:abseil_time", - "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_full", - "@proxy_wasm_cpp_sdk//contrib:contrib_lib", - ], -) diff --git a/extensions/metadata_exchange/BUILD b/extensions/metadata_exchange/BUILD deleted file mode 100644 index 37e910443fb..00000000000 --- a/extensions/metadata_exchange/BUILD +++ /dev/null @@ -1,50 +0,0 @@ -licenses(["notice"]) # Apache 2 - -load( - "@envoy//bazel:envoy_build_system.bzl", - "envoy_cc_library", - "envoy_package", -) - -envoy_package() - -envoy_cc_library( - name = "metadata_exchange_lib", - srcs = [ - "config.cc", - "plugin.cc", - ], - hdrs = [ - "plugin.h", - ], - repository = "@envoy", - visibility = ["//visibility:public"], - deps = [ - "//extensions/common:context", - "//extensions/common:json_util", - "//extensions/common:proto_util", - "@envoy//source/common/common:base64_lib", - "@envoy//source/extensions/common/wasm/ext:declare_property_cc_proto", - "@proxy_wasm_cpp_host//:null_lib", - ], -) - -proto_library( - name = "config_proto", - srcs = ["config.proto"], - deps = [ - "@com_google_protobuf//:wrappers_proto", - ], -) - -proto_library( - name = "declare_property_proto", - srcs = ["declare_property.proto"], -) - -cc_proto_library( - name = "declare_property_proto_cc", - deps = [":declare_property_proto"], -) - -exports_files(["base64.h"]) diff --git a/extensions/metadata_exchange/config.cc b/extensions/metadata_exchange/config.cc deleted file mode 100644 index 23f1cd35b41..00000000000 --- a/extensions/metadata_exchange/config.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2019 Istio Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "include/proxy-wasm/null_plugin.h" -#include "source/common/common/base64.h" - -namespace proxy_wasm { -namespace null_plugin { -namespace MetadataExchange { -namespace Plugin { -NullPluginRegistry* context_registry_{}; -} // namespace Plugin - -// Registration glue -RegisterNullVmPluginFactory - register_http_metadata_exchange_filter("envoy.wasm.metadata_exchange", []() { - return std::make_unique(Plugin::context_registry_); - }); - -} // namespace MetadataExchange -} // namespace null_plugin -} // namespace proxy_wasm diff --git a/extensions/metadata_exchange/config.pb.html b/extensions/metadata_exchange/config.pb.html deleted file mode 100644 index c88c577f700..00000000000 --- a/extensions/metadata_exchange/config.pb.html +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: Metadata Exchange Config -description: Configuration for Metadata Exchange Filter. -location: https://istio.io/docs/reference/config/proxy_extensions/metadata_exchange.html -layout: protoc-gen-docs -generator: protoc-gen-docs -weight: 20 -number_of_entries: 2 ---- -

PluginConfig

-
- - - - - - - - - - - - - - - - - -
FieldTypeDescriptionRequired
max_peer_cache_sizeUInt32Value -

maximum size of the peer metadata cache. -A long lived proxy that connects with many transient peers can build up a -large cache. To turn off the cache, set this field to zero.

- -
-No -
-
-

google.protobuf.UInt32Value

-
-

Wrapper message for uint32.

-

The JSON representation for UInt32Value is JSON number.

- - - - - - - - - - - - - - - - - - -
FieldTypeDescriptionRequired
valueuint32 -

The uint32 value.

- -
-No -
-
diff --git a/extensions/metadata_exchange/config.proto b/extensions/metadata_exchange/config.proto deleted file mode 100644 index 6dc220147d9..00000000000 --- a/extensions/metadata_exchange/config.proto +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2019 Istio Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -syntax = "proto3"; - -// clang-format off -// $title: Metadata Exchange Config -// $description: Configuration for Metadata Exchange Filter. -// $location: https://istio.io/docs/reference/config/proxy_extensions/metadata_exchange.html -// $weight: 20 -// clang-format on - -package metadata_exchange; - -import "google/protobuf/wrappers.proto"; - -// next id: 2 - -message PluginConfig { - // maximum size of the peer metadata cache. - // A long lived proxy that connects with many transient peers can build up a - // large cache. To turn off the cache, set this field to zero. - google.protobuf.UInt32Value max_peer_cache_size = 1; -} diff --git a/extensions/metadata_exchange/declare_property.pb.html b/extensions/metadata_exchange/declare_property.pb.html deleted file mode 100644 index 6cc0d538cc8..00000000000 --- a/extensions/metadata_exchange/declare_property.pb.html +++ /dev/null @@ -1,127 +0,0 @@ ---- -title: envoy.source.extensions.common.wasm -layout: protoc-gen-docs -generator: protoc-gen-docs -number_of_entries: 3 ---- -

DeclarePropertyArguments

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FieldTypeDescriptionRequired
namestring - -No -
readonlybool - -No -
typeWasmType - -No -
schemabytes - -No -
spanLifeSpan - -No -
-
-

WasmType

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
Bytes -
String -
FlatBuffers -
Protobuf -
-
-

LifeSpan

-
- - - - - - - - - - - - - - - - - - - - - -
NameDescription
FilterChain -
DownstreamRequest -
DownstreamConnection -
-
diff --git a/extensions/metadata_exchange/declare_property.proto b/extensions/metadata_exchange/declare_property.proto deleted file mode 100644 index d5affe96fa3..00000000000 --- a/extensions/metadata_exchange/declare_property.proto +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2020 Istio Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// DO NOT MODIFY. -// This is a copy of envoy-wasm proto, used for Wasm build only. - -syntax = "proto3"; - -package envoy.source.extensions.common.wasm; - -enum WasmType { - Bytes = 0; - String = 1; - FlatBuffers = 2; - Protobuf = 3; -}; - -enum LifeSpan { - FilterChain = 0; - DownstreamRequest = 1; - DownstreamConnection = 2; -}; - -message DeclarePropertyArguments { - string name = 1; - bool readonly = 2; - WasmType type = 3; - bytes schema = 4; - LifeSpan span = 5; -}; diff --git a/extensions/metadata_exchange/plugin.cc b/extensions/metadata_exchange/plugin.cc deleted file mode 100644 index feb6725e10a..00000000000 --- a/extensions/metadata_exchange/plugin.cc +++ /dev/null @@ -1,236 +0,0 @@ -/* Copyright 2019 Istio Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "extensions/metadata_exchange/plugin.h" - -#include "absl/strings/str_cat.h" -#include "absl/strings/str_split.h" -#include "extensions/common/context.h" -#include "extensions/common/proto_util.h" -#include "extensions/common/util.h" -#include "extensions/common/wasm/json_util.h" - -#ifndef NULL_PLUGIN - -#include "extensions/common/wasm/base64.h" -#include "extensions/metadata_exchange/declare_property.pb.h" - -#else - -#include "source/common/common/base64.h" -#include "source/extensions/common/wasm/ext/declare_property.pb.h" - -namespace proxy_wasm { -namespace null_plugin { -namespace MetadataExchange { -namespace Plugin { - -PROXY_WASM_NULL_PLUGIN_REGISTRY; - -using Base64 = Envoy::Base64; - -#endif - -static RegisterContextFactory register_MetadataExchange(CONTEXT_FACTORY(PluginContext), - ROOT_FACTORY(PluginRootContext)); - -void PluginRootContext::updateMetadataValue() { - auto node_info = ::Wasm::Common::extractLocalNodeFlatBuffer(); - - google::protobuf::Struct metadata; - ::Wasm::Common::extractStructFromNodeFlatBuffer( - *flatbuffers::GetRoot<::Wasm::Common::FlatNode>(node_info.data()), &metadata); - - std::string metadata_bytes; - ::Wasm::Common::serializeToStringDeterministic(metadata, &metadata_bytes); - metadata_value_ = Base64::encode(metadata_bytes.data(), metadata_bytes.size()); -} - -// Metadata exchange has sane defaults and therefore it will be fully -// functional even with configuration errors. -// A configuration error thrown here will cause the proxy to crash. -bool PluginRootContext::onConfigure(size_t size) { - updateMetadataValue(); - if (!getValue({"node", "id"}, &node_id_)) { - LOG_DEBUG("cannot get node ID"); - } - LOG_DEBUG( - absl::StrCat("metadata_value_ id:", id(), " value:", metadata_value_, " node:", node_id_)); - - // Parse configuration JSON string. - if (size > 0 && !configure(size)) { - LOG_WARN("configuration has errrors, but initialzation can continue."); - } - - // Declare filter state property type. - const std::string function = "declare_property"; - envoy::source::extensions::common::wasm::DeclarePropertyArguments args; - args.set_type(envoy::source::extensions::common::wasm::WasmType::FlatBuffers); - args.set_span(envoy::source::extensions::common::wasm::LifeSpan::DownstreamRequest); - args.set_schema(::Wasm::Common::nodeInfoSchema().data(), ::Wasm::Common::nodeInfoSchema().size()); - std::string in; - args.set_name(std::string(::Wasm::Common::kUpstreamMetadataKey)); - args.SerializeToString(&in); - proxy_call_foreign_function(function.data(), function.size(), in.data(), in.size(), nullptr, - nullptr); - - args.set_name(std::string(::Wasm::Common::kDownstreamMetadataKey)); - args.SerializeToString(&in); - proxy_call_foreign_function(function.data(), function.size(), in.data(), in.size(), nullptr, - nullptr); - - return true; -} - -bool PluginRootContext::configure(size_t configuration_size) { - auto configuration_data = - getBufferBytes(WasmBufferType::PluginConfiguration, 0, configuration_size); - // Parse configuration JSON string. - auto result = ::Wasm::Common::JsonParse(configuration_data->view()); - if (!result.has_value()) { - LOG_WARN(absl::StrCat("cannot parse plugin configuration JSON string: ", - ::Wasm::Common::toAbslStringView(configuration_data->view()))); - return false; - } - - auto j = result.value(); - auto max_peer_cache_size_field = ::Wasm::Common::JsonGetField(j, "max_peer_cache_size"); - if (max_peer_cache_size_field.detail() == Wasm::Common::JsonParserResultDetail::OK) { - max_peer_cache_size_ = max_peer_cache_size_field.value(); - } - return true; -} - -bool PluginRootContext::updatePeer(std::string_view key, std::string_view peer_id, - std::string_view peer_header) { - std::string id = std::string(peer_id); - if (max_peer_cache_size_ > 0) { - auto it = cache_.find(id); - if (it != cache_.end()) { - setFilterState(key, it->second); - return true; - } - } - -#ifndef NULL_PLUGIN - auto peer_header_view = peer_header; -#else - auto peer_header_view = Wasm::Common::toAbslStringView(peer_header); -#endif - - auto bytes = Base64::decodeWithoutPadding(peer_header_view); - google::protobuf::Struct metadata; - if (!metadata.ParseFromString(bytes)) { - return false; - } - - auto fb = ::Wasm::Common::extractNodeFlatBufferFromStruct(metadata); - std::string_view out(reinterpret_cast(fb.data()), fb.size()); - setFilterState(key, out); - - if (max_peer_cache_size_ > 0) { - // do not let the cache grow beyond max cache size. - if (static_cast(cache_.size()) > max_peer_cache_size_) { - auto it = cache_.begin(); - cache_.erase(cache_.begin(), std::next(it, max_peer_cache_size_ / 4)); - LOG_DEBUG(absl::StrCat("cleaned cache, new cache_size:", cache_.size())); - } - cache_.emplace(std::move(id), out); - } - - return true; -} - -FilterHeadersStatus PluginContext::onRequestHeaders(uint32_t, bool) { - // strip and store downstream peer metadata - auto downstream_metadata_id = getRequestHeader(ExchangeMetadataHeaderId); - if (downstream_metadata_id != nullptr && !downstream_metadata_id->view().empty()) { - removeRequestHeader(ExchangeMetadataHeaderId); - setFilterState(::Wasm::Common::kDownstreamMetadataIdKey, downstream_metadata_id->view()); - } else { - metadata_id_received_ = false; - } - - auto downstream_metadata_value = getRequestHeader(ExchangeMetadataHeader); - if (downstream_metadata_value != nullptr && !downstream_metadata_value->view().empty()) { - removeRequestHeader(ExchangeMetadataHeader); - if (!rootContext()->updatePeer(::Wasm::Common::kDownstreamMetadataKey, - downstream_metadata_id->view(), - downstream_metadata_value->view())) { - LOG_DEBUG("cannot set downstream peer node"); - } - } else { - metadata_received_ = false; - } - - // do not send request internal headers to sidecar app if it is an inbound - // proxy - if (direction_ != ::Wasm::Common::TrafficDirection::Inbound) { - auto metadata = metadataValue(); - // insert peer metadata struct for upstream - if (!metadata.empty()) { - replaceRequestHeader(ExchangeMetadataHeader, metadata); - } - - auto nodeid = nodeId(); - if (!nodeid.empty()) { - replaceRequestHeader(ExchangeMetadataHeaderId, nodeid); - } - } - - return FilterHeadersStatus::Continue; -} - -FilterHeadersStatus PluginContext::onResponseHeaders(uint32_t, bool) { - // strip and store upstream peer metadata - auto upstream_metadata_id = getResponseHeader(ExchangeMetadataHeaderId); - if (upstream_metadata_id != nullptr && !upstream_metadata_id->view().empty()) { - removeResponseHeader(ExchangeMetadataHeaderId); - setFilterState(::Wasm::Common::kUpstreamMetadataIdKey, upstream_metadata_id->view()); - } - - auto upstream_metadata_value = getResponseHeader(ExchangeMetadataHeader); - if (upstream_metadata_value != nullptr && !upstream_metadata_value->view().empty()) { - removeResponseHeader(ExchangeMetadataHeader); - if (!rootContext()->updatePeer(::Wasm::Common::kUpstreamMetadataKey, - upstream_metadata_id->view(), upstream_metadata_value->view())) { - LOG_DEBUG("cannot set upstream peer node"); - } - } - - // do not send response internal headers to sidecar app if it is an outbound - // proxy - if (direction_ != ::Wasm::Common::TrafficDirection::Outbound) { - auto metadata = metadataValue(); - // insert peer metadata struct for downstream - if (!metadata.empty() && metadata_received_) { - replaceResponseHeader(ExchangeMetadataHeader, metadata); - } - - auto nodeid = nodeId(); - if (!nodeid.empty() && metadata_id_received_) { - replaceResponseHeader(ExchangeMetadataHeaderId, nodeid); - } - } - - return FilterHeadersStatus::Continue; -} - -#ifdef NULL_PLUGIN -} // namespace Plugin -} // namespace MetadataExchange -} // namespace null_plugin -} // namespace proxy_wasm -#endif diff --git a/extensions/metadata_exchange/plugin.h b/extensions/metadata_exchange/plugin.h deleted file mode 100644 index fc64cb698b9..00000000000 --- a/extensions/metadata_exchange/plugin.h +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright 2019 Istio Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "extensions/common/context.h" - -#ifndef NULL_PLUGIN - -#include -#define ASSERT(_X) assert(_X) - -#include "proxy_wasm_intrinsics.h" - -static const std::string EMPTY_STRING; - -#else - -#include "include/proxy-wasm/null_plugin.h" - -namespace proxy_wasm { -namespace null_plugin { -namespace MetadataExchange { -namespace Plugin { - -#endif - -constexpr std::string_view ExchangeMetadataHeader = "x-envoy-peer-metadata"; -constexpr std::string_view ExchangeMetadataHeaderId = "x-envoy-peer-metadata-id"; -const size_t DefaultNodeCacheMaxSize = 500; - -// PluginRootContext is the root context for all streams processed by the -// thread. It has the same lifetime as the worker thread and acts as target for -// interactions that outlives individual stream, e.g. timer, async calls. -class PluginRootContext : public RootContext { -public: - PluginRootContext(uint32_t id, std::string_view root_id) : RootContext(id, root_id) {} - bool onConfigure(size_t) override; - bool configure(size_t); - - std::string_view metadataValue() { return metadata_value_; }; - std::string_view nodeId() { return node_id_; }; - bool updatePeer(std::string_view key, std::string_view peer_id, std::string_view peer_header); - -private: - void updateMetadataValue(); - std::string metadata_value_; - std::string node_id_; - - // maps peer ID to the decoded peer flat buffer - std::unordered_map cache_; - int64_t max_peer_cache_size_{DefaultNodeCacheMaxSize}; -}; - -// Per-stream context. -class PluginContext : public Context { -public: - explicit PluginContext(uint32_t id, RootContext* root) : Context(id, root) { - direction_ = ::Wasm::Common::getTrafficDirection(); - } - - FilterHeadersStatus onRequestHeaders(uint32_t, bool) override; - FilterHeadersStatus onResponseHeaders(uint32_t, bool) override; - -private: - inline PluginRootContext* rootContext() { - return dynamic_cast(this->root()); - }; - inline std::string_view metadataValue() { return rootContext()->metadataValue(); }; - inline std::string_view nodeId() { return rootContext()->nodeId(); } - - ::Wasm::Common::TrafficDirection direction_; - bool metadata_received_{true}; - bool metadata_id_received_{true}; -}; - -#ifdef NULL_PLUGIN -} // namespace Plugin -} // namespace MetadataExchange -} // namespace null_plugin -} // namespace proxy_wasm -#endif diff --git a/scripts/release-binary.sh b/scripts/release-binary.sh index 326d3abea47..382ace84437 100755 --- a/scripts/release-binary.sh +++ b/scripts/release-binary.sh @@ -168,38 +168,3 @@ done if [ "${BUILD_ENVOY_BINARY_ONLY}" -eq 1 ]; then exit 0 fi - -# Build and publish Wasm plugins -extensions=(metadata_exchange) -TMP_WASM=$(mktemp -d -t wasm-plugins-XXXXXXXXXX) -trap 'rm -rf ${TMP_WASM}' EXIT -make build_wasm -if [ -n "${DST}" ]; then - for extension in "${extensions[@]}"; do - # Rename the plugin file and generate sha256 for it - WASM_NAME="${extension}-${SHA}.wasm" - WASM_COMPILED_NAME="${extension}-${SHA}.compiled.wasm" - WASM_PATH="${TMP_WASM}/${WASM_NAME}" - WASM_COMPILED_PATH="${TMP_WASM}/${WASM_COMPILED_NAME}" - SHA256_PATH="${WASM_PATH}.sha256" - SHA256_COMPILED_PATH="${WASM_COMPILED_PATH}.sha256" - # shellcheck disable=SC2086 - BAZEL_TARGET=$(bazel info ${BAZEL_BUILD_ARGS} output_path)/${ARCH_NAME}-opt/bin/extensions/${extension}.wasm - # shellcheck disable=SC2086 - BAZEL_COMPILED_TARGET=$(bazel info ${BAZEL_BUILD_ARGS} output_path)/${ARCH_NAME}-opt/bin/extensions/${extension}.compiled.wasm - cp "${BAZEL_TARGET}" "${WASM_PATH}" - cp "${BAZEL_COMPILED_TARGET}" "${WASM_COMPILED_PATH}" - sha256sum "${WASM_PATH}" > "${SHA256_PATH}" - sha256sum "${WASM_COMPILED_PATH}" > "${SHA256_COMPILED_PATH}" - - # push wasm files and sha to the given bucket - gsutil stat "${DST}/${WASM_NAME}" \ - && { echo "WASM file ${WASM_NAME} already exist"; continue; } \ - || echo "Pushing the WASM file ${WASM_NAME}" - gsutil stat "${DST}/${WASM_COMPILED_NAME}" \ - && { echo "WASM file ${WASM_COMPILED_NAME} already exist"; continue; } \ - || echo "Pushing the WASM file ${WASM_COMPILED_NAME}" - gsutil cp "${WASM_PATH}" "${SHA256_PATH}" "${DST}" - gsutil cp "${WASM_COMPILED_PATH}" "${SHA256_COMPILED_PATH}" "${DST}" - done -fi diff --git a/test/envoye2e/http_metadata_exchange/exchange_test.go b/test/envoye2e/http_metadata_exchange/exchange_test.go index c3da6027d21..6e239ace221 100644 --- a/test/envoye2e/http_metadata_exchange/exchange_test.go +++ b/test/envoye2e/http_metadata_exchange/exchange_test.go @@ -39,55 +39,6 @@ func EncodeMetadata(t *testing.T, p *driver.Params) string { return base64.RawStdEncoding.EncodeToString(bytes) } -func TestHTTPExchange(t *testing.T) { - params := driver.NewTestParams(t, map[string]string{}, envoye2e.ProxyE2ETests) - params.Vars["ClientMetadata"] = params.LoadTestData("testdata/client_node_metadata.json.tmpl") - params.Vars["ServerMetadata"] = params.LoadTestData("testdata/server_node_metadata.json.tmpl") - params.Vars["ServerHTTPFilters"] = params.LoadTestData("testdata/filters/mx_inbound.yaml.tmpl") - params.Vars["ClientHTTPFilters"] = params.LoadTestData("testdata/filters/mx_outbound.yaml.tmpl") - if err := (&driver.Scenario{ - Steps: []driver.Step{ - &driver.XDS{}, - &driver.Update{Node: "server", Version: "0", Listeners: []string{driver.LoadTestData("testdata/listener/server.yaml.tmpl")}}, - &driver.Envoy{Bootstrap: params.LoadTestData("testdata/bootstrap/server.yaml.tmpl")}, - &driver.Sleep{Duration: 1 * time.Second}, - &driver.HTTPCall{ - Port: params.Ports.ServerPort, - Body: "hello, world!", - ResponseHeaders: map[string]string{ - "x-envoy-peer-metadata-id": driver.None, - "x-envoy-peer-metadata": driver.None, - }, - }, - &driver.HTTPCall{ - Port: params.Ports.ServerPort, - Body: "hello, world!", - RequestHeaders: map[string]string{ - "x-envoy-peer-metadata-id": "client", - }, - ResponseHeaders: map[string]string{ - "x-envoy-peer-metadata-id": "server", - "x-envoy-peer-metadata": driver.None, - }, - }, - &driver.HTTPCall{ - Port: params.Ports.ServerPort, - Body: "hello, world!", - RequestHeaders: map[string]string{ - "x-envoy-peer-metadata-id": "client", - "x-envoy-peer-metadata": EncodeMetadata(t, params), - }, - ResponseHeaders: map[string]string{ - "x-envoy-peer-metadata-id": "server", - "x-envoy-peer-metadata": driver.Any, - }, - }, - }, - }).Run(params); err != nil { - t.Fatal(err) - } -} - func TestNativeHTTPExchange(t *testing.T) { params := driver.NewTestParams(t, map[string]string{}, envoye2e.ProxyE2ETests) params.Vars["ClientMetadata"] = params.LoadTestData("testdata/client_node_metadata.json.tmpl") diff --git a/test/envoye2e/otel/otel_test.go b/test/envoye2e/otel/otel_test.go index 1cf30c9a427..8cbb9e2d9ad 100644 --- a/test/envoye2e/otel/otel_test.go +++ b/test/envoye2e/otel/otel_test.go @@ -27,8 +27,8 @@ func enableMetadataExchange(t *testing.T, params *driver.Params) { t.Helper() params.Vars["ClientMetadata"] = driver.LoadTestData("testdata/client_node_metadata.json.tmpl") params.Vars["ServerMetadata"] = driver.LoadTestData("testdata/server_node_metadata.json.tmpl") - params.Vars["ClientHTTPFilters"] = driver.LoadTestData("testdata/filters/mx_outbound.yaml.tmpl") - params.Vars["ServerHTTPFilters"] = driver.LoadTestData("testdata/filters/mx_inbound.yaml.tmpl") + params.Vars["ClientHTTPFilters"] = driver.LoadTestData("testdata/filters/mx_native_outbound.yaml.tmpl") + params.Vars["ServerHTTPFilters"] = driver.LoadTestData("testdata/filters/mx_native_inbound.yaml.tmpl") } func enableOtelMetrics(t *testing.T, params *driver.Params, port uint16) { diff --git a/testdata/filters/mx_inbound.yaml.tmpl b/testdata/filters/mx_inbound.yaml.tmpl deleted file mode 100644 index 65623bfeac9..00000000000 --- a/testdata/filters/mx_inbound.yaml.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -- name: mx_inbound{{.N}} - typed_config: - "@type": type.googleapis.com/udpa.type.v1.TypedStruct - type_url: envoy.extensions.filters.http.wasm.v3.Wasm - value: - config: - vm_config: - {{- if .Vars.WasmRuntime }} - runtime: {{ .Vars.WasmRuntime }} - {{- else }} - runtime: envoy.wasm.runtime.null - {{- end }} - code: - {{- if .Vars.MetadataExchangeFilterCode }} - local: { {{ .Vars.MetadataExchangeFilterCode }} } - {{- else }} - local: { inline_string: "envoy.wasm.metadata_exchange" } - {{- end }} - allow_precompiled: true - configuration: - "@type": "type.googleapis.com/google.protobuf.StringValue" - value: | - { "max_peer_cache_size": 20 } diff --git a/testdata/filters/mx_outbound.yaml.tmpl b/testdata/filters/mx_outbound.yaml.tmpl deleted file mode 100644 index 9ce71775372..00000000000 --- a/testdata/filters/mx_outbound.yaml.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -- name: mx_outbound{{.N}} - typed_config: - "@type": type.googleapis.com/udpa.type.v1.TypedStruct - type_url: envoy.extensions.filters.http.wasm.v3.Wasm - value: - config: - vm_config: - {{- if .Vars.WasmRuntime }} - runtime: {{ .Vars.WasmRuntime }} - {{- else }} - runtime: envoy.wasm.runtime.null - {{- end }} - code: - {{- if .Vars.MetadataExchangeFilterCode }} - local: { {{ .Vars.MetadataExchangeFilterCode }} } - {{- else }} - local: { inline_string: "envoy.wasm.metadata_exchange" } - {{- end }} - allow_precompiled: true - configuration: - "@type": "type.googleapis.com/google.protobuf.StringValue" - value: | - { "max_peer_cache_size": 20 }