Skip to content

Fix missing endpoint profiling when request_queuing is enabled in rack instrumentation#3109

Merged
ivoanjo merged 1 commit into
masterfrom
ivoanjo/endpoint-profiling-missing-request-queuing
Sep 6, 2023
Merged

Fix missing endpoint profiling when request_queuing is enabled in rack instrumentation#3109
ivoanjo merged 1 commit into
masterfrom
ivoanjo/endpoint-profiling-missing-request-queuing

Conversation

@ivoanjo

@ivoanjo ivoanjo commented Sep 5, 2023

Copy link
Copy Markdown
Member

What does this PR do?

This PR tweaks the logic that decides if the profiler should collect the resource from an active trace to also consider the span type proxy, which is used when the request_queuing feature is in use in the rack instrumentation.

Without this fix, the endpoint profiling feature (e.g. allowing customers to drill into their profiles by endpoint) does not work in combination with request_queuing, and the feature is hidden in the profiler UX.

Motivation:

Make sure that customers that enable request_queuing are still able to look at their profiles per-endpoint.

Additional Notes:

N/A

How to test the change?

The change includes test coverage. If you're interested in testing it out with a real http app, you can do so by enabling the request_queuing feature:

Datadog.configure do |c|
  c.tracing.instrument :rack, request_queuing: true
end

and then perform a request to the app including the X-Request-Start header:

$ curl --header "X-Request-Start: t=1693901946000" http://localhost:8080/foo

This will generate a queue span, and with this change, the endpoint will show up in the right sidebar when looking at profiles for this application. Without this change, it would not show up at all for requests with the queue span.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

@ivoanjo
ivoanjo requested a review from a team September 5, 2023 08:51
@github-actions github-actions Bot added the profiling Involves Datadog profiling label Sep 5, 2023
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #3109 (2a79636) into master (744b96e) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3109      +/-   ##
==========================================
- Coverage   98.16%   98.15%   -0.01%     
==========================================
  Files        1323     1323              
  Lines       75155    75160       +5     
  Branches     3428     3428              
==========================================
+ Hits        73773    73775       +2     
- Misses       1382     1385       +3     
Files Changed Coverage Δ
...atadog/profiling/collectors/thread_context_spec.rb 98.13% <100.00%> (-0.30%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you are potentially doing 2 strlen() calls per string per call does it make sense to make these constants so we don't evaluate them every function call?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair point

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since this is strlen on a constant string, the compiler will optimize it away, even at -O0, see: https://godbolt.org/z/Wb351Monv :)

…k instrumentation

**What does this PR do?**

This PR tweaks the logic that decides if the profiler should collect
the resource from an active trace to also consider the span type
`proxy`, which is used when the `request_queuing` feature is in use
in the rack instrumentation.

Without this fix, the endpoint profiling feature (e.g. allowing
customers to drill into their profiles by endpoint) does not work
in combination with `request_queuing`, and the feature is hidden
in the profiler UX.

**Motivation:**

Make sure that customers that enable `request_queuing` are still able
to look at their profiles per-endpoint.

**Additional Notes:**

N/A

**How to test the change?**

The change includes test coverage. If you're interested in testing
it out with a real http app, you can do so by enabling the
`request_queuing` feature:

```ruby
Datadog.configure do |c|
  c.tracing.instrument :rack, request_queuing: true
end
```

and then perform a request to the app including the
`X-Request-Start` header:

```
$ curl --header "X-Request-Start: t=1693901946000" http://localhost:8080/foo
```

This will generate a `queue` span, and with this change, the endpoint
will show up in the right sidebar when looking at profiles for this
application. Without this change, it would not show up at all for
requests with the `queue` span.
@ivoanjo
ivoanjo force-pushed the ivoanjo/endpoint-profiling-missing-request-queuing branch from 2a79636 to 4f72d84 Compare September 6, 2023 08:37
@ivoanjo

ivoanjo commented Sep 6, 2023

Copy link
Copy Markdown
Member Author

I've rebased this on top of current master without any other changes so as to incorporate the new CI job which is a requirement for merging.

@ivoanjo
ivoanjo merged commit 213abca into master Sep 6, 2023
@ivoanjo
ivoanjo deleted the ivoanjo/endpoint-profiling-missing-request-queuing branch September 6, 2023 09:18
@github-actions github-actions Bot added this to the 1.15.0 milestone Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants