Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Fix span dropping in RemoteReporter
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Hier <isaachier@gmail.com>
  • Loading branch information
isaachier committed Feb 9, 2018
1 parent c36adcf commit f27c912
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand All @@ -50,7 +49,6 @@ IncludeCategories:
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
Expand All @@ -72,7 +70,6 @@ PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
Expand Down
4 changes: 2 additions & 2 deletions src/jaegertracing/reporters/CompositeReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class CompositeReporter : public Reporter {

~CompositeReporter() { close(); }

void report(const Span& span) override
void report(const Span& span) noexcept override
{
std::for_each(
std::begin(_reporters),
std::end(_reporters),
[&span](const ReporterPtr& reporter) { reporter->report(span); });
}

void close() override
void close() noexcept override
{
std::for_each(std::begin(_reporters),
std::end(_reporters),
Expand Down
10 changes: 5 additions & 5 deletions src/jaegertracing/reporters/InMemoryReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ class InMemoryReporter : public Reporter {
_spans.reserve(kInitialCapacity);
}

void report(const Span& span) override
void report(const Span& span) noexcept override
{
std::lock_guard<std::mutex> lock(_mutex);
_spans.push_back(span);
}

void close() override {}
void close() noexcept override {}

int spansSubmitted() const
int spansSubmitted() const noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
return _spans.size();
}

std::vector<Span> spans() const
std::vector<Span> spans() const noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
return _spans;
}

void reset()
void reset() noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
_spans.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/reporters/LoggingReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace jaegertracing {
namespace reporters {

void LoggingReporter::report(const Span& span)
void LoggingReporter::report(const Span& span) noexcept
{
std::ostringstream oss;
oss << "Reporting span " << span;
Expand Down
4 changes: 2 additions & 2 deletions src/jaegertracing/reporters/LoggingReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class LoggingReporter : public Reporter {
{
}

void report(const Span& span) override;
void report(const Span& span) noexcept override;

void close() override {}
void close() noexcept override {}

private:
logging::Logger& _logger;
Expand Down
4 changes: 2 additions & 2 deletions src/jaegertracing/reporters/NullReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace reporters {

class NullReporter : public Reporter {
public:
void report(const Span&) override {}
void report(const Span&) noexcept override {}

void close() override {}
void close() noexcept override {}
};

} // namespace reporters
Expand Down
32 changes: 17 additions & 15 deletions src/jaegertracing/reporters/RemoteReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RemoteReporter::RemoteReporter(const Clock::duration& bufferFlushInterval,
_thread = std::thread([this]() { sweepQueue(); });
}

void RemoteReporter::report(const Span& span)
void RemoteReporter::report(const Span& span) noexcept
{
std::unique_lock<std::mutex> lock(_mutex);
const auto pushed = (static_cast<int>(_queue.size()) < _fixedQueueSize);
Expand All @@ -60,21 +60,25 @@ void RemoteReporter::report(const Span& span)
}
}

void RemoteReporter::close()
void RemoteReporter::close() noexcept
{
{
std::unique_lock<std::mutex> lock(_mutex);
if (!_running) {
return;
try {
{
std::lock_guard<std::mutex> lock(_mutex);
if (!_running) {
return;
}
_running = false;
flush();
}
_running = false;
lock.unlock();
_cv.notify_one();
_thread.join();
} catch (...) {
utils::ErrorUtil::logError(_logger, "Failed in Reporter::close");
}
_thread.join();
}

void RemoteReporter::sweepQueue()
void RemoteReporter::sweepQueue() noexcept
{
while (true) {
try {
Expand All @@ -97,15 +101,13 @@ void RemoteReporter::sweepQueue()
flush();
}
} catch (...) {
auto logger = logging::consoleLogger();
assert(logger);
utils::ErrorUtil::logError(*logger,
utils::ErrorUtil::logError(_logger,
"Failed in Reporter::sweepQueue");
}
}
}

void RemoteReporter::sendSpan(const Span& span)
void RemoteReporter::sendSpan(const Span& span) noexcept
{
try {
const auto flushed = _sender->append(span);
Expand All @@ -122,7 +124,7 @@ void RemoteReporter::sendSpan(const Span& span)
}
}

void RemoteReporter::flush()
void RemoteReporter::flush() noexcept
{
try {
const auto flushed = _sender->flush();
Expand Down
10 changes: 5 additions & 5 deletions src/jaegertracing/reporters/RemoteReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class RemoteReporter : public Reporter {

~RemoteReporter() { close(); }

void report(const Span& span) override;
void report(const Span& span) noexcept override;

void close() override;
void close() noexcept override;

private:
void sweepQueue();
void sweepQueue() noexcept;

void sendSpan(const Span& span);
void sendSpan(const Span& span) noexcept;

void flush();
void flush() noexcept;

bool bufferFlushIntervalExpired() const
{
Expand Down
4 changes: 2 additions & 2 deletions src/jaegertracing/reporters/Reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Reporter {
public:
virtual ~Reporter() = default;

virtual void report(const Span& span) = 0;
virtual void report(const Span& span) noexcept = 0;

virtual void close() = 0;
virtual void close() noexcept = 0;
};

} // namespace reporters
Expand Down

0 comments on commit f27c912

Please sign in to comment.