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

Fix W3C test service #686

Merged
merged 24 commits into from
Jun 15, 2022
Merged

Conversation

yuktea
Copy link
Contributor

@yuktea yuktea commented May 26, 2022

Attempts to fix the W3C test service by updating usage patterns to match the refactorings and functional changes that have been applied since it was last updated. The effort remains a work-in-progress with the tests failing due to a reason I've been unable to diagnose yet.

Attempts to fix the W3C test service by updating usage patterns to
match the refactorings and functional changes that have been applied
since it was last updated. The effort remains a work-in-progress with
the tests failing due to a reason I've been unable to diagnose yet.
@bobstrecansky
Copy link
Collaborator

You'll need to run a make style to format your code and get to the next step of CI.

When I pulled down your branch and ran make test to test your code, I was able to see two relatively simple errors. Is that what you see as well?

@yuktea
Copy link
Contributor Author

yuktea commented May 26, 2022

@bobstrecansky

You'll need to run a make style to format your code and get to the next step of CI.

When I pulled down your branch and ran make test to test your code, I was able to see two relatively simple errors. Is that what you see as well?

I think you'll need to run make w3c-test-service to get the test service to run. What I see on my end: first all the tests from the w3c test.py script are failing.

----------------------------------------------------------------------
Ran 40 tests in 24.305s

FAILED (failures=40)
ERROR: 40
make: *** [Makefile:64: w3c-test-service] Error 40

On investigating the curl outputs from the symfony app, I see an error about an invalid argument to foreach (1) and (2):

<!-- Attempted to load class &quot;AlwaysOnSampler&quot; from namespace &quot;OpenTelemetry\SDK\Trace\Sampler&quot;.
Did you forget a &quot;use&quot; statement for another namespace? (500 Internal Server Error) -->

I haven't figured out why (1) is happening because I didn't change the (I think) relevant part in W3CTestService/TestController.php.

Any clue what could be causing (2)?

UPDATE 1: I've resolved both (1) and (2).

@codecov
Copy link

codecov bot commented May 26, 2022

Codecov Report

Merging #686 (6796211) into main (499c58a) will decrease coverage by 2.22%.
The diff coverage is 55.17%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #686      +/-   ##
============================================
- Coverage     85.00%   82.77%   -2.23%     
- Complexity     1233     1242       +9     
============================================
  Files           137      139       +2     
  Lines          2980     3036      +56     
============================================
- Hits           2533     2513      -20     
- Misses          447      523      +76     
Flag Coverage Δ
7.4 82.76% <55.17%> (-2.25%) ⬇️
8.0 82.82% <55.17%> (-2.23%) ⬇️
8.1 82.82% <55.17%> (-2.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/API/Trace/SpanContext.php 82.92% <0.00%> (-4.26%) ⬇️
...ation/SanitizeCombinedHeadersPropagationGetter.php 0.00% <0.00%> (ø)
...c/API/Trace/Propagation/TraceContextPropagator.php 100.00% <100.00%> (ø)
src/API/Trace/TraceState.php 100.00% <100.00%> (ø)
src/SDK/Trace/Span.php 93.69% <0.00%> (-0.23%) ⬇️
src/SDK/Common/Exception/StackTraceFormatter.php 0.00% <0.00%> (ø)
src/SDK/Trace/RandomIdGenerator.php 85.71% <0.00%> (+5.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 499c58a...6796211. Read the comment docs.

@yuktea yuktea force-pushed the fix-w3c-test-service branch from f438e31 to 961e58f Compare May 27, 2022 13:40
@yuktea
Copy link
Contributor Author

yuktea commented May 27, 2022

At this point, the test service is running as expected. However all 40 w3c tests are failing, output for all failures from the w3c trace-context test script looks like:

<!-- Unsupported carrier type: NULL. Unable to set value associated with key:traceparent (500 Internal Server Error) -->
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="robots" content="noindex,nofollow" />
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <title>Unsupported carrier type: NULL. Unable to set value associated with key:traceparent (500 Internal Server Error)</title>

@bobstrecansky any ideas to what might be causing this?

UPDATE: I recorded the wrong error initially.

@yuktea yuktea force-pushed the fix-w3c-test-service branch from 961e58f to 0eeada3 Compare May 27, 2022 14:08
@yuktea
Copy link
Contributor Author

yuktea commented May 28, 2022

I've ironed out issues in the service controller. All tests still fail, I suspect we're doing something wrong within the controller still but I'm not sure. Could use help in diagnosis.

I replaced deprecated SpanContext::generate() with
`SpanContext::createInvalid()`. That didn't look right for obvious
reasons, so with this commit it's replaced with a `new Context()`.
I'm still not sure if this does the job.
@bobstrecansky
Copy link
Collaborator

I'm trying to replicate this locally. What commands are you running to see your failures?

@yuktea
Copy link
Contributor Author

yuktea commented May 28, 2022

I'm trying to replicate this locally. What commands are you running to see your failures?

make w3c-test-service

Edit: Sorry, I messed up some syntax in the setup script which got past me since I was running commands directly in a docker container. You should be able to reproduce the issues with the make command now.

@yuktea
Copy link
Contributor Author

yuktea commented May 31, 2022

At of dff26c7 the w3c tests are still failing. I'll try to document my interpretation of what's going wrong with these tests in the hope it helps us figure out what it's lacking.

  • All 40 w3c tests fail.
  • Failure diagnosis output looks like:
    ======================================================================
    FAIL: test_tracestate_value_illegal_characters (__main__.TraceContextTest)
    harness sends a request with an invalid tracestate header with illegal value format
    ----------------------------------------------------------------------
    Traceback (most recent call last):
    File "/usr/src/myapp/tests/TraceContext/W3CTestService/trace-context/test/test.py", line 819, in test_tracestate_value_illegal_characters
    traceparent, tracestate = self.make_single_request_and_get_tracecontext([
    File "/usr/src/myapp/tests/TraceContext/W3CTestService/trace-context/test/test.py", line 113, in make_single_request_and_get_tracecontext
    return (self.get_traceparent(headers), self.get_tracestate(headers))
    File "/usr/src/myapp/tests/TraceContext/W3CTestService/trace-context/test/test.py", line 101, in get_traceparent
    self.assertEqual(len(retval), 1, 'expect one traceparent header, got {} {!r}'.format('more' if retval else 'zero', retval))
    AssertionError: 0 != 1 : expect one traceparent header, got zero []
    
  • Going by the diagnosis message and looking through the TestController, I believe we're not returning the response header as expected. However I have not been able to figure out exactly what it is we should be returning in the
    headers/body. Please take a look: https://github.com/yuktea/opentelemetry-php/blob/dff26c7119e4285b0b2ff99c6267645b90cdb853/tests/TraceContext/W3CTestService/TestController.php#L44
  • To reproduce on your end, please run make w3c-test-service. At this point, I have fixed the script and verified that the failure is reproducible.

/cc @bobstrecansky @tidal @brettmc

@bobstrecansky
Copy link
Collaborator

I'm able to reproduce your error, and I also get 40 errors. It appears you turned the debug log on, that's a good start. What inconsistencies have you found in the traceparent logic that would cause these errors? Remember, this pulls in the w3c test service here:

https://github.com/open-telemetry/opentelemetry-php/blob/main/tests/TraceContext/W3CTestService/symfony-setup#L47

@Nevay
Copy link
Contributor

Nevay commented May 31, 2022

Regarding TestController#L44, this should be:

$traceCtxPropagator->inject($headers, null, $context);

Some causes for the remaining failures:

  • the webserver concatenates multiple tracestate headers using ';' (see test_tracestate_empty_header)
  • the testsuite expects that the entire tracestate is discarded on invalid member (currently invalid members are dropped) (not required by spec; "If the tracestate header cannot be parsed the vendor MAY discard the entire header. Invalid tracestate entries MAY also be discarded.")
  • the tracestate propagator doesnt handle future versions (should allow >= 4 components instead of exactly 4 components if version is not 0x00)

@yuktea
Copy link
Contributor Author

yuktea commented May 31, 2022

I'm able to reproduce your error, and I also get 40 errors. It appears you turned the debug log on, that's a good start. What inconsistencies have you found in the traceparent logic that would cause these errors? Remember, this pulls in the w3c test service here:

https://github.com/open-telemetry/opentelemetry-php/blob/main/tests/TraceContext/W3CTestService/symfony-setup#L47

I think the biggest consistency was discarding the traces the expected by the tests in our response headers to the test harness. Beyond this we still have some more failures to investigate that @Nevay's assessment seems to cover well.

As of 4cfc68c, we are passing 30/40 tests. I'm currently investigating the other failures with help from the comments above.

@yuktea yuktea marked this pull request as ready for review June 1, 2022 06:10
@yuktea yuktea requested review from zsistla and tidal as code owners June 1, 2022 06:10
@yuktea
Copy link
Contributor Author

yuktea commented Jun 1, 2022

I think at this point the W3C test service is working fine. The 10 remaining failures we likely owe to not complying with the W3C trace context spec which we could work on outside of this PR.

@Nevay

the webserver concatenates multiple tracestate headers using ';' (see test_tracestate_empty_header)

I tried getting around this by doing a string replacement ; -> , but that breaks the same amount of tests it fixes. Apparently ; is a valid character in tracestates :/.
Is there any other workaround for this? I haven't been able to figure it out yet.

@yuktea yuktea force-pushed the fix-w3c-test-service branch from 79dcd16 to 77eb918 Compare June 1, 2022 08:55
@yuktea
Copy link
Contributor Author

yuktea commented Jun 1, 2022

Once we get this merged I'll open another PR to factor this to vanilla PHP for speed.

@yuktea
Copy link
Contributor Author

yuktea commented Jun 2, 2022

After these changes the errors are down to:

* 1x not supporting future versions, this has be resolved as it is required by spec

* 4x not dropping the entire tracestate on invalid member

Now we're down to these 5 failures in this PR. Should we cover them here?

/cc @bobstrecansky @tidal

@bobstrecansky
Copy link
Collaborator

We should attempt to cover them in this PR if possible.

yuktea added 2 commits June 3, 2022 19:04
-4x failures on the w3c trace context test:
- Drop empty tracestates.
- Drop the entire tracestate if a member is invalid.
- Drop the entire tracestate if member count exceeds max.
@yuktea yuktea force-pushed the fix-w3c-test-service branch from 7a5fb3f to 45974a5 Compare June 3, 2022 14:29
@yuktea
Copy link
Contributor Author

yuktea commented Jun 3, 2022

Should be good to go. Please check that the spec compliance changes are at the right place. Thanks

@yuktea yuktea force-pushed the fix-w3c-test-service branch from 45974a5 to 8b0bf8a Compare June 3, 2022 14:37
@yuktea
Copy link
Contributor Author

yuktea commented Jun 3, 2022

Some tests breaking. Will take a look and fix in a while.

@yuktea
Copy link
Contributor Author

yuktea commented Jun 3, 2022

Updated unit tests.

edit: and added some additional relevant tests.

@yuktea
Copy link
Contributor Author

yuktea commented Jun 8, 2022

lets get this merged?

Co-authored-by: Brett McBride <brett.a.mcbride@gmail.com>
src/API/Trace/TraceState.php Outdated Show resolved Hide resolved
Adds a new decorator to extract header sanitization to propagation getter decorator, for servers that concatenate duplicate headers with `;`. Enables this sanitation logic to be used across propagated state.
@brettmc brettmc merged commit 90edbd3 into open-telemetry:main Jun 15, 2022
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