diff --git a/source/server/configuration_impl.cc b/source/server/configuration_impl.cc index b933167533a1..e9c77fc77eeb 100644 --- a/source/server/configuration_impl.cc +++ b/source/server/configuration_impl.cc @@ -92,6 +92,10 @@ void MainImpl::initializeTracers(const Json::Object& tracing_configuration) { opts->access_token = server_.api().fileReadToEnd(driver->getString("access_token_file")); StringUtil::rtrim(opts->access_token); + if (server_.localInfo().clusterName().empty()) { + throw EnvoyException("cluster name must be defined if LightStep tracing is enabled. See " + "--service-cluster option."); + } opts->tracer_attributes["lightstep.component_name"] = server_.localInfo().clusterName(); opts->guid_generator = [&rand]() { return rand.random(); }; diff --git a/test/server/configuration_impl_test.cc b/test/server/configuration_impl_test.cc index 47ab25a072da..f16920b88351 100644 --- a/test/server/configuration_impl_test.cc +++ b/test/server/configuration_impl_test.cc @@ -6,6 +6,7 @@ using testing::InSequence; using testing::Return; +using testing::ReturnRef; namespace Server { namespace Configuration { @@ -119,5 +120,66 @@ TEST(ConfigurationImplTest, BadListenerConfig) { EXPECT_THROW(config.initialize(*loader), Json::Exception); } +TEST(ConfigurationImplTest, ServiceClusterNotSetWhenLSTracing) { + std::string json = R"EOF( + { + "listeners" : [ + { + "port" : 1234, + "filters": [] + } + ], + "cluster_manager": { + "clusters": [] + }, + "tracing": { + "http": { + "driver": { + "type": "lightstep", + "access_token_file": "/etc/envoy/envoy.cfg" + } + } + } + } + )EOF"; + + Json::ObjectPtr loader = Json::Factory::LoadFromString(json); + + NiceMock<Server::MockInstance> server; + server.local_info_.cluster_name_ = ""; + MainImpl config(server); + EXPECT_THROW(config.initialize(*loader), EnvoyException); +} + +TEST(ConfigurationImplTest, UnsupportedDriverType) { + std::string json = R"EOF( + { + "listeners" : [ + { + "port" : 1234, + "filters": [] + } + ], + "cluster_manager": { + "clusters": [] + }, + "tracing": { + "http": { + "driver": { + "type": "unknown", + "access_token_file": "/etc/envoy/envoy.cfg" + } + } + } + } + )EOF"; + + Json::ObjectPtr loader = Json::Factory::LoadFromString(json); + + NiceMock<Server::MockInstance> server; + MainImpl config(server); + EXPECT_THROW(config.initialize(*loader), EnvoyException); +} + } // Configuration } // Server