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-30350 Add open telemetry support to roxie/hthor/thor #17822

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

ghalliday
Copy link
Member

@ghalliday ghalliday commented Sep 26, 2023

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:

@ghalliday
Copy link
Member Author

@rpastrana @afishbeck this is ready for review.
I have tested with the new end-to-end testing query with the following parameters:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
 <soap:Body>
  <soaptest_mainserviceRequest xmlns="urn:hpccsystems:ecl:soaptest_mainservice" traceLevel="2" logFullQueries="1">
   <searchwords>one,and,sheep,when,richard,king</searchwords>
   <url>http://.:9876</url>
  </soaptest_mainserviceRequest>
 </soap:Body>
</soap:Envelope>

And the traceid/spanid was created and the remote span id was recorded for the child soapcalls.
It needs careful reviewing, especially that no regressions have been introduced in roxie. (I will re-review tomorrow.)
It is based on a previous PR that you are both tagged on as well.

@github-actions
Copy link

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.

@ghalliday looks good, left a few questions and suggestions on minor concerns.

virtual void getLogPrefix(StringBuffer & out) const override
{
const char * caller = queryCallerId();
if (caller)
Copy link
Member

Choose a reason for hiding this comment

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

!isEmptyString ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will change

if (caller)
{
out.append('[');
if (caller)
Copy link
Member

Choose a reason for hiding this comment

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

is test on L:259 enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

The outer condition is not right - I have since fixed.

out.appendf("caller:%s", caller);

const char *local = queryLocalId();
if (local && *local)
Copy link
Member

Choose a reason for hiding this comment

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

!isEmptyString ?

const char *local = queryLocalId();
if (local && *local)
{
if (caller)
Copy link
Member

Choose a reason for hiding this comment

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

L:259?

const char * queryTraceName() const
{
return tracerName.get();
}

virtual const char* queryGlobalId() const override
Copy link
Member

Choose a reason for hiding this comment

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

in this file we typically have a new line between method definitions.

@@ -518,6 +515,12 @@ class CServerSpan : public CSpan
hpccGlobalId.set(httpHeaders->queryProp(kGlobalIdHttpHeaderName));
else if (httpHeaders->hasProp(kLegacyGlobalIdHttpHeaderName))
hpccGlobalId.set(httpHeaders->queryProp(kLegacyGlobalIdHttpHeaderName));
else if (hasMask(flags, SpanFlags::EnsureGlobalId))
{
StringBuffer gen_id;
Copy link
Member

Choose a reason for hiding this comment

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

minor, but var name doesn't follow file convention

StringBuffer gen_id;
appendGloballyUniqueId(gen_id);
hpccGlobalId.set(gen_id.str());
}
Copy link
Member

Choose a reason for hiding this comment

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

looking over the new span flags, I notice we're not handling 'EnsureTraceId' here, and now I'm wondering what that flag's intention is.

Copy link
Member

Choose a reason for hiding this comment

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

What is the current behavior if a server span is created but there is not a trace header? Do we end up with a server span with it's own trace-id, but no reference to a remote parent span?

Copy link
Member Author

Choose a reason for hiding this comment

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

It may not be needed - I will delete for the moment, and can add back in later.

@@ -2863,25 +2868,33 @@ class DummyLogCtx : implements IContextLogger
{
return 0;
}
virtual void setGlobalId(const char *id, SocketEndpoint &ep, unsigned pid) override
virtual void setActiveSpan(ISpan * span) override
Copy link
Member

@rpastrana rpastrana Sep 26, 2023

Choose a reason for hiding this comment

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

minor, but this overloads the OTel "active span" concept, but it seems to convey a slightly different meaning. I would consider another term (not sure what it would be)

Copy link
Member

Choose a reason for hiding this comment

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

From what I've seen of the OTel active span concept it's basically for single threaded applications. I see this as the "per query" version of the active span concept.

Copy link
Member

Choose a reason for hiding this comment

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

From what I've seen of the OTel active span concept it's basically for single threaded applications. I see this as the "per query" version of the active span concept.

@afishbeck is this in reply to my comment to Gavin?
If so, it is still overloading the term and can be misunderstood. It should go without saying, and I'm sure you'll agree, we should avoid any/all potential confusion if possible.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I could see someone already familiar with the OTel API making an assumption about what this means when they read the name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions for a better name? setCurrentSpan()?

Copy link
Member

Choose a reason for hiding this comment

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

current span was my immediate thought as well.

Copy link
Member

Choose a reason for hiding this comment

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

I think "current span" would be fine here.

@@ -2822,10 +2822,15 @@ void IContextLogger::logOperatorException(IException *E, const char *file, unsig
}
class CRuntimeStatisticCollection;

/*
This class is used to implement the defauult log context - especially used for engines that only support a single query at a time
Copy link
Member

Choose a reason for hiding this comment

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

very minor, 'default'

Copy link
Member

@afishbeck afishbeck left a comment

Choose a reason for hiding this comment

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

@ghalliday some comments / questions.

if (globalId.length())
{
workunit->setDebugValue("GlobalId", globalId.str(), true);
workunit->setDebugValue("GlobalIdHeader", globalIdHeader.str(), true); //use same header received
Copy link
Member

Choose a reason for hiding this comment

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

@ghalliday @rpastrana Note for when the ESP instrumentation is done, but I would expect open telemetry headers to also be added to the workunit here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - I would actually expect this to now call the new function recordTraceDebugOptions()

{
const char * key = iter->getPropKey();
if (!httpHeaderBlockContainsHeader(httpheaders, key))
request.append(key).append(": ").append(traceHeaders->queryProp(key)).append("\r\n");
Copy link
Member

Choose a reason for hiding this comment

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

Is there any chance the value is empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pass. I'll add a check.

s.append("]");
ensureContextLogger();

Owned<ISpan> requestSpan = queryTraceManager().createServerSpan("request", headers, flags);
Copy link
Member

Choose a reason for hiding this comment

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

Should be passing allHeaders?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well spotted. I will fix.

@@ -2863,25 +2868,33 @@ class DummyLogCtx : implements IContextLogger
{
return 0;
}
virtual void setGlobalId(const char *id, SocketEndpoint &ep, unsigned pid) override
virtual void setActiveSpan(ISpan * span) override
Copy link
Member

Choose a reason for hiding this comment

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

From what I've seen of the OTel active span concept it's basically for single threaded applications. I see this as the "per query" version of the active span concept.

common/thorhelper/thorsoapcall.cpp Show resolved Hide resolved
@@ -1308,6 +1302,7 @@ class RoxieWorkUnitWorker : public RoxieQueryWorker
StringBuffer s;
logctx.getStats(s);

//MORE: logctx.queryActiveSpan()->getLogPrefix() or similar.
Copy link
Member

Choose a reason for hiding this comment

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

Agreed we need a consistent way of doing this for each flavor of tracing. And longer term we will need to make sure there is enough info to tie traces and log lines together so the tools can hop between the two.

msgctx->setTransactionId(uid, nullptr, false);
else

msgctx->startSpan(uid, httpHelper.queryRequestHeaders());
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too clear on how this interacts with or replaces the span created above, currently line 1801:

msgctx->startSpan(nullptr, httpHelper.queryRequestHeaders());

Copy link
Member

Choose a reason for hiding this comment

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

Should this really just be setting attributes on the initial span. For example if necessary updating the global-id header or related attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant to delete the 1st one - I will fix. You should not be able to update the global-id/trace-id once the span has been started. Other properties are ok though.

StringBuffer gen_id;
appendGloballyUniqueId(gen_id);
hpccGlobalId.set(gen_id.str());
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the current behavior if a server span is created but there is not a trace header? Do we end up with a server span with it's own trace-id, but no reference to a remote parent span?

}
}

msgctx->startSpan(nullptr, httpHelper.queryRequestHeaders());
Copy link
Member

Choose a reason for hiding this comment

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

Spans will be used to analyze timings. Since there is a delay from when the socket was accepted and when the span is created I think we should have saved off the real start times and pass them in here to be used for the span.

From the open telemetry c++ sdk docs:

struct StartSpanOptions
{
// Optionally sets the start time of a Span.
//
// If the start time of a Span is set, timestamps from both the system clock
// and steady clock must be provided.
//
// Timestamps from the steady clock can be used to most accurately measure a
// Span's duration, while timestamps from the system clock can be used to most
// accurately place a Span's
// time point relative to other Spans collected across a distributed system.
common::SystemTimestamp start_system_time;
common::SteadyTimestamp start_steady_time;

Copy link
Member Author

Choose a reason for hiding this comment

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

Created HPCC-30374 and pasted your comment from here in there.

Copy link
Member Author

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

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

I will push an update.

common/thorhelper/thorsoapcall.cpp Show resolved Hide resolved
{
const char * key = iter->getPropKey();
if (!httpHeaderBlockContainsHeader(httpheaders, key))
request.append(key).append(": ").append(traceHeaders->queryProp(key)).append("\r\n");
Copy link
Member Author

Choose a reason for hiding this comment

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

Pass. I'll add a check.

if (globalId.length())
{
workunit->setDebugValue("GlobalId", globalId.str(), true);
workunit->setDebugValue("GlobalIdHeader", globalIdHeader.str(), true); //use same header received
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - I would actually expect this to now call the new function recordTraceDebugOptions()

s.append("]");
ensureContextLogger();

Owned<ISpan> requestSpan = queryTraceManager().createServerSpan("request", headers, flags);
Copy link
Member Author

Choose a reason for hiding this comment

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

Well spotted. I will fix.

}
}

msgctx->startSpan(nullptr, httpHelper.queryRequestHeaders());
Copy link
Member Author

Choose a reason for hiding this comment

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

Created HPCC-30374 and pasted your comment from here in there.

msgctx->setTransactionId(uid, nullptr, false);
else

msgctx->startSpan(uid, httpHelper.queryRequestHeaders());
Copy link
Member Author

Choose a reason for hiding this comment

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

I meant to delete the 1st one - I will fix. You should not be able to update the global-id/trace-id once the span has been started. Other properties are ok though.

@@ -2863,25 +2868,33 @@ class DummyLogCtx : implements IContextLogger
{
return 0;
}
virtual void setGlobalId(const char *id, SocketEndpoint &ep, unsigned pid) override
virtual void setActiveSpan(ISpan * span) override
Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions for a better name? setCurrentSpan()?

virtual void getLogPrefix(StringBuffer & out) const override
{
const char * caller = queryCallerId();
if (caller)
Copy link
Member Author

Choose a reason for hiding this comment

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

I will change

if (caller)
{
out.append('[');
if (caller)
Copy link
Member Author

Choose a reason for hiding this comment

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

The outer condition is not right - I have since fixed.

StringBuffer gen_id;
appendGloballyUniqueId(gen_id);
hpccGlobalId.set(gen_id.str());
}
Copy link
Member Author

Choose a reason for hiding this comment

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

It may not be needed - I will delete for the moment, and can add back in later.

@ghalliday
Copy link
Member Author

@afishbeck @rpastrana rebased and issues addressed (2 new commits, 1 from changes I spotted, and second in response to reviews)

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.

@ghalliday I didn't find any worthwhile issues.

Copy link
Member

@afishbeck afishbeck left a comment

Choose a reason for hiding this comment

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

@ghalliday A couple of general comments, and I think you were going to rename ActiveSpan, otherwise ready to approve.

@@ -1743,12 +1743,12 @@
"httpCallerIdHeader": {
"type": "string",
"default": "HPCC-Caller-Id",
"description": "HTTP Header field to use for sending and receiving CallerId"
"description": "HTTP Header field to use for sending and receiving CallerId (deprecated and ignored)"
Copy link
Member

Choose a reason for hiding this comment

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

Should disappear when rebased?

@@ -2863,25 +2868,33 @@ class DummyLogCtx : implements IContextLogger
{
return 0;
}
virtual void setGlobalId(const char *id, SocketEndpoint &ep, unsigned pid) override
virtual void setActiveSpan(ISpan * span) override
Copy link
Member

Choose a reason for hiding this comment

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

I think "current span" would be fine here.

@@ -351,11 +301,57 @@ class CSpan : public CInterfaceOf<ISpan>
return opentelemetry::trace::SpanContext::GetInvalid();
}

virtual void getLogPrefix(StringBuffer & out) const override
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment elsewhere. We want to avoid verbosity but ultimately should the span id be included here so that log processors can tie the trace info to the log lines. It makes for really nice navigation through the UI?

We have to maintain bw compatibility with the global-id services. But long term I hope that the global-id and local-id become attributes of the span and we only log the span-id.
The back end could then tie everything together. But that requires coordination with Kevin L. and Shanaka.

@ghalliday ghalliday force-pushed the issue30350 branch 2 times, most recently from ac588bc to 429f1f7 Compare September 28, 2023 07:34
Copy link
Member

@richardkchapman richardkchapman left a comment

Choose a reason for hiding this comment

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

One comment


Owned<IProperties> traceHeaders = extractTraceDebugOptions(wu);
Owned<ISpan> requestSpan = queryTraceManager().createServerSpan(wu->queryWuid(), traceHeaders);
updateDummyContextLogger().setActiveSpan(requestSpan);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why this would not be something like logxtx.setActiveSpan(requestSpan). What is the dummy context logger for?

@ghalliday ghalliday merged commit 1e8dd86 into hpcc-systems:candidate-9.4.x Sep 28, 2023
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.

4 participants