-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Perform lightstep flushing on timer. #119
Changes from 5 commits
ee1263f
b5c8ad3
844db8d
4e97b72
66e8b60
bf07f0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,16 +114,47 @@ void HttpTracerImpl::populateStats(const Decision& decision) { | |
} | ||
} | ||
|
||
LightStepRecorder::LightStepRecorder(const lightstep::TracerImpl& tracer, LightStepSink& sink) | ||
: builder_(tracer), sink_(sink) {} | ||
LightStepRecorder::LightStepRecorder(const lightstep::TracerImpl& tracer, LightStepSink& sink, | ||
Event::Dispatcher& dispatcher) | ||
: builder_(tracer), sink_(sink) { | ||
flush_timer_ = dispatcher.createTimer([this]() -> void { | ||
sink_.tracerStats().timer_flushed_.inc(); | ||
flushSpans(); | ||
uint64_t flush_interval = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: duplicate code here and below can be collapsed into helper function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing |
||
sink_.runtime().snapshot().getInteger("tracing.lightstep.flush_interval_ms", 1000U); | ||
flush_timer_->enableTimer(std::chrono::milliseconds(flush_interval)); | ||
}); | ||
|
||
uint64_t flush_interval = | ||
sink_.runtime().snapshot().getInteger("tracing.lightstep.flush_interval_ms", 1000U); | ||
flush_timer_->enableTimer(std::chrono::milliseconds(flush_interval)); | ||
} | ||
|
||
void LightStepRecorder::RecordSpan(lightstep::collector::Span&& span) { | ||
builder_.addSpan(std::move(span)); | ||
|
||
uint64_t min_flush_spans = | ||
sink_.runtime().snapshot().getInteger("tracing.lightstep.min_flush_spans", 5U); | ||
if (builder_.pendingSpans() == min_flush_spans) { | ||
sink_.tracerStats().spans_sent_.add(min_flush_spans); | ||
flushSpans(); | ||
} | ||
} | ||
|
||
bool LightStepRecorder::FlushWithTimeout(lightstep::Duration) { | ||
// Note: We don't expect this to be called, since the Tracer | ||
// reference is private to its LightStepSink. | ||
return true; | ||
} | ||
|
||
std::unique_ptr<lightstep::Recorder> | ||
LightStepRecorder::NewInstance(LightStepSink& sink, Event::Dispatcher& dispatcher, | ||
const lightstep::TracerImpl& tracer) { | ||
return std::unique_ptr<lightstep::Recorder>(new LightStepRecorder(tracer, sink, dispatcher)); | ||
} | ||
|
||
void LightStepRecorder::flushSpans() { | ||
if (builder_.pendingSpans() != 0) { | ||
sink_.tracerStats().spans_sent_.add(builder_.pendingSpans()); | ||
lightstep::collector::ReportRequest request; | ||
std::swap(request, builder_.pending()); | ||
|
||
|
@@ -133,29 +164,24 @@ void LightStepRecorder::RecordSpan(lightstep::collector::Span&& span) { | |
|
||
message->body(Grpc::Common::serializeBody(std::move(request))); | ||
|
||
uint64_t timeout = | ||
sink_.runtime().snapshot().getInteger("tracing.lightstep.request_timeout", 5000U); | ||
sink_.clusterManager() | ||
.httpAsyncClientForCluster(sink_.collectorCluster()) | ||
.send(std::move(message), *this, std::chrono::milliseconds(5000)); | ||
.send(std::move(message), *this, std::chrono::milliseconds(timeout)); | ||
} | ||
} | ||
|
||
bool LightStepRecorder::FlushWithTimeout(lightstep::Duration) { | ||
// Note: We don't expect this to be called, since the Tracer | ||
// reference is private to its LightStepSink. | ||
return true; | ||
} | ||
|
||
std::unique_ptr<lightstep::Recorder> | ||
LightStepRecorder::NewInstance(LightStepSink& sink, const lightstep::TracerImpl& tracer) { | ||
return std::unique_ptr<lightstep::Recorder>(new LightStepRecorder(tracer, sink)); | ||
} | ||
LightStepSink::TlsLightStepTracer::TlsLightStepTracer(lightstep::Tracer tracer, LightStepSink& sink) | ||
: tracer_(tracer), sink_(sink) {} | ||
|
||
LightStepSink::LightStepSink(const Json::Object& config, Upstream::ClusterManager& cluster_manager, | ||
Stats::Store& stats, const std::string& service_node, | ||
ThreadLocal::Instance& tls, Runtime::Loader& runtime, | ||
Event::Dispatcher& dispatcher, Stats::Store& stats, | ||
const std::string& service_node, ThreadLocal::Instance& tls, | ||
Runtime::Loader& runtime, | ||
std::unique_ptr<lightstep::TracerOptions> options) | ||
: collector_cluster_(config.getString("collector_cluster")), cm_(cluster_manager), | ||
stats_store_(stats), | ||
dispatcher_(dispatcher), stats_store_(stats), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete/don't need any more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
tracer_stats_{LIGHTSTEP_TRACER_STATS(POOL_COUNTER_PREFIX(stats, "tracing.lightstep."))}, | ||
service_node_(service_node), tls_(tls), runtime_(runtime), options_(std::move(options)), | ||
tls_slot_(tls.allocateSlot()) { | ||
|
@@ -169,10 +195,10 @@ LightStepSink::LightStepSink(const Json::Object& config, Upstream::ClusterManage | |
fmt::format("{} collector cluster must support http2 for gRPC calls", collector_cluster_)); | ||
} | ||
|
||
tls_.set(tls_slot_, [this](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectPtr { | ||
tls_.set(tls_slot_, [this](Event::Dispatcher& dispatcher) -> ThreadLocal::ThreadLocalObjectPtr { | ||
lightstep::Tracer tracer(lightstep::NewUserDefinedTransportLightStepTracer( | ||
*options_, | ||
std::bind(&LightStepRecorder::NewInstance, std::ref(*this), std::placeholders::_1))); | ||
*options_, std::bind(&LightStepRecorder::NewInstance, std::ref(*this), std::ref(dispatcher), | ||
std::placeholders::_1))); | ||
|
||
return ThreadLocal::ThreadLocalObjectPtr{new TlsLightStepTracer(std::move(tracer), *this)}; | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,9 @@ struct HttpTracerStats { | |
HTTP_TRACER_STATS(GENERATE_COUNTER_STRUCT) | ||
}; | ||
|
||
#define LIGHTSTEP_TRACER_STATS(COUNTER) COUNTER(spans_sent) | ||
#define LIGHTSTEP_TRACER_STATS(COUNTER) \ | ||
COUNTER(spans_sent) \ | ||
COUNTER(timer_flushed) | ||
|
||
struct LightstepTracerStats { | ||
LIGHTSTEP_TRACER_STATS(GENERATE_COUNTER_STRUCT) | ||
|
@@ -98,8 +100,9 @@ class HttpTracerImpl : public HttpTracer { | |
class LightStepSink : public HttpSink { | ||
public: | ||
LightStepSink(const Json::Object& config, Upstream::ClusterManager& cluster_manager, | ||
Stats::Store& stats, const std::string& service_node, ThreadLocal::Instance& tls, | ||
Runtime::Loader& runtime, std::unique_ptr<lightstep::TracerOptions> options); | ||
Event::Dispatcher& dispatcher, Stats::Store& stats, const std::string& service_node, | ||
ThreadLocal::Instance& tls, Runtime::Loader& runtime, | ||
std::unique_ptr<lightstep::TracerOptions> options); | ||
|
||
// Tracer::HttpSink | ||
void flushTrace(const Http::HeaderMap& request_headers, const Http::HeaderMap& response_headers, | ||
|
@@ -110,14 +113,14 @@ class LightStepSink : public HttpSink { | |
Runtime::Loader& runtime() { return runtime_; } | ||
Stats::Store& statsStore() { return stats_store_; } | ||
LightstepTracerStats& tracerStats() { return tracer_stats_; } | ||
Event::Dispatcher& dispatcher() { return dispatcher_; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
static const std::string LIGHTSTEP_SERVICE; | ||
static const std::string LIGHTSTEP_METHOD; | ||
|
||
private: | ||
struct TlsLightStepTracer : ThreadLocal::ThreadLocalObject { | ||
TlsLightStepTracer(lightstep::Tracer tracer, LightStepSink& sink) | ||
: tracer_(tracer), sink_(sink) {} | ||
TlsLightStepTracer(lightstep::Tracer tracer, LightStepSink& sink); | ||
|
||
void shutdown() override {} | ||
|
||
|
@@ -131,6 +134,7 @@ class LightStepSink : public HttpSink { | |
|
||
const std::string collector_cluster_; | ||
Upstream::ClusterManager& cm_; | ||
Event::Dispatcher& dispatcher_; | ||
Stats::Store& stats_store_; | ||
LightstepTracerStats tracer_stats_; | ||
const std::string service_node_; | ||
|
@@ -142,7 +146,8 @@ class LightStepSink : public HttpSink { | |
|
||
class LightStepRecorder : public lightstep::Recorder, Http::AsyncClient::Callbacks { | ||
public: | ||
LightStepRecorder(const lightstep::TracerImpl& tracer, LightStepSink& sink); | ||
LightStepRecorder(const lightstep::TracerImpl& tracer, LightStepSink& sink, | ||
Event::Dispatcher& dispatcher); | ||
|
||
// lightstep::Recorder | ||
void RecordSpan(lightstep::collector::Span&& span) override; | ||
|
@@ -152,12 +157,15 @@ class LightStepRecorder : public lightstep::Recorder, Http::AsyncClient::Callbac | |
void onSuccess(Http::MessagePtr&&) override; | ||
void onFailure(Http::AsyncClient::FailureReason) override; | ||
|
||
void flushSpans(); | ||
static std::unique_ptr<lightstep::Recorder> NewInstance(LightStepSink& sink, | ||
Event::Dispatcher& dispatcher, | ||
const lightstep::TracerImpl& tracer); | ||
|
||
private: | ||
lightstep::ReportBuilder builder_; | ||
LightStepSink& sink_; | ||
Event::TimerPtr flush_timer_; | ||
}; | ||
|
||
} // Tracing |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ void MainImpl::initializeTracers(const Json::Object& tracing_configuration_) { | |
opts->guid_generator = [&rand]() { return rand.random(); }; | ||
|
||
http_tracer_->addSink(Tracing::HttpSinkPtr{new Tracing::LightStepSink( | ||
sink.getObject("config"), *cluster_manager_, server_.stats(), | ||
sink.getObject("config"), *cluster_manager_, server_.dispatcher(), server_.stats(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
server_.options().serviceNodeName(), server_.threadLocal(), server_.runtime(), | ||
std::move(opts))}); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check pending spans != 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point