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

tracer: Drop unsampled txs when APM Server >= 8.0 #1208

Merged
merged 8 commits into from
Feb 11, 2022
Merged

tracer: Drop unsampled txs when APM Server >= 8.0 #1208

merged 8 commits into from
Feb 11, 2022

Conversation

marclop
Copy link
Contributor

@marclop marclop commented Feb 7, 2022

Description

Extends the HTTP Transport with a new method that queries the remote APM
Server / endpoint to obtain its version. Allowing the tracer to drop
unsampled transactions when the APM Server is version 8.0.0 or higher.

The version will be cached in a local variable until the APM Server URL
changes which will refresh the APM Server's version. The tracer launches
a goroutine to update the version when it is instantiated and refreshes
the remote server version every 10 seconds.

Any SendStream errors will cause the version cache to be invalidated and
will be refreshed the next time the ticker runs. It may cause unsampled
to be sent to the APM Server while the cache is invalid.

Related Issues

Closes #1153

@marclop marclop assigned marclop and unassigned marclop Feb 7, 2022
@apmmachine
Copy link
Contributor

apmmachine commented Feb 7, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-02-11T10:02:27.207+0000

  • Duration: 42 min 24 sec

Test stats 🧪

Test Results
Failed 0
Passed 7342
Skipped 174
Total 7516

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark test.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Extends the HTTP Transport with a new method that queries the remote APM
Server `/` endpoint to obtain its version. This allows the tracer to
drop unsampled transactions when the APM Server to which it sends traces
is version `8.0.0` or higher.

The version will be cached in a local variable until the APM Server URL
changes which will refresh the APM Server's version.

Signed-off-by: Marc Lopez Rubio <[email protected]>
@marclop marclop marked this pull request as ready for review February 8, 2022 03:01
@marclop marclop requested a review from a team February 8, 2022 03:01
Signed-off-by: Marc Lopez Rubio <[email protected]>
tracer.go Outdated Show resolved Hide resolved
transport/transporttest/recorder.go Outdated Show resolved Hide resolved
tracer.go Outdated Show resolved Hide resolved
tracer.go Outdated Show resolved Hide resolved
tracer_test.go Show resolved Hide resolved
tracer.go Outdated Show resolved Hide resolved
@@ -306,7 +313,10 @@ func (t *HTTPTransport) SetServerURL(u ...*url.URL) error {
t.intakeURLs = intakeURLs
t.configURLs = configURLs
t.profileURLs = profileURLs
t.urlIndex = 0
atomic.StoreInt32(&t.urlIndex, 0)
Copy link
Member

Choose a reason for hiding this comment

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

There was an unwritten assumption that SetServerURLs is not called concurrently with other methods: t.intakeURLs etc. are set without a lock. Is there some new concurrency that requires the atomic call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it wasn't stated anywhere and it seemed like a fairly small change to avoid having a potential data race when the index is increased and SetServerURL is called at the same time.

I can revert if you feel like we don't need to do it, but it seemed like a small price to pay to avoid any potential panics on consumer applications.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to be precise when it comes to concurrency: either the method needs to be concurrent-safe, or it doesn't. The atomic implies it does, but the unsynchronised mutation of t.intakeURLs etc. implies it doesn't.

Unless we need it (maybe we do?), I'd prefer to revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I will revert the change since it's unclear whether this is a scenario that users may encounter.

Signed-off-by: Marc Lopez Rubio <[email protected]>
tracer.go Outdated Show resolved Hide resolved
tracer_test.go Outdated Show resolved Hide resolved
@@ -306,7 +313,10 @@ func (t *HTTPTransport) SetServerURL(u ...*url.URL) error {
t.intakeURLs = intakeURLs
t.configURLs = configURLs
t.profileURLs = profileURLs
t.urlIndex = 0
atomic.StoreInt32(&t.urlIndex, 0)
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to be precise when it comes to concurrency: either the method needs to be concurrent-safe, or it doesn't. The atomic implies it does, but the unsynchronised mutation of t.intakeURLs etc. implies it doesn't.

Unless we need it (maybe we do?), I'd prefer to revert.

transport/http.go Outdated Show resolved Hide resolved
transport/http.go Outdated Show resolved Hide resolved
@marclop marclop added v8.1.0 and removed v8.0.0 labels Feb 10, 2022
@marclop marclop added this to the 2.0 milestone Feb 11, 2022
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

LGTM with a handful of small things. Thanks!

tracer.go Show resolved Hide resolved
tracer.go Outdated Show resolved Hide resolved
tracer.go Outdated Show resolved Hide resolved
config_test.go Show resolved Hide resolved
config_test.go Show resolved Hide resolved
tracer_test.go Outdated Show resolved Hide resolved
tracer_test.go Show resolved Hide resolved
tracer_test.go Outdated Show resolved Hide resolved
tracer_test.go Show resolved Hide resolved
@marclop marclop enabled auto-merge (squash) February 11, 2022 10:36
@marclop marclop merged commit 17f24e8 into elastic:main Feb 11, 2022
@marclop marclop deleted the f/drop-unsampled-transactions-when-server-8.0+ branch February 11, 2022 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[META 545] Drop unsampled transactions when connected to APM Server 8.0+
3 participants