-
Notifications
You must be signed in to change notification settings - Fork 5.3k
access_logger: correctly throw exception for grpc logger #17908
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
Merged
yanavlasov
merged 10 commits into
envoyproxy:main
from
mathetake:access-logger-exception
Sep 14, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1ca401b
access_logger: correctly throw exception for grpc logger
mathetake 59cc9e3
Fix test
mathetake 8e97897
Add tcp_config_test.
mathetake f1a12db
Merge remote-tracking branch 'origin/main' into access-logger-exception
mathetake 1294f5e
review: add checkActiveStaticCluster in ClusterManager.
mathetake bdb6b20
fix
mathetake 124249b
reviews
mathetake aef67ec
fix tests
mathetake 131b89d
review: throw exceptions in checkActiveStaticCluster.
mathetake f9b3627
Merge remote-tracking branch 'origin/main' into access-logger-exception
mathetake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include "envoy/config/core/v3/grpc_service.pb.h" | ||
| #include "envoy/extensions/access_loggers/grpc/v3/als.pb.h" | ||
| #include "envoy/registry/registry.h" | ||
| #include "envoy/server/access_log_config.h" | ||
| #include "envoy/stats/scope.h" | ||
|
|
||
| #include "source/extensions/access_loggers/grpc/tcp_grpc_access_log_impl.h" | ||
|
|
||
| #include "test/mocks/server/factory_context.h" | ||
|
|
||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using testing::_; | ||
| using testing::Invoke; | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace AccessLoggers { | ||
| namespace TcpGrpc { | ||
| namespace { | ||
|
|
||
| class TcpGrpcAccessLogConfigTest : public testing::Test { | ||
| public: | ||
| void SetUp() override { | ||
| factory_ = | ||
| Registry::FactoryRegistry<Server::Configuration::AccessLogInstanceFactory>::getFactory( | ||
| "envoy.access_loggers.tcp_grpc"); | ||
| ASSERT_NE(nullptr, factory_); | ||
|
|
||
| message_ = factory_->createEmptyConfigProto(); | ||
| ASSERT_NE(nullptr, message_); | ||
| } | ||
|
|
||
| void run(const std::string cluster_name) { | ||
| const auto good_cluster = "good_cluster"; | ||
| EXPECT_CALL(context_.cluster_manager_, checkActiveStaticCluster(cluster_name)) | ||
| .WillOnce(Invoke([good_cluster](const std::string& cluster_name) { | ||
| if (cluster_name != good_cluster) { | ||
| throw EnvoyException("fake"); | ||
| } | ||
| })); | ||
|
|
||
| auto* common_config = tcp_grpc_access_log_.mutable_common_config(); | ||
| common_config->set_log_name("foo"); | ||
| common_config->mutable_grpc_service()->mutable_envoy_grpc()->set_cluster_name(cluster_name); | ||
| common_config->set_transport_api_version(envoy::config::core::v3::ApiVersion::V3); | ||
| TestUtility::jsonConvert(tcp_grpc_access_log_, *message_); | ||
|
|
||
| if (cluster_name == good_cluster) { | ||
| EXPECT_CALL(context_.cluster_manager_.async_client_manager_, factoryForGrpcService(_, _, _)) | ||
| .WillOnce(Invoke([](const envoy::config::core::v3::GrpcService&, Stats::Scope&, bool) { | ||
| return std::make_unique<NiceMock<Grpc::MockAsyncClientFactory>>(); | ||
| })); | ||
| AccessLog::InstanceSharedPtr instance = | ||
| factory_->createAccessLogInstance(*message_, std::move(filter_), context_); | ||
| EXPECT_NE(nullptr, instance); | ||
| EXPECT_NE(nullptr, dynamic_cast<TcpGrpcAccessLog*>(instance.get())); | ||
| } else { | ||
| EXPECT_THROW_WITH_MESSAGE( | ||
| factory_->createAccessLogInstance(*message_, std::move(filter_), context_), | ||
| EnvoyException, "fake"); | ||
| } | ||
| } | ||
|
|
||
| AccessLog::FilterPtr filter_; | ||
| NiceMock<Server::Configuration::MockServerFactoryContext> context_; | ||
| envoy::extensions::access_loggers::grpc::v3::TcpGrpcAccessLogConfig tcp_grpc_access_log_; | ||
| ProtobufTypes::MessagePtr message_; | ||
| Server::Configuration::AccessLogInstanceFactory* factory_{}; | ||
| }; | ||
|
|
||
| // Normal OK configuration. | ||
| TEST_F(TcpGrpcAccessLogConfigTest, Ok) { run("good_cluster"); } | ||
|
|
||
| // Wrong configuration with invalid clusters. | ||
| TEST_F(TcpGrpcAccessLogConfigTest, InvalidCluster) { run("invalid"); } | ||
|
|
||
| } // namespace | ||
| } // namespace TcpGrpc | ||
| } // namespace AccessLoggers | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.