Skip to content

Commit

Permalink
Avoid capturing logger pointer in callback lambda (envoyproxy#2492)
Browse files Browse the repository at this point in the history
* fix sd filter bugs

* fix test

* remove mesh uid change
  • Loading branch information
bianpengyuan authored and istio-testing committed Oct 29, 2019
1 parent 787a566 commit 30e2f9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 12 additions & 8 deletions extensions/stackdriver/log/exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ namespace Stackdriver {
namespace Log {

ExporterImpl::ExporterImpl(RootContext* root_context,
const std::string& logging_service_endpoint)
: export_call_(MetricType::Counter, "stackdriver_logging_filter",
{MetricTag{"type", MetricTag::TagType::String},
MetricTag{"success", MetricTag::TagType::Bool}}) {
const std::string& logging_service_endpoint) {
context_ = root_context;
success_callback_ = [this](google::protobuf::Empty&&) {
export_call_.increment(1, "logging", true);
Metric export_call(MetricType::Counter, "stackdriver_filter",
{MetricTag{"type", MetricTag::TagType::String},
MetricTag{"success", MetricTag::TagType::Bool}});
auto success_counter = export_call.resolve("logging", true);
auto failure_counter = export_call.resolve("logging", false);
success_callback_ = [success_counter](google::protobuf::Empty&&) {
// TODO(bianpengyuan): replace this with envoy's generic gRPC counter.
incrementMetric(success_counter, 1);
logDebug("successfully sent Stackdriver logging request");
};

failure_callback_ = [this](GrpcStatus status, StringView message) {
failure_callback_ = [failure_counter](GrpcStatus status, StringView message) {
// TODO(bianpengyuan): add retry.
export_call_.increment(1, "logging", false);
// TODO(bianpengyuan): replace this with envoy's generic gRPC counter.
incrementMetric(failure_counter, 1);
logWarn("Stackdriver logging api call error: " +
std::to_string(static_cast<int>(status)) + std::string(message));
};
Expand Down
5 changes: 0 additions & 5 deletions extensions/stackdriver/log/exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ class ExporterImpl : public Exporter {
// Callbacks for gRPC calls.
std::function<void(google::protobuf::Empty&&)> success_callback_;
std::function<void(GrpcStatus, StringView)> failure_callback_;

// Counter of stackdriver export calls, with a boolean label to indicate if
// the call is successful or not and a string label to indicate the type of
// export call.
Metric export_call_;
};

} // namespace Log
Expand Down

0 comments on commit 30e2f9b

Please sign in to comment.