From 147748673fa8b7d19b7d9bbda52e6553a80a90e9 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 13 Jul 2021 10:48:49 +0900 Subject: [PATCH 1/9] wasm: delete unused code. Signed-off-by: Takeshi Yoneda --- extensions/attributegen/BUILD | 1 - extensions/common/BUILD | 6 -- extensions/stackdriver/common/BUILD | 1 - extensions/stackdriver/log/BUILD | 1 - extensions/stackdriver/metric/BUILD | 1 - extensions/stats/BUILD | 1 - src/envoy/BUILD | 1 - src/envoy/extensions/wasm/BUILD | 36 ------- src/envoy/extensions/wasm/wasm.cc | 157 ---------------------------- 9 files changed, 205 deletions(-) delete mode 100644 src/envoy/extensions/wasm/BUILD delete mode 100644 src/envoy/extensions/wasm/wasm.cc diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index 20c8d555562..4fbb5565426 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -81,6 +81,5 @@ envoy_extension_cc_test( "@envoy//test/mocks/upstream:upstream_mocks", "@envoy//test/test_common:environment_lib", "@envoy//test/test_common:utility_lib", - "@envoy//test/test_common:wasm_lib", ], ) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index 71996ca5fa2..f235f911e52 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -100,7 +100,6 @@ envoy_cc_test( deps = [ ":node_info_fb_cc", ":proto_util", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -111,7 +110,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":context", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -137,7 +135,6 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -172,7 +169,4 @@ envoy_cc_library( ], repository = "@envoy", visibility = ["//visibility:public"], - deps = [ - "@envoy//source/extensions/common/wasm:wasm_lib", - ], ) diff --git a/extensions/stackdriver/common/BUILD b/extensions/stackdriver/common/BUILD index 82435ad1161..f23b073d8d5 100644 --- a/extensions/stackdriver/common/BUILD +++ b/extensions/stackdriver/common/BUILD @@ -66,7 +66,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":utils", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/log/BUILD b/extensions/stackdriver/log/BUILD index 9a36093b30d..125112cadb6 100644 --- a/extensions/stackdriver/log/BUILD +++ b/extensions/stackdriver/log/BUILD @@ -71,6 +71,5 @@ envoy_cc_test( repository = "@envoy", deps = [ ":logger", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/metric/BUILD b/extensions/stackdriver/metric/BUILD index 550c8a77d39..0923878c5ed 100644 --- a/extensions/stackdriver/metric/BUILD +++ b/extensions/stackdriver/metric/BUILD @@ -54,6 +54,5 @@ envoy_cc_test( repository = "@envoy", deps = [ ":metric", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stats/BUILD b/extensions/stats/BUILD index 8a51e16e36c..b50489d9361 100644 --- a/extensions/stats/BUILD +++ b/extensions/stats/BUILD @@ -60,6 +60,5 @@ envoy_cc_test( deps = [ ":stats_plugin", "//external:abseil_hash_testing", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/src/envoy/BUILD b/src/envoy/BUILD index 643f80b4593..5f35b0f7053 100644 --- a/src/envoy/BUILD +++ b/src/envoy/BUILD @@ -30,7 +30,6 @@ envoy_cc_binary( "//extensions/metadata_exchange:metadata_exchange_lib", "//extensions/stackdriver:stackdriver_plugin", "//extensions/stats:stats_plugin", - "//src/envoy/extensions/wasm:wasm_lib", "//src/envoy/http/alpn:config_lib", "//src/envoy/http/authn:filter_lib", "//src/envoy/tcp/forward_downstream_sni:config_lib", diff --git a/src/envoy/extensions/wasm/BUILD b/src/envoy/extensions/wasm/BUILD deleted file mode 100644 index adbf2f3a036..00000000000 --- a/src/envoy/extensions/wasm/BUILD +++ /dev/null @@ -1,36 +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. -# -################################################################################ -# - -load( - "@envoy//bazel:envoy_build_system.bzl", - "envoy_cc_library", -) - -envoy_cc_library( - name = "wasm_lib", - srcs = [ - "wasm.cc", - ], - repository = "@envoy", - visibility = ["//visibility:public"], - deps = [ - "@envoy//source/common/stats:stats_lib", - "@envoy//source/common/version:version_lib", - "@envoy//source/extensions/common/wasm:wasm_hdr", - "@envoy//source/server/admin:prometheus_stats_lib", - ], -) diff --git a/src/envoy/extensions/wasm/wasm.cc b/src/envoy/extensions/wasm/wasm.cc deleted file mode 100644 index 10db4481bbc..00000000000 --- a/src/envoy/extensions/wasm/wasm.cc +++ /dev/null @@ -1,157 +0,0 @@ -/* Copyright 2018 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 "source/extensions/common/wasm/wasm.h" - -#include "source/common/stats/utility.h" -#include "source/common/version/version.h" -#include "source/server/admin/prometheus_stats.h" - -namespace Envoy { -namespace Extensions { -namespace Common { -namespace Wasm { -namespace Istio { -namespace { - -struct ConfigStats { - ConfigStats(Stats::SymbolTable& symbol_table) - : stat_name_pool_(symbol_table) {} - Stats::StatNamePool stat_name_pool_; - // NB: Use pointers because references must be initialized in the - // initialization list which then would then require that all the component - // stat names to be member variables because stat_name_pool_.add() does not - // dedup so we can not create them as temporaries. - Stats::Counter* permanent_read_error_; - Stats::Counter* eventually_consistent_read_; - Stats::Counter* invalid_module_; - Stats::Counter* invalid_configuration_; -}; - -} // namespace - -class IstioWasmExtension : public EnvoyWasm { - public: - IstioWasmExtension() { - ::Envoy::Server::PrometheusStatsFormatter::registerPrometheusNamespace( - "istio"); - } - ~IstioWasmExtension() override = default; - void onEvent(WasmEvent event, const PluginSharedPtr& plugin) override; - void onRemoteCacheEntriesChanged(int remote_cache_entries) override; - void createStats(const Stats::ScopeSharedPtr& scope, - const PluginSharedPtr& plugin) override; - void resetStats() override; - - private: - std::map> config_stats_; -}; - -static std::string statsKey(const PluginSharedPtr& plugin) { - auto sep = std::string("\t"); - return plugin->name_ + sep + plugin->runtime_; -} - -void IstioWasmExtension::onEvent(WasmEvent event, - const PluginSharedPtr& plugin) { - EnvoyWasm::onEvent(event, plugin); - auto key = statsKey(plugin); - auto& stats = config_stats_.at(key); - switch (event) { - case EnvoyWasm::WasmEvent::Ok: - case EnvoyWasm::WasmEvent::RemoteLoadCacheHit: - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheNegativeHit: - stats->permanent_read_error_->inc(); - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheMiss: - stats->eventually_consistent_read_->inc(); - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchSuccess: - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchFailure: - stats->permanent_read_error_->inc(); - break; - case EnvoyWasm::WasmEvent::UnableToCreateVM: - case EnvoyWasm::WasmEvent::UnableToCloneVM: - case EnvoyWasm::WasmEvent::MissingFunction: - case EnvoyWasm::WasmEvent::UnableToInitializeCode: - stats->invalid_module_->inc(); - break; - case EnvoyWasm::WasmEvent::StartFailed: - case EnvoyWasm::WasmEvent::ConfigureFailed: - stats->invalid_configuration_->inc(); - break; - case EnvoyWasm::WasmEvent::RuntimeError: - break; - } -} - -void IstioWasmExtension::onRemoteCacheEntriesChanged(int entries) { - EnvoyWasm::onRemoteCacheEntriesChanged(entries); -} - -// NB: the "scope" here is tied to the lifetime of the filter chain in many -// cases and may disappear. Code in envoy detects that and will call -// resetStats(). -void IstioWasmExtension::createStats(const Stats::ScopeSharedPtr& scope, - const PluginSharedPtr& plugin) { - EnvoyWasm::createStats(scope, plugin); - std::string istio_version = Envoy::VersionInfo::version(); - auto node_metadata_fields = plugin->localInfo().node().metadata().fields(); - auto istio_version_it = node_metadata_fields.find("ISTIO_VERSION"); - if (istio_version_it != node_metadata_fields.end()) { - istio_version = istio_version_it->second.string_value(); - } - auto key = statsKey(plugin); - if (config_stats_.find(key) == config_stats_.end()) { - auto new_stats = std::make_unique(scope->symbolTable()); - auto& pool = new_stats->stat_name_pool_; - auto prefix = pool.add("istio_wasm_config_errors_total"); - auto error_type = pool.add("error_type"); - auto plugin_name = pool.add("plugin_name"); - auto name = pool.add(plugin->name_); - auto proxy_version = pool.add("proxy_version"); - auto version = pool.add(istio_version); - auto vm = pool.add("vm"); - auto runtime = pool.add(plugin->runtime_); - new_stats->permanent_read_error_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("permanent_read_errors"), - plugin_name, name, proxy_version, version, vm, runtime}); - new_stats->eventually_consistent_read_ = - &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("eventually_consistent_read"), - plugin_name, name, proxy_version, version, vm, runtime}); - new_stats->invalid_module_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("invalid_module"), plugin_name, - name, proxy_version, version, vm, runtime}); - new_stats->invalid_configuration_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("invalid_configuration"), - plugin_name, name, proxy_version, version, vm, runtime}); - config_stats_[key] = std::move(new_stats); - } -} - -void IstioWasmExtension::resetStats() { - EnvoyWasm::resetStats(); - config_stats_.clear(); -} - -REGISTER_WASM_EXTENSION(IstioWasmExtension); - -} // namespace Istio -} // namespace Wasm -} // namespace Common -} // namespace Extensions -} // namespace Envoy From 8f4daeda21189c9d4abfec745a25273262b06f22 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 15 Jul 2021 10:21:14 +0900 Subject: [PATCH 2/9] Add missing lib Signed-off-by: Takeshi Yoneda --- extensions/attributegen/BUILD | 1 + extensions/common/BUILD | 1 + 2 files changed, 2 insertions(+) diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index 19b5bf3bbe0..e5c7e8681a3 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -69,6 +69,7 @@ envoy_extension_cc_test( repository = "@envoy", deps = [ ":attributegen_plugin", + "@envoy//source/extensions/filters/common/expr:cel_state_lib", "@envoy//source/extensions/filters/http/wasm:wasm_filter_lib", "@envoy//test/extensions/common/wasm:wasm_runtime", "@envoy//test/mocks/grpc:grpc_mocks", diff --git a/extensions/common/BUILD b/extensions/common/BUILD index f235f911e52..278a08baebc 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -135,6 +135,7 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", + "@envoy//source/extensions/filters/common/expr:cel_state_lib", ], ) From 0d9539d61c45a71149744482b90c251c096377c5 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 15 Jul 2021 10:29:56 +0900 Subject: [PATCH 3/9] Add missing lib Signed-off-by: Takeshi Yoneda --- extensions/attributegen/BUILD | 2 +- extensions/common/BUILD | 6 +++++- extensions/stackdriver/common/BUILD | 1 + extensions/stackdriver/log/BUILD | 1 + extensions/stackdriver/metric/BUILD | 1 + extensions/stats/BUILD | 1 + 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index e5c7e8681a3..a581f195e04 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -69,7 +69,6 @@ envoy_extension_cc_test( repository = "@envoy", deps = [ ":attributegen_plugin", - "@envoy//source/extensions/filters/common/expr:cel_state_lib", "@envoy//source/extensions/filters/http/wasm:wasm_filter_lib", "@envoy//test/extensions/common/wasm:wasm_runtime", "@envoy//test/mocks/grpc:grpc_mocks", @@ -82,5 +81,6 @@ envoy_extension_cc_test( "@envoy//test/mocks/upstream:upstream_mocks", "@envoy//test/test_common:environment_lib", "@envoy//test/test_common:utility_lib", + "@envoy//test/test_common:wasm_lib", ], ) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index 278a08baebc..ca4e2ec1713 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -110,6 +110,7 @@ envoy_cc_test( repository = "@envoy", deps = [ ":context", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -135,7 +136,7 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", - "@envoy//source/extensions/filters/common/expr:cel_state_lib", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -170,4 +171,7 @@ envoy_cc_library( ], repository = "@envoy", visibility = ["//visibility:public"], + deps = [ + "@envoy//source/extensions/common/wasm:wasm_lib", + ], ) diff --git a/extensions/stackdriver/common/BUILD b/extensions/stackdriver/common/BUILD index f23b073d8d5..82435ad1161 100644 --- a/extensions/stackdriver/common/BUILD +++ b/extensions/stackdriver/common/BUILD @@ -66,6 +66,7 @@ envoy_cc_test( repository = "@envoy", deps = [ ":utils", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/log/BUILD b/extensions/stackdriver/log/BUILD index 125112cadb6..9a36093b30d 100644 --- a/extensions/stackdriver/log/BUILD +++ b/extensions/stackdriver/log/BUILD @@ -71,5 +71,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":logger", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/metric/BUILD b/extensions/stackdriver/metric/BUILD index 0923878c5ed..550c8a77d39 100644 --- a/extensions/stackdriver/metric/BUILD +++ b/extensions/stackdriver/metric/BUILD @@ -54,5 +54,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":metric", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stats/BUILD b/extensions/stats/BUILD index b50489d9361..8a51e16e36c 100644 --- a/extensions/stats/BUILD +++ b/extensions/stats/BUILD @@ -60,5 +60,6 @@ envoy_cc_test( deps = [ ":stats_plugin", "//external:abseil_hash_testing", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) From 95672d2225c7d85559ac6e2136724a4854a965d0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 15 Jul 2021 10:31:05 +0900 Subject: [PATCH 4/9] Add missing lib Signed-off-by: Takeshi Yoneda --- extensions/common/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index ca4e2ec1713..71996ca5fa2 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -100,6 +100,7 @@ envoy_cc_test( deps = [ ":node_info_fb_cc", ":proto_util", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) From 117fb209f77d50e28d7f3b86ded341a88006651d Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 15 Jul 2021 05:45:48 +0000 Subject: [PATCH 5/9] Revert "Add missing lib" This reverts commit 95672d2225c7d85559ac6e2136724a4854a965d0. --- extensions/common/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index 71996ca5fa2..ca4e2ec1713 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -100,7 +100,6 @@ envoy_cc_test( deps = [ ":node_info_fb_cc", ":proto_util", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) From 83445c8fd712a732a66b0892423d3d54b769988f Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 15 Jul 2021 05:45:52 +0000 Subject: [PATCH 6/9] Revert "Add missing lib" This reverts commit 0d9539d61c45a71149744482b90c251c096377c5. --- extensions/attributegen/BUILD | 2 +- extensions/common/BUILD | 6 +----- extensions/stackdriver/common/BUILD | 1 - extensions/stackdriver/log/BUILD | 1 - extensions/stackdriver/metric/BUILD | 1 - extensions/stats/BUILD | 1 - 6 files changed, 2 insertions(+), 10 deletions(-) diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index a581f195e04..e5c7e8681a3 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -69,6 +69,7 @@ envoy_extension_cc_test( repository = "@envoy", deps = [ ":attributegen_plugin", + "@envoy//source/extensions/filters/common/expr:cel_state_lib", "@envoy//source/extensions/filters/http/wasm:wasm_filter_lib", "@envoy//test/extensions/common/wasm:wasm_runtime", "@envoy//test/mocks/grpc:grpc_mocks", @@ -81,6 +82,5 @@ envoy_extension_cc_test( "@envoy//test/mocks/upstream:upstream_mocks", "@envoy//test/test_common:environment_lib", "@envoy//test/test_common:utility_lib", - "@envoy//test/test_common:wasm_lib", ], ) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index ca4e2ec1713..278a08baebc 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -110,7 +110,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":context", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -136,7 +135,7 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", - "@envoy//source/extensions/common/wasm:wasm_lib", + "@envoy//source/extensions/filters/common/expr:cel_state_lib", ], ) @@ -171,7 +170,4 @@ envoy_cc_library( ], repository = "@envoy", visibility = ["//visibility:public"], - deps = [ - "@envoy//source/extensions/common/wasm:wasm_lib", - ], ) diff --git a/extensions/stackdriver/common/BUILD b/extensions/stackdriver/common/BUILD index 82435ad1161..f23b073d8d5 100644 --- a/extensions/stackdriver/common/BUILD +++ b/extensions/stackdriver/common/BUILD @@ -66,7 +66,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":utils", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/log/BUILD b/extensions/stackdriver/log/BUILD index 9a36093b30d..125112cadb6 100644 --- a/extensions/stackdriver/log/BUILD +++ b/extensions/stackdriver/log/BUILD @@ -71,6 +71,5 @@ envoy_cc_test( repository = "@envoy", deps = [ ":logger", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/metric/BUILD b/extensions/stackdriver/metric/BUILD index 550c8a77d39..0923878c5ed 100644 --- a/extensions/stackdriver/metric/BUILD +++ b/extensions/stackdriver/metric/BUILD @@ -54,6 +54,5 @@ envoy_cc_test( repository = "@envoy", deps = [ ":metric", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stats/BUILD b/extensions/stats/BUILD index 8a51e16e36c..b50489d9361 100644 --- a/extensions/stats/BUILD +++ b/extensions/stats/BUILD @@ -60,6 +60,5 @@ envoy_cc_test( deps = [ ":stats_plugin", "//external:abseil_hash_testing", - "@envoy//source/extensions/common/wasm:wasm_lib", ], ) From 80fecc4922b0a6bdcedff40d1dc8071971d0fa18 Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 15 Jul 2021 05:45:54 +0000 Subject: [PATCH 7/9] Revert "Add missing lib" This reverts commit 8f4daeda21189c9d4abfec745a25273262b06f22. --- extensions/attributegen/BUILD | 1 - extensions/common/BUILD | 1 - 2 files changed, 2 deletions(-) diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index e5c7e8681a3..19b5bf3bbe0 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -69,7 +69,6 @@ envoy_extension_cc_test( repository = "@envoy", deps = [ ":attributegen_plugin", - "@envoy//source/extensions/filters/common/expr:cel_state_lib", "@envoy//source/extensions/filters/http/wasm:wasm_filter_lib", "@envoy//test/extensions/common/wasm:wasm_runtime", "@envoy//test/mocks/grpc:grpc_mocks", diff --git a/extensions/common/BUILD b/extensions/common/BUILD index 278a08baebc..f235f911e52 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -135,7 +135,6 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", - "@envoy//source/extensions/filters/common/expr:cel_state_lib", ], ) From cb384a9aed959feb858da7e6ce7dbac8f963cb18 Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 15 Jul 2021 05:47:16 +0000 Subject: [PATCH 8/9] Revert "wasm: delete unused code." This reverts commit 147748673fa8b7d19b7d9bbda52e6553a80a90e9. --- extensions/attributegen/BUILD | 1 + extensions/common/BUILD | 6 ++ extensions/stackdriver/common/BUILD | 1 + extensions/stackdriver/log/BUILD | 1 + extensions/stackdriver/metric/BUILD | 1 + extensions/stats/BUILD | 1 + src/envoy/BUILD | 1 + src/envoy/extensions/wasm/BUILD | 36 +++++++ src/envoy/extensions/wasm/wasm.cc | 157 ++++++++++++++++++++++++++++ 9 files changed, 205 insertions(+) create mode 100644 src/envoy/extensions/wasm/BUILD create mode 100644 src/envoy/extensions/wasm/wasm.cc diff --git a/extensions/attributegen/BUILD b/extensions/attributegen/BUILD index 19b5bf3bbe0..a581f195e04 100644 --- a/extensions/attributegen/BUILD +++ b/extensions/attributegen/BUILD @@ -81,5 +81,6 @@ envoy_extension_cc_test( "@envoy//test/mocks/upstream:upstream_mocks", "@envoy//test/test_common:environment_lib", "@envoy//test/test_common:utility_lib", + "@envoy//test/test_common:wasm_lib", ], ) diff --git a/extensions/common/BUILD b/extensions/common/BUILD index f235f911e52..71996ca5fa2 100644 --- a/extensions/common/BUILD +++ b/extensions/common/BUILD @@ -100,6 +100,7 @@ envoy_cc_test( deps = [ ":node_info_fb_cc", ":proto_util", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -110,6 +111,7 @@ envoy_cc_test( repository = "@envoy", deps = [ ":context", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -135,6 +137,7 @@ envoy_cc_benchmark_binary( ":node_info_fb_cc", ":proto_util", "@envoy//source/common/stream_info:filter_state_lib", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) @@ -169,4 +172,7 @@ envoy_cc_library( ], repository = "@envoy", visibility = ["//visibility:public"], + deps = [ + "@envoy//source/extensions/common/wasm:wasm_lib", + ], ) diff --git a/extensions/stackdriver/common/BUILD b/extensions/stackdriver/common/BUILD index f23b073d8d5..82435ad1161 100644 --- a/extensions/stackdriver/common/BUILD +++ b/extensions/stackdriver/common/BUILD @@ -66,6 +66,7 @@ envoy_cc_test( repository = "@envoy", deps = [ ":utils", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/log/BUILD b/extensions/stackdriver/log/BUILD index 125112cadb6..9a36093b30d 100644 --- a/extensions/stackdriver/log/BUILD +++ b/extensions/stackdriver/log/BUILD @@ -71,5 +71,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":logger", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stackdriver/metric/BUILD b/extensions/stackdriver/metric/BUILD index 0923878c5ed..550c8a77d39 100644 --- a/extensions/stackdriver/metric/BUILD +++ b/extensions/stackdriver/metric/BUILD @@ -54,5 +54,6 @@ envoy_cc_test( repository = "@envoy", deps = [ ":metric", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/extensions/stats/BUILD b/extensions/stats/BUILD index b50489d9361..8a51e16e36c 100644 --- a/extensions/stats/BUILD +++ b/extensions/stats/BUILD @@ -60,5 +60,6 @@ envoy_cc_test( deps = [ ":stats_plugin", "//external:abseil_hash_testing", + "@envoy//source/extensions/common/wasm:wasm_lib", ], ) diff --git a/src/envoy/BUILD b/src/envoy/BUILD index 5f35b0f7053..643f80b4593 100644 --- a/src/envoy/BUILD +++ b/src/envoy/BUILD @@ -30,6 +30,7 @@ envoy_cc_binary( "//extensions/metadata_exchange:metadata_exchange_lib", "//extensions/stackdriver:stackdriver_plugin", "//extensions/stats:stats_plugin", + "//src/envoy/extensions/wasm:wasm_lib", "//src/envoy/http/alpn:config_lib", "//src/envoy/http/authn:filter_lib", "//src/envoy/tcp/forward_downstream_sni:config_lib", diff --git a/src/envoy/extensions/wasm/BUILD b/src/envoy/extensions/wasm/BUILD new file mode 100644 index 00000000000..adbf2f3a036 --- /dev/null +++ b/src/envoy/extensions/wasm/BUILD @@ -0,0 +1,36 @@ +# 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. +# +################################################################################ +# + +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_library", +) + +envoy_cc_library( + name = "wasm_lib", + srcs = [ + "wasm.cc", + ], + repository = "@envoy", + visibility = ["//visibility:public"], + deps = [ + "@envoy//source/common/stats:stats_lib", + "@envoy//source/common/version:version_lib", + "@envoy//source/extensions/common/wasm:wasm_hdr", + "@envoy//source/server/admin:prometheus_stats_lib", + ], +) diff --git a/src/envoy/extensions/wasm/wasm.cc b/src/envoy/extensions/wasm/wasm.cc new file mode 100644 index 00000000000..10db4481bbc --- /dev/null +++ b/src/envoy/extensions/wasm/wasm.cc @@ -0,0 +1,157 @@ +/* Copyright 2018 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 "source/extensions/common/wasm/wasm.h" + +#include "source/common/stats/utility.h" +#include "source/common/version/version.h" +#include "source/server/admin/prometheus_stats.h" + +namespace Envoy { +namespace Extensions { +namespace Common { +namespace Wasm { +namespace Istio { +namespace { + +struct ConfigStats { + ConfigStats(Stats::SymbolTable& symbol_table) + : stat_name_pool_(symbol_table) {} + Stats::StatNamePool stat_name_pool_; + // NB: Use pointers because references must be initialized in the + // initialization list which then would then require that all the component + // stat names to be member variables because stat_name_pool_.add() does not + // dedup so we can not create them as temporaries. + Stats::Counter* permanent_read_error_; + Stats::Counter* eventually_consistent_read_; + Stats::Counter* invalid_module_; + Stats::Counter* invalid_configuration_; +}; + +} // namespace + +class IstioWasmExtension : public EnvoyWasm { + public: + IstioWasmExtension() { + ::Envoy::Server::PrometheusStatsFormatter::registerPrometheusNamespace( + "istio"); + } + ~IstioWasmExtension() override = default; + void onEvent(WasmEvent event, const PluginSharedPtr& plugin) override; + void onRemoteCacheEntriesChanged(int remote_cache_entries) override; + void createStats(const Stats::ScopeSharedPtr& scope, + const PluginSharedPtr& plugin) override; + void resetStats() override; + + private: + std::map> config_stats_; +}; + +static std::string statsKey(const PluginSharedPtr& plugin) { + auto sep = std::string("\t"); + return plugin->name_ + sep + plugin->runtime_; +} + +void IstioWasmExtension::onEvent(WasmEvent event, + const PluginSharedPtr& plugin) { + EnvoyWasm::onEvent(event, plugin); + auto key = statsKey(plugin); + auto& stats = config_stats_.at(key); + switch (event) { + case EnvoyWasm::WasmEvent::Ok: + case EnvoyWasm::WasmEvent::RemoteLoadCacheHit: + break; + case EnvoyWasm::WasmEvent::RemoteLoadCacheNegativeHit: + stats->permanent_read_error_->inc(); + break; + case EnvoyWasm::WasmEvent::RemoteLoadCacheMiss: + stats->eventually_consistent_read_->inc(); + break; + case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchSuccess: + break; + case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchFailure: + stats->permanent_read_error_->inc(); + break; + case EnvoyWasm::WasmEvent::UnableToCreateVM: + case EnvoyWasm::WasmEvent::UnableToCloneVM: + case EnvoyWasm::WasmEvent::MissingFunction: + case EnvoyWasm::WasmEvent::UnableToInitializeCode: + stats->invalid_module_->inc(); + break; + case EnvoyWasm::WasmEvent::StartFailed: + case EnvoyWasm::WasmEvent::ConfigureFailed: + stats->invalid_configuration_->inc(); + break; + case EnvoyWasm::WasmEvent::RuntimeError: + break; + } +} + +void IstioWasmExtension::onRemoteCacheEntriesChanged(int entries) { + EnvoyWasm::onRemoteCacheEntriesChanged(entries); +} + +// NB: the "scope" here is tied to the lifetime of the filter chain in many +// cases and may disappear. Code in envoy detects that and will call +// resetStats(). +void IstioWasmExtension::createStats(const Stats::ScopeSharedPtr& scope, + const PluginSharedPtr& plugin) { + EnvoyWasm::createStats(scope, plugin); + std::string istio_version = Envoy::VersionInfo::version(); + auto node_metadata_fields = plugin->localInfo().node().metadata().fields(); + auto istio_version_it = node_metadata_fields.find("ISTIO_VERSION"); + if (istio_version_it != node_metadata_fields.end()) { + istio_version = istio_version_it->second.string_value(); + } + auto key = statsKey(plugin); + if (config_stats_.find(key) == config_stats_.end()) { + auto new_stats = std::make_unique(scope->symbolTable()); + auto& pool = new_stats->stat_name_pool_; + auto prefix = pool.add("istio_wasm_config_errors_total"); + auto error_type = pool.add("error_type"); + auto plugin_name = pool.add("plugin_name"); + auto name = pool.add(plugin->name_); + auto proxy_version = pool.add("proxy_version"); + auto version = pool.add(istio_version); + auto vm = pool.add("vm"); + auto runtime = pool.add(plugin->runtime_); + new_stats->permanent_read_error_ = &Stats::Utility::counterFromElements( + *scope, {prefix, error_type, pool.add("permanent_read_errors"), + plugin_name, name, proxy_version, version, vm, runtime}); + new_stats->eventually_consistent_read_ = + &Stats::Utility::counterFromElements( + *scope, {prefix, error_type, pool.add("eventually_consistent_read"), + plugin_name, name, proxy_version, version, vm, runtime}); + new_stats->invalid_module_ = &Stats::Utility::counterFromElements( + *scope, {prefix, error_type, pool.add("invalid_module"), plugin_name, + name, proxy_version, version, vm, runtime}); + new_stats->invalid_configuration_ = &Stats::Utility::counterFromElements( + *scope, {prefix, error_type, pool.add("invalid_configuration"), + plugin_name, name, proxy_version, version, vm, runtime}); + config_stats_[key] = std::move(new_stats); + } +} + +void IstioWasmExtension::resetStats() { + EnvoyWasm::resetStats(); + config_stats_.clear(); +} + +REGISTER_WASM_EXTENSION(IstioWasmExtension); + +} // namespace Istio +} // namespace Wasm +} // namespace Common +} // namespace Extensions +} // namespace Envoy From ecd9b93cb07a463a6758acc00ba9fb3bdd36c2d1 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 15 Jul 2021 14:53:38 +0900 Subject: [PATCH 9/9] Register Istio namespace. Signed-off-by: Takeshi Yoneda --- src/envoy/extensions/wasm/BUILD | 2 - src/envoy/extensions/wasm/wasm.cc | 128 ++---------------------------- 2 files changed, 6 insertions(+), 124 deletions(-) diff --git a/src/envoy/extensions/wasm/BUILD b/src/envoy/extensions/wasm/BUILD index adbf2f3a036..f016ee164cd 100644 --- a/src/envoy/extensions/wasm/BUILD +++ b/src/envoy/extensions/wasm/BUILD @@ -29,8 +29,6 @@ envoy_cc_library( visibility = ["//visibility:public"], deps = [ "@envoy//source/common/stats:stats_lib", - "@envoy//source/common/version:version_lib", - "@envoy//source/extensions/common/wasm:wasm_hdr", "@envoy//source/server/admin:prometheus_stats_lib", ], ) diff --git a/src/envoy/extensions/wasm/wasm.cc b/src/envoy/extensions/wasm/wasm.cc index 10db4481bbc..a8f1b45c372 100644 --- a/src/envoy/extensions/wasm/wasm.cc +++ b/src/envoy/extensions/wasm/wasm.cc @@ -12,10 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "source/extensions/common/wasm/wasm.h" - #include "source/common/stats/utility.h" -#include "source/common/version/version.h" #include "source/server/admin/prometheus_stats.h" namespace Envoy { @@ -23,132 +20,19 @@ namespace Extensions { namespace Common { namespace Wasm { namespace Istio { -namespace { - -struct ConfigStats { - ConfigStats(Stats::SymbolTable& symbol_table) - : stat_name_pool_(symbol_table) {} - Stats::StatNamePool stat_name_pool_; - // NB: Use pointers because references must be initialized in the - // initialization list which then would then require that all the component - // stat names to be member variables because stat_name_pool_.add() does not - // dedup so we can not create them as temporaries. - Stats::Counter* permanent_read_error_; - Stats::Counter* eventually_consistent_read_; - Stats::Counter* invalid_module_; - Stats::Counter* invalid_configuration_; -}; - -} // namespace -class IstioWasmExtension : public EnvoyWasm { +// Stat prefix cannot be configured dynamically. +// https://github.com/envoyproxy/envoy/issues/14920 +// https://github.com/istio/istio/issues/27635 +class RegisterPrometheusNamespace { public: - IstioWasmExtension() { + RegisterPrometheusNamespace() { ::Envoy::Server::PrometheusStatsFormatter::registerPrometheusNamespace( "istio"); } - ~IstioWasmExtension() override = default; - void onEvent(WasmEvent event, const PluginSharedPtr& plugin) override; - void onRemoteCacheEntriesChanged(int remote_cache_entries) override; - void createStats(const Stats::ScopeSharedPtr& scope, - const PluginSharedPtr& plugin) override; - void resetStats() override; - - private: - std::map> config_stats_; }; -static std::string statsKey(const PluginSharedPtr& plugin) { - auto sep = std::string("\t"); - return plugin->name_ + sep + plugin->runtime_; -} - -void IstioWasmExtension::onEvent(WasmEvent event, - const PluginSharedPtr& plugin) { - EnvoyWasm::onEvent(event, plugin); - auto key = statsKey(plugin); - auto& stats = config_stats_.at(key); - switch (event) { - case EnvoyWasm::WasmEvent::Ok: - case EnvoyWasm::WasmEvent::RemoteLoadCacheHit: - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheNegativeHit: - stats->permanent_read_error_->inc(); - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheMiss: - stats->eventually_consistent_read_->inc(); - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchSuccess: - break; - case EnvoyWasm::WasmEvent::RemoteLoadCacheFetchFailure: - stats->permanent_read_error_->inc(); - break; - case EnvoyWasm::WasmEvent::UnableToCreateVM: - case EnvoyWasm::WasmEvent::UnableToCloneVM: - case EnvoyWasm::WasmEvent::MissingFunction: - case EnvoyWasm::WasmEvent::UnableToInitializeCode: - stats->invalid_module_->inc(); - break; - case EnvoyWasm::WasmEvent::StartFailed: - case EnvoyWasm::WasmEvent::ConfigureFailed: - stats->invalid_configuration_->inc(); - break; - case EnvoyWasm::WasmEvent::RuntimeError: - break; - } -} - -void IstioWasmExtension::onRemoteCacheEntriesChanged(int entries) { - EnvoyWasm::onRemoteCacheEntriesChanged(entries); -} - -// NB: the "scope" here is tied to the lifetime of the filter chain in many -// cases and may disappear. Code in envoy detects that and will call -// resetStats(). -void IstioWasmExtension::createStats(const Stats::ScopeSharedPtr& scope, - const PluginSharedPtr& plugin) { - EnvoyWasm::createStats(scope, plugin); - std::string istio_version = Envoy::VersionInfo::version(); - auto node_metadata_fields = plugin->localInfo().node().metadata().fields(); - auto istio_version_it = node_metadata_fields.find("ISTIO_VERSION"); - if (istio_version_it != node_metadata_fields.end()) { - istio_version = istio_version_it->second.string_value(); - } - auto key = statsKey(plugin); - if (config_stats_.find(key) == config_stats_.end()) { - auto new_stats = std::make_unique(scope->symbolTable()); - auto& pool = new_stats->stat_name_pool_; - auto prefix = pool.add("istio_wasm_config_errors_total"); - auto error_type = pool.add("error_type"); - auto plugin_name = pool.add("plugin_name"); - auto name = pool.add(plugin->name_); - auto proxy_version = pool.add("proxy_version"); - auto version = pool.add(istio_version); - auto vm = pool.add("vm"); - auto runtime = pool.add(plugin->runtime_); - new_stats->permanent_read_error_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("permanent_read_errors"), - plugin_name, name, proxy_version, version, vm, runtime}); - new_stats->eventually_consistent_read_ = - &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("eventually_consistent_read"), - plugin_name, name, proxy_version, version, vm, runtime}); - new_stats->invalid_module_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("invalid_module"), plugin_name, - name, proxy_version, version, vm, runtime}); - new_stats->invalid_configuration_ = &Stats::Utility::counterFromElements( - *scope, {prefix, error_type, pool.add("invalid_configuration"), - plugin_name, name, proxy_version, version, vm, runtime}); - config_stats_[key] = std::move(new_stats); - } -} - -void IstioWasmExtension::resetStats() { - EnvoyWasm::resetStats(); - config_stats_.clear(); -} - -REGISTER_WASM_EXTENSION(IstioWasmExtension); +RegisterPrometheusNamespace register_namespace; } // namespace Istio } // namespace Wasm