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-30403 Provide ECL based API for Tracing #18057

Merged

Conversation

rpastrana
Copy link
Member

@rpastrana rpastrana commented Nov 21, 2023

  • Declares several ecl calls to logging library
  • Defines getTraceSpanHeader, getTraceStateHeader
  • Defines getTraceID, getSpanID, setSpanAttribute

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:

@rpastrana rpastrana changed the title HPCC-30403 Provid ECL based API for Tracing HPCC-30403 Provide ECL based API for Tracing Nov 21, 2023
Copy link

@rpastrana rpastrana requested a review from ghalliday November 21, 2023 04:46
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.

@rpastrana looks good. A few very minor comments.

@@ -730,6 +730,18 @@ IProperties * getClientHeaders(const ISpan * span)
return headers.getClear();
}

void setSpanAttribute(ISpan * span, const char * name, const char * val)
Copy link
Member

Choose a reason for hiding this comment

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

minor: Not sure why you would call this rather than span->setSpanAttribute()

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I ended up going this route because in logging.cpp, ctx->queryContextLogger() returns a const, this approach seemed to bypass the const restriction on the ctxLogger. Do we want to make the contexlogger non-const?

Copy link
Member

Choose a reason for hiding this comment

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

You can still call

    activeSpan->setSpanAttribute(name, value);

from within a const function. const generally prevents direct member variables from being modified - it does not prevent objects pointed to by member variables from being modified.

{
StringBuffer ret;
Owned<IProperties> httpHeaders = ctx->queryContextLogger().getSpanContext();
if (httpHeaders)
Copy link
Member

Choose a reason for hiding this comment

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

Can this ever return null? If not it is clearer without the if() test. (It also confuses static analysers).

StringBuffer attVal(valueLen, value);

ctx->queryContextLogger().setSpanAttribute(attName.str(), attVal.str());
}
Copy link
Member

Choose a reason for hiding this comment

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

minor: newline missing from end of file.

}
virtual void setSpanAttribute(const char *name, const char *value) const override
{
return ctx->setSpanAttribute(name, value);
Copy link
Member

Choose a reason for hiding this comment

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

observation: This did not use to be legal (return with a void expression), but it appears it is now.

@rpastrana rpastrana requested a review from ghalliday November 21, 2023 20:04
@rpastrana
Copy link
Member Author

@ghalliday made these change during pto hoping to get the pr merged in time for latest rc.
However, this does need some unittests which I hope to include in follow up pr.
Any info on how ecl plugins are typically auto-tested? I'd like to add at least the following:

import lib_logging;

output(lib_logging.Logging.getSpanID());
output(lib_logging.Logging.getTraceID());

>379563f3fcd56bc9
>0c483675c6c887d9fb49885c0f2ba116
import lib_logging;

output(lib_logging.Logging.getTraceSpanHeader());
output(lib_logging.Logging.getTraceStateHeader());

>00-a9f8b7d14d25d9233b829b3481bfaf93-6846688c1431ef1d-01
import lib_logging;
output(lib_logging.Logging.getSpanID());
lib_logging.Logging.setSpanAttribute('some','{"lines":[{"fields":[{"timestamp": "2023-11-06T20:52:19.265Z","hpcc.log.threadid": "232","hpcc.log.timestamp": "2023-11-06 20:52:19.265","kubernetes.container.name": "myeclccserver",}]},{"fields":[{"hpcc.log.jobid": "W20231111-222222","hpcc.log.audience": "OPR","hpcc.log.message": "hthor build community_9.4.9-closedown0Debug[heads/HPCC-30401-JTrace-optional-traceid-support-0-gc85263-dirty]",          "kubernetes.pod.name": "hthor-job-w20231106-205213-jdcss",}]}]}');

@@ -730,6 +730,18 @@ IProperties * getClientHeaders(const ISpan * span)
return headers.getClear();
}

void setSpanAttribute(ISpan * span, const char * name, const char * val)
Copy link
Member

Choose a reason for hiding this comment

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

You can still call

    activeSpan->setSpanAttribute(name, value);

from within a const function. const generally prevents direct member variables from being modified - it does not prevent objects pointed to by member variables from being modified.

if (httpHeaders)
ret.set(httpHeaders->queryProp("traceID"));

StringBuffer ret(ctx->queryContextLogger().getSpanContext()->queryProp("traceID"));
Copy link
Member

Choose a reason for hiding this comment

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

This change isn't correct - it will now leak the properties (we return pointers rather than smart pointers).

@rpastrana rpastrana requested a review from ghalliday November 27, 2023 17:43
return ret.detach();
}

LOGGING_API void LOGGING_CALL setSpanAttribute(ICodeContext *ctx,
Copy link
Member

Choose a reason for hiding this comment

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

trivial. Is this newline accidental?

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.

Please squash (one trivial comment about a newline)

@ghalliday
Copy link
Member

@rpastrana Also looks like it needs rebasing.

@rpastrana
Copy link
Member Author

@ghalliday added a regression suite test case for this, if nothing else, to document the use case. If you're ok with the change I'll squash.

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.

All looks good, please squash

- Adds several tracing related calls to ECL logging lib
- Defines getTraceSpanHeader, getTraceStateHeader
- Defines getTraceID, getSpanID, setSpanAttribute
- Adds regression tests

Signed-off-by: Rodrigo Pastrana <rodrigo.pastrana@lexisnexisrisk.com>
@rpastrana
Copy link
Member Author

@ghalliday squashed

@ghalliday ghalliday merged commit 929d7fc into hpcc-systems:candidate-9.4.x Nov 29, 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.

2 participants