Skip to content

Commit

Permalink
make onconfigure work with multiple calls (envoyproxy#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
bianpengyuan authored and istio-testing committed Oct 26, 2019
1 parent 29c0205 commit de7a821
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
6 changes: 6 additions & 0 deletions extensions/stackdriver/common/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ constexpr double kNanosecondsPerMillisecond = 1000000.0;
constexpr char kOutboundRootContextId[] = "stackdriver_outbound";
constexpr char kInboundRootContextId[] = "stackdriver_inbound";

// Stackdriver service endpoint node metadata key.
constexpr char kMonitoringEndpointKey[] = "STACKDRIVER_MONITORING_ENDPOINT";
constexpr char kLoggingEndpointKey[] = "STACKDRIVER_LOGGING_ENDPOINT";
constexpr char kMeshTelemetryEndpointKey[] =
"STACKDRIVER_MESH_TELEMETRY_ENDPOINT";

} // namespace Common
} // namespace Stackdriver
} // namespace Extensions
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package stackdriver.config.v1alpha1;
import "google/protobuf/duration.proto";

message PluginConfig {
// next id: 8
// next id: 5

// Optional. Controls whether to export server access log.
bool disable_server_access_logging = 1;
Expand All @@ -30,25 +30,12 @@ message PluginConfig {
// will be used instead
string destination_service_name = 2;

// Optional. The endpoint that plugin targets for metric reporting. If not
// specified, the default Stackdriver monitoring endpoint will be used.
string test_monitoring_endpoint = 3;

// Optional. The endpoint that plugin targets for access log reporting. If not
// specified, the default Stackdriver logging endpoint will be used.
string test_logging_endpoint = 4;

// Optional. Controls whether or not to export mesh edges to a mesh edges
// service. This is disabled by default.
bool enable_mesh_edges_reporting = 5;

// Optional. The service endpoint that the plugin should use for mesh edges
// reporting. If not specified, the default Stackdriver endpoint will be used
// (when mesh edges reporting is enabled).
string mesh_edges_service_endpoint = 6;
bool enable_mesh_edges_reporting = 3;

// Optional. Allows configuration of the time between calls out to the mesh
// edges service to report edges. The minimum configurable duration is `10s`.
// The default duration is `10m`.
google.protobuf.Duration mesh_edges_reporting_duration = 7;
google.protobuf.Duration mesh_edges_reporting_duration = 4;
}
63 changes: 53 additions & 10 deletions extensions/stackdriver/stackdriver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ constexpr char kExporterRegistered[] = "registered";
constexpr int kDefaultLogExportMilliseconds = 10000; // 10s
constexpr long int kDefaultEdgeReportDurationNanoseconds = 600000000000; // 10m

namespace {

// Gets monitoring service endpoint from node metadata. Returns empty string if
// it is not found.
std::string getMonitoringEndpoint() {
std::string monitoring_service;
if (!getStringValue({"node", "metadata", kMonitoringEndpointKey},
&monitoring_service)) {
return "";
}
return monitoring_service;
}

// Gets logging service endpoint from node metadata. Returns empty string if it
// is not found.
std::string getLoggingEndpoint() {
std::string logging_service;
if (!getStringValue({"node", "metadata", kLoggingEndpointKey},
&logging_service)) {
return "";
}
return logging_service;
}

// Get mesh telemetry service endpoint from node metadata. Returns empty string
// if it is not found.
std::string getMeshTelemetryEndpoint() {
std::string mesh_telemetry_service;
if (!getStringValue({"node", "metadata", kMeshTelemetryEndpointKey},
&mesh_telemetry_service)) {
return "";
}
return mesh_telemetry_service;
}

} // namespace

bool StackdriverRootContext::onConfigure(
std::unique_ptr<WasmData> configuration) {
// Parse configuration JSON string.
Expand All @@ -85,15 +122,22 @@ bool StackdriverRootContext::onConfigure(
logWarn("Unable to get plugin direction");
}

auto exporter =
std::make_unique<ExporterImpl>(this, config_.test_logging_endpoint());
// logger takes ownership of exporter.
logger_ = std::make_unique<Logger>(local_node_info_, std::move(exporter));
if (!logger_) {
// logger should only be initiated once, for now there is no reason to
// recreate logger because of config update.
auto exporter = std::make_unique<ExporterImpl>(this, getLoggingEndpoint());
// logger takes ownership of exporter.
logger_ = std::make_unique<Logger>(local_node_info_, std::move(exporter));
}

auto edges_client = std::make_unique<MeshEdgesServiceClientImpl>(
this, config_.mesh_edges_service_endpoint());
edge_reporter_ =
std::make_unique<EdgeReporter>(local_node_info_, std::move(edges_client));
if (!edge_reporter_) {
// edge reporter should only be initiated once, for now there is no reason
// to recreate edge reporter because of config update.
auto edges_client = std::make_unique<MeshEdgesServiceClientImpl>(
this, getMeshTelemetryEndpoint());
edge_reporter_ = std::make_unique<EdgeReporter>(local_node_info_,
std::move(edges_client));
}

if (config_.has_mesh_edges_reporting_duration()) {
edge_report_duration_nanos_ =
Expand All @@ -113,8 +157,7 @@ bool StackdriverRootContext::onConfigure(

setSharedData(kStackdriverExporter, kExporterRegistered);
opencensus::exporters::stats::StackdriverExporter::Register(
getStackdriverOptions(local_node_info_,
config_.test_monitoring_endpoint()));
getStackdriverOptions(local_node_info_, getMonitoringEndpoint()));

// Register opencensus measures and views.
registerViews();
Expand Down
Binary file added extensions/stats/plugin.wasm
Binary file not shown.
18 changes: 8 additions & 10 deletions test/envoye2e/stackdriver_plugin/stackdriver_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ const outboundStackdriverFilter = `- name: envoy.filters.http.wasm
code:
inline_string: "envoy.wasm.null.stackdriver"
configuration: >-
{
"testMonitoringEndpoint": "localhost:12312",
"testLoggingEndpoint": "localhost:12312",
}`
{}`

const inboundStackdriverFilter = `- name: envoy.filters.http.wasm
config:
Expand All @@ -70,10 +67,7 @@ const inboundStackdriverFilter = `- name: envoy.filters.http.wasm
code:
inline_string: "envoy.wasm.null.stackdriver"
configuration: >-
{
"testMonitoringEndpoint": "localhost:12312",
"testLoggingEndpoint": "localhost:12312",
}`
{}`

const outboundNodeMetadata = `"NAMESPACE": "default",
"INCLUDE_INBOUND_PORTS": "9080",
Expand Down Expand Up @@ -102,7 +96,9 @@ const outboundNodeMetadata = `"NAMESPACE": "default",
"pod-template-hash": "84975bc778"
},
"ISTIO_PROXY_SHA": "istio-proxy:47e4559b8e4f0d516c0d17b233d127a3deb3d7ce",
"NAME": "productpage-v1-84975bc778-pxz2w",`
"NAME": "productpage-v1-84975bc778-pxz2w",
"STACKDRIVER_MONITORING_ENDPOINT": "localhost:12312",
"STACKDRIVER_LOGGING_ENDPOINT": "localhost:12312",`

const inboundNodeMetadata = `"NAMESPACE": "default",
"INCLUDE_INBOUND_PORTS": "9080",
Expand Down Expand Up @@ -131,7 +127,9 @@ const inboundNodeMetadata = `"NAMESPACE": "default",
"pod-template-hash": "84975bc778"
},
"ISTIO_PROXY_SHA": "istio-proxy:47e4559b8e4f0d516c0d17b233d127a3deb3d7ce",
"NAME": "ratings-v1-84975bc778-pxz2w",`
"NAME": "ratings-v1-84975bc778-pxz2w",
"STACKDRIVER_MONITORING_ENDPOINT": "localhost:12312",
"STACKDRIVER_LOGGING_ENDPOINT": "localhost:12312",`

func compareTimeSeries(got, want *monitoringpb.TimeSeries) error {
// ignore time difference
Expand Down

0 comments on commit de7a821

Please sign in to comment.