Skip to content

Feat[bmq]: Add interfaces in DTTracer to serialize and deserialize span #627

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,12 @@ class DTTestSpan : public bmqpi::DTSpan {
{
return d_operation;
}

int finish() const BSLS_KEYWORD_OVERRIDE
{
// NOT IMPLEMENTED
return 0;
}
};

class DTTestTracer : public bmqpi::DTTracer {
Expand Down Expand Up @@ -2834,6 +2840,26 @@ class DTTestTracer : public bmqpi::DTTracer {
d_allocator_p);
return result;
}

int
serializeSpan(BSLS_ANNOTATION_UNUSED bsl::vector<unsigned char>* buffer,
BSLS_ANNOTATION_UNUSED const bsl::shared_ptr<bmqpi::DTSpan>&
dtSpan) const BSLS_KEYWORD_OVERRIDE
{
// NOT IMPLEMENTED
return 0;
}

int deserializeAndCreateChildSpan(
BSLS_ANNOTATION_UNUSED bsl::shared_ptr<bmqpi::DTSpan>* child,
BSLS_ANNOTATION_UNUSED const bsl::vector<unsigned char>& buffer,
BSLS_ANNOTATION_UNUSED const bsl::string_view& operation,
BSLS_ANNOTATION_UNUSED const bmqpi::DTSpan::Baggage& baggage) const
BSLS_KEYWORD_OVERRIDE
{
// NOT IMPLEMENTED
return 0;
}
};

} // close unnamed namespace
Expand Down
8 changes: 8 additions & 0 deletions src/groups/bmq/bmqpi/bmqpi_dtspan.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ class DTSpan {
// PUBLIC CREATORS

/// Destructor
/// Upon destruction, `finish()` will be called to mark the end of a span.
virtual ~DTSpan();

// PUBLIC ACCESSORS

/// Returns the name of the operation that this `DTSpan` represents.
virtual bsl::string_view operation() const = 0;

/// Mark the end of the `DTSpan`. Only the timing of the first call for a
/// given `DTSpan` will be recorded, and implementations are free to ignore
/// all further calls. A finished Span can not be re-started. If finish()
/// is not directly called, it will be called from the destructor.
/// Return 0 on success, or a non-zero error code on error.
virtual int finish() const = 0;

// =============
// class Baggage
// =============
Expand Down
6 changes: 6 additions & 0 deletions src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace BloombergLP;
/// A test implementation of the `bmqpi::DTSpan` protocol.
struct DTSpanTestImp : public bsls::ProtocolTestImp<bmqpi::DTSpan> {
bsl::string_view operation() const BSLS_KEYWORD_OVERRIDE;
int finish() const BSLS_KEYWORD_OVERRIDE;
};

// Define one of DTSpanTestImp methods out-of-line, to instruct the compiler to
Expand All @@ -38,6 +39,11 @@ bsl::string_view DTSpanTestImp::operation() const
return markDone();
}

int DTSpanTestImp::finish() const
{
return markDone();
};

// ============================================================================
// TESTS
// ============================================================================
Expand Down
17 changes: 17 additions & 0 deletions src/groups/bmq/bmqpi/bmqpi_dttracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// BDE
#include <bsl_memory.h>
#include <bsl_string_view.h>
#include <bsl_vector.h>

namespace BloombergLP {
namespace bmqpi {
Expand All @@ -56,6 +57,22 @@ class DTTracer {
const bsl::shared_ptr<DTSpan>& parent,
const bsl::string_view& operation,
const DTSpan::Baggage& baggage = DTSpan::Baggage()) const = 0;

/// Serialize the specified `dtSpan` into the specified `buffer`.
/// Return 0 on success, or a non-zero error code on error with `buffer`
/// being valid-but-unspecified.
virtual int serializeSpan(bsl::vector<unsigned char>* buffer,
const bsl::shared_ptr<DTSpan>& dtSpan) const = 0;

/// Deserialize the specified `buffer` as a span, and then construct a
/// new `DTSpan` in `child`, representing `operation` as a child of the
/// deserialized span and having the key-value tags defined by `baggage`.
/// Return 0 on success, or a non-zero error code on error.
virtual int deserializeAndCreateChildSpan(
bsl::shared_ptr<DTSpan>* child,
const bsl::vector<unsigned char>& buffer,
const bsl::string_view& operation,
const DTSpan::Baggage& baggage = DTSpan::Baggage()) const = 0;
};

} // close package namespace
Expand Down
35 changes: 33 additions & 2 deletions src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ using namespace BloombergLP;

/// A test implementation of the `bmqpi::DTTracer` protocol.
struct DTTracerTestImp : public bsls::ProtocolTestImp<bmqpi::DTTracer> {
virtual bsl::shared_ptr<bmqpi::DTSpan> createChildSpan(
bsl::shared_ptr<bmqpi::DTSpan> createChildSpan(
const bsl::shared_ptr<bmqpi::DTSpan>& parent,
const bsl::string_view& operation,
const bmqpi::DTSpan::Baggage& baggage) const BSLS_KEYWORD_OVERRIDE;

int serializeSpan(bsl::vector<unsigned char>* buffer,
const bsl::shared_ptr<bmqpi::DTSpan>& dtSpan) const
BSLS_KEYWORD_OVERRIDE;

int deserializeAndCreateChildSpan(
bsl::shared_ptr<bmqpi::DTSpan>* child,
const bsl::vector<unsigned char>& buffer,
const bsl::string_view& operation,
const bmqpi::DTSpan::Baggage& baggage = bmqpi::DTSpan::Baggage()) const
BSLS_KEYWORD_OVERRIDE;
};

// Define one of DTTracerTestImp methods out-of-line, to instruct the
Expand All @@ -47,6 +58,21 @@ DTTracerTestImp::createChildSpan(const bsl::shared_ptr<bmqpi::DTSpan>&,
return markDone();
}

int DTTracerTestImp::serializeSpan(bsl::vector<unsigned char>*,
const bsl::shared_ptr<bmqpi::DTSpan>&) const
{
return markDone();
}

int DTTracerTestImp::deserializeAndCreateChildSpan(
bsl::shared_ptr<bmqpi::DTSpan>*,
const bsl::vector<unsigned char>&,
const bsl::string_view&,
const bmqpi::DTSpan::Baggage&) const
{
return markDone();
}

// ============================================================================
// TESTS
// ============================================================================
Expand Down Expand Up @@ -100,8 +126,13 @@ static void test1_breathingTest()
BMQTST_ASSERT(tracer.testVirtualDestructor());

PV("Verify that all methods are public and virtual");
bmqpi::DTSpan::Baggage empty;
bmqpi::DTSpan::Baggage empty(bmqtst::TestHelperUtil::allocator());
bsl::vector<unsigned char> emptyVec(bmqtst::TestHelperUtil::allocator());
BSLS_PROTOCOLTEST_ASSERT(tracer, createChildSpan(NULL, "", empty));
BSLS_PROTOCOLTEST_ASSERT(tracer, serializeSpan(NULL, NULL));
BSLS_PROTOCOLTEST_ASSERT(
tracer,
deserializeAndCreateChildSpan(NULL, emptyVec, "", empty));
}

// ============================================================================
Expand Down
Loading