Skip to content
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

HPCC-32691 Add optional timestamp arg to createClientSpan() #18969

Merged

Conversation

mckellyln
Copy link
Contributor

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Cloud-compatibility
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Smoketest:

  • Send notifications about my Pull Request position in Smoketest queue.
  • Test my draft Pull Request.

Testing:

@mckellyln
Copy link
Contributor Author

@rpastrana here are my quick changes to be able to call createClientSpan() with a starting timestamp so that we can time something and if that time exceeds a threshold we then create the span.

@mckellyln
Copy link
Contributor Author

mckellyln commented Aug 8, 2024

I am using this code via -

                SpanTimeStamp SpanTS;
                SpanTS.setMSTickTime(startms);
                Owned<ISpan> clientSpan = ctx->queryContextLogger().queryActiveSpan()->createClientSpan("method-name", &SpanTS);
                StringBuffer endPoint(host);
                endPoint.appendf(":%d", port);
                clientSpan->setSpanAttribute("server", endPoint.str());
                clientSpan->setSpanStatusSuccess(true);

@mckellyln mckellyln requested a review from rpastrana August 8, 2024 01:04
@mckellyln
Copy link
Contributor Author

@rpastrana - Should I create a real Pull Request for this ?

@rpastrana
Copy link
Member

@mckellyln yes let's move forward with this.
I'm not sure if the internal spans would benefit much from this feature or not, but if nothing else, for symmetry let's add the optional start timestamp to the createinternalspans as well.

Copy link
Member

@rpastrana rpastrana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mckellyln seems fine, consider extending feature to createInternal. Also, should add unittets:

class JlibTraceTest : public CppUnit::TestFixture

@@ -557,7 +557,7 @@ class CSpan : public CInterfaceOf<ISpan>
return spanID.get();
}

ISpan * createClientSpan(const char * name) override;
ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override;
ISpan * createInternalSpan(const char * name) override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add optional spansparttime to createInternalSpan as well?

: CChildSpan(spanName, parent)
{
if (spanStartTimeStamp && spanStartTimeStamp->isInitialized())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we add the starttime option to internal, it might make sense to move this to CChildSpan?

@mckellyln mckellyln force-pushed the timestamp_client_span branch from a46d622 to 4a01adf Compare August 30, 2024 13:36
@mckellyln mckellyln force-pushed the timestamp_client_span branch 2 times, most recently from 8afcaa6 to efa28e8 Compare September 19, 2024 19:46
@mckellyln mckellyln changed the title HPCC-00000 Add optional timestamp arg to createClientSpan() HPCC-32691 Add optional timestamp arg to createClientSpan() Sep 19, 2024
@mckellyln mckellyln marked this pull request as ready for review September 19, 2024 23:02
@mckellyln mckellyln requested a review from rpastrana September 19, 2024 23:02
@mckellyln mckellyln force-pushed the timestamp_client_span branch from e6f0432 to 8aebdec Compare September 19, 2024 23:25
@mckellyln
Copy link
Contributor Author

@rpastrana I've updated PR and added a test case.

Copy link
Member

@rpastrana rpastrana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mckellyln looks good, but a couple of questions re: unittests

@@ -482,11 +483,33 @@ class JlibTraceTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected",
strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID")));

CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected missing remoteParentID detected", true,
retrievedSpanCtxAttributes->hasProp("remoteParentID"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected GlobalID detected", false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these changes seem unrelated.

unsigned startMs = msTick() - 1234;
SpanTimeStamp SpanTS;
SpanTS.setMSTickTime(startMs);
OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpan", &SpanTS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L:503 exercises the new constructor signature, but the bulk of this test seems unrelated to the functionality we want to test which is the span's manually declared start time. I think manualTestsDeclaredSpanStartTime could be used as a template to test this new functionality

@mckellyln mckellyln force-pushed the timestamp_client_span branch from 8aebdec to b9aa7e6 Compare September 21, 2024 19:56
@mckellyln
Copy link
Contributor Author

I am not sure how to get unittest output into OTEL collector

@mckellyln mckellyln requested a review from rpastrana September 23, 2024 14:52
Copy link
Member

@rpastrana rpastrana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mckellyln looks good, but I'm left wondering if there's enough in the manual test to confirm the feature worked as expected.

@@ -231,6 +231,11 @@ class JlibTraceTest : public CppUnit::TestFixture
OwnedSpanScope serverSpan = queryTraceManager().createServerSpan("declaredSpanStartTime", emptyMockHTTPHeaders, &declaredSpanStartTime);
//{ "type": "span", "name": "declaredSpanStartTime", "trace_id": "0a2eff24e1996540056745aaeb2f5824", "span_id": "46d0faf8b4da893e",
//"start": 1702672311203213259, "duration": 125311051 }

SpanTimeStamp clientSpanTimeStamp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were you able to confirm the start time was adjusted as expected?
We're not able to automatically validate these values (yet) but the log output should match your expected start time (we might need to printout clientSpanTimeStamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I added the comments for the jlog Span output

@rpastrana
Copy link
Member

I am not sure how to get unittest output into OTEL collector

Right now we're dependent on visual inspection of the log output

@mckellyln mckellyln force-pushed the timestamp_client_span branch 2 times, most recently from c084788 to 3d612b0 Compare September 24, 2024 17:56
@mckellyln mckellyln force-pushed the timestamp_client_span branch from 3d612b0 to ebd3d33 Compare September 24, 2024 17:57
@mckellyln
Copy link
Contributor Author

mckellyln commented Sep 24, 2024

Added jlog output as comments to help verify output is expected.
Squashed.

Copy link
Member

@rpastrana rpastrana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mckellyln approved

@mckellyln
Copy link
Contributor Author

Thanks so much.
Ready for merge.

@ghalliday ghalliday merged commit db2438c into hpcc-systems:candidate-9.8.x Sep 25, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants