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-33145: Optimize ESP server span creation #19373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timothyklemm
Copy link
Contributor

@timothyklemm timothyklemm commented Dec 20, 2024

  • Create the server span as soon as the request information needed to decide
    if a span should be created is available.
  • Change the server span's start time to reflect the time when the first line
    of the incoming request is read.

Signed-off-by: Tim Klemm [email protected]

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:

Copy link

Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-33145

Jirabot Action Result:
Workflow Transition To: Merge Pending
Updated PR

Copy link
Member

@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.

A couple of minor comments

@@ -2089,6 +2089,7 @@ int CHttpRequest::processHeaders(IMultiException *me)
char oneline[MAX_HTTP_HEADER_LEN + 2];

int lenread = m_bufferedsocket->readline(oneline, MAX_HTTP_HEADER_LEN + 1, me);
m_receivedAt.now(); // use receipt of a first loe as the start time for a server span
Copy link
Member

Choose a reason for hiding this comment

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

typo: line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep

wantTracing = !(methodName.isEmpty() ||
strieq(methodName, "files") ||
strieq(methodName, "xslt") ||
strieq(methodName, "frame") ||
Copy link
Member

Choose a reason for hiding this comment

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

is "body" deliberately missing?

How do we ensure this stays in sync with the code later in the function? Should at least be a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Not only is "body" not intentionally missing, but this doesn't account for the underscore that could be added to each name.

I'm thinking about defining a mapping of method name to enumerated value. This tracing check will only need to check the map for a matching entry. The subsequent handling code will be refactored to switch on the enumerated value. Only one set of string comparisons will be necessary, for a small performance boost.

@timothyklemm timothyklemm force-pushed the hpcc-33145-esp-server-span-creation branch from e5d40b8 to 80b6799 Compare January 2, 2025 23:44
@timothyklemm timothyklemm requested a review from ghalliday January 3, 2025 02:51
Copy link
Member

@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.

@timothyklemm I like the change. There is one issue.

The other two comments I would not have added if there was no other comments. They are there for discussion/to help the clarity of the code.

{
// The presence of a method name in the get request map is sufficient to
// suppress trace output. The enumerated value will be used later.
untracedRequestIt = getRequests.find(methodName);
Copy link
Member

Choose a reason for hiding this comment

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

This will not be executed if !isTracingEnabled, which means the switch statement later on will not work. This needs to be unconditional - and because it is now using a map it should be ok to be unconditional.

return onGetFile(m_request.get(), m_response.get(), pathEx.str());
}
else if (!stricmp(methodName.str(), "xslt"))
if (untracedRequestIt != getRequests.end())
Copy link
Member

Choose a reason for hiding this comment

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

picky style/encapsulation: Rather than comparing against the map null entry I would add a None entry to UntracedGetMethod, and have a local variable of that type, which was filled in. Why? Because the later test is reasonably separated from where the variable is set up, and a test against getRequests.end() isn't immediately obvious that what it is checking.

@@ -297,6 +299,50 @@ void CEspHttpServer::traceRequest(IEspContext* ctx, const char* normalizeMethod)
span->setSpanAttribute("url.full", full);
}

// Enumeration of "esp" service methods that are never traced. Add new values as additional
// requests become relevant.
enum class UntracedGetMethod
Copy link
Member

Choose a reason for hiding this comment

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

picky naming: What characteristic do these methods have that means they are not traced? Is it they are simple file requests? Something else? That adjective should be used to describe the method, rather than "Untraced" - because they are untraced for that reason, not the other way around.

@timothyklemm timothyklemm requested a review from ghalliday January 7, 2025 14:03
Copy link
Member

@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.

Looks a close. A couple of minor comment.

{"soapreq", UntracedGetMethod::SoapReq},
using EspGetMethodMap = std::map<const char*, EspGetMethod, EspGetMethodNameComparator>;
// Association of method names to specific "esp" service requests. This mapping allows
// pprocessRequest to decide if the request should be traced before processing the request, without
Copy link
Member

Choose a reason for hiding this comment

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

typo: pprocessRequest

@@ -402,29 +411,30 @@ int CEspHttpServer::processRequest()
// so maximize the amount of request processing that can be traced. Specifically, user
// authentication and authorization may generate trace output.
bool wantTracing = true;
Copy link
Member

Choose a reason for hiding this comment

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

minor: Should be initialised to queryTraceManager().isTracingEnabled()
otherwise it will be true if it is an unhandled get method even if that function returns false.

@timothyklemm timothyklemm requested a review from ghalliday January 9, 2025 18:52
Copy link
Member

@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.

Looks good afaics. Thanks, please squash.

- Create the server span as soon as the request information needed to decide
  if a span should be created is available.
- Change the server span's start time to reflect the time when the first line
  of the incoming request is read.

Signed-off-by: Tim Klemm <[email protected]>
@timothyklemm timothyklemm force-pushed the hpcc-33145-esp-server-span-creation branch from 2d79881 to be76f8c Compare January 10, 2025 11:06
@timothyklemm
Copy link
Contributor Author

@ghalliday it's squashed.

@timothyklemm
Copy link
Contributor Author

@ghalliday there's a build break on master unrelated to this change. I just ran into it after updating my local build.

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.

2 participants