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

Move from uint63 to uint64 for trace_id span_id and parent_id #1237

Merged
merged 26 commits into from
May 26, 2021

Conversation

labbati
Copy link
Member

@labbati labbati commented May 18, 2021

Motivation

PHP has not a concept of uint64, only int64, equivalent to unint63 for this discussion. As a consequence, when a frontend non-PHP service generates a random uint64 as the trace/span ID, then this ID is wrongly converted to a uint63 (or int64) by PHP and propagated.

Description

Move from uint63 IDs to unit64. After this R:

  • In userland, IDs are always and only strings;
  • In C, IDs are only uint64;
  • Conversion from into uint64 is done as the last step during the array serialization into a msgpack structure;

Readiness checklist

  • (only for Members) Changelog has been added to the release document.
  • Tests added for this feature/bug.

Reviewer checklist

  • Appropriate labels assigned.
  • Milestone is set.
  • Changelog has been added to the release document. For community contributors the reviewer is in charge of this task.

@labbati labbati added this to the 0.60.0 milestone May 18, 2021
@labbati labbati added the c-extension Apply this label to issues and prs related to the C-extension label May 18, 2021
@labbati
Copy link
Member Author

labbati commented May 18, 2021

@SammyK and @bwoebi I'd like to receive an opinion on the approach, so I am opening this PR as draft. In the description I summarized the motivation behind this and why we need this change.

Base automatically changed from labbati/remove-json to master May 18, 2021 14:07
if (string_as_uint64) {
mpack_write_u64(writer, strtoull(ZSTR_VAL(Z_STR_P(trace)), NULL, 10));
} else {
mpack_write_cstr(writer, ZSTR_VAL(Z_STR_P(trace)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the more idiomatic variant: Z_STRVAL_P(s) == ZSTR_VAL(Z_STR_P(s))

ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

static int msgpack_write_zval(mpack_writer_t *writer, zval *trace TSRMLS_DC);
static const char *trace_id_keyword = "trace_id";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Either use the variable everywhere (i.e. also in the add_assoc_string below) or not at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Very good point, did not catch that!

bwoebi
bwoebi previously approved these changes May 19, 2021
Copy link
Collaborator

@bwoebi bwoebi 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 in general

Copy link
Contributor

@SammyK SammyK left a comment

Choose a reason for hiding this comment

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

Nice work so far @labbati! I left some suggestions on the PHP 5 code that applies to 7 & 8 (with the exception of the add_assoc_string duplication issue which is PHP 5 specific).

ext/php5/random.c Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
tests/Common/TracerTestTrait.php Outdated Show resolved Hide resolved
Copy link
Member Author

@labbati labbati left a comment

Choose a reason for hiding this comment

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

Thank you for this first round of review @SammyK and @bwoebi

ext/php5/serializer.c Outdated Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
ext/php5/serializer.c Outdated Show resolved Hide resolved
ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

static int msgpack_write_zval(mpack_writer_t *writer, zval *trace TSRMLS_DC);
static const char *trace_id_keyword = "trace_id";
Copy link
Member Author

Choose a reason for hiding this comment

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

Very good point, did not catch that!

@@ -17,6 +19,11 @@

ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

#define MAX_ID_LEN 20 // 1.8e^19 = 20 chars
Copy link
Collaborator

Choose a reason for hiding this comment

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

TBH, this is not defensive, it's easy to forget a + 1 when allocating the buffer and it does no harm to have one byte too much allocated on the stack, better do 21 here and call it maybe MAX_ID_BUFSIZ

Copy link
Contributor

Choose a reason for hiding this comment

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

Very good point @bwoebi. I'll have to change my go-to way of doing this from now on. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Like it. Done

// Writing the value
if (zval_string_as_uint64) {
mpack_write_u64(writer, strtoull(Z_STRVAL_P(tmp), NULL, 10));
} else if (msgpack_write_zval(writer, tmp TSRMLS_CC) != 1) {
Copy link
Collaborator

@bwoebi bwoebi May 21, 2021

Choose a reason for hiding this comment

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

Don't add new TSRMLS - maybe rebase it, then compilation would fail (remove it in PHP 7 and PHP 8)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏻 just pulled in master

@labbati labbati marked this pull request as ready for review May 25, 2021 08:28
bwoebi
bwoebi previously approved these changes May 25, 2021
Copy link
Collaborator

@bwoebi bwoebi 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 now :-)

SammyK
SammyK previously approved these changes May 25, 2021
Copy link
Contributor

@SammyK SammyK left a comment

Choose a reason for hiding this comment

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

Looks great, @labbati! 💯 I left one optional suggestion about future proofing how we're using sprintf (but this could be a separate PR). LGTM. 👍

ext/php5/serializer.c Outdated Show resolved Hide resolved
@labbati labbati dismissed stale reviews from SammyK and bwoebi via 42d8cbc May 25, 2021 14:22
Copy link
Contributor

@SammyK SammyK left a comment

Choose a reason for hiding this comment

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

Thanks for knocking out that last change! 👍

@labbati
Copy link
Member Author

labbati commented May 26, 2021

The two failing tests are unrelated to this PR (master fails as well) and we are going to fix the failures in a separate PR. Merging it right now.

@labbati labbati merged commit bd6fd2f into master May 26, 2021
@labbati labbati deleted the labbati/uint64 branch May 26, 2021 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-extension Apply this label to issues and prs related to the C-extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants