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

[SDTEST-409] Send telemetry events in batches #3749

Merged
merged 8 commits into from
Jul 2, 2024

Conversation

anmarchenko
Copy link
Member

@anmarchenko anmarchenko commented Jul 1, 2024

What does this PR do?
Optimises telemetry events sending by sending them in batches using message-batch event type.

Motivation:
I expect the number of telemetry events to grow as soon as products start using metrics. We can save time by batching the list of events into a single event.

How to test the change?
System tests pass for telemetry events.

Logs from rails app with DD_TRACE_DEBUG=1:

D, [2024-07-01T16:08:58.970222 #20478] DEBUG -- datadog: [datadog] (/Users/andrey.marchenko/p/dd-trace-rb/lib/datadog/core/telemetry/worker.rb:88:in `flush_events') Sending 2 telemetry events
D, [2024-07-01T16:08:59.137402 #20478] DEBUG -- datadog: [datadog] (/Users/andrey.marchenko/p/dd-trace-rb/lib/datadog/core/telemetry/emitter.rb:29:in `request') Telemetry sent for event `message-batch` (code: 202)

@github-actions github-actions bot added the core Involves Datadog core libraries label Jul 1, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 98.64865% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.11%. Comparing base (4cd328d) to head (8d02f3e).
Report is 30 commits behind head on master.

Files Patch % Lines
lib/datadog/core/telemetry/event.rb 97.67% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3749   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files        1235     1235           
  Lines       73749    73788   +39     
  Branches     3560     3562    +2     
=======================================
+ Hits        72357    72398   +41     
+ Misses       1392     1390    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anmarchenko anmarchenko marked this pull request as ready for review July 1, 2024 13:50
@anmarchenko anmarchenko requested a review from a team as a code owner July 1, 2024 13:50
@events.map do |event|
{
request_type: event.type,
payload: event.payload(seq_id),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it OK that seq id is the same for all of the events?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question, I need to look it up in the spec.

Copy link
Member Author

Choose a reason for hiding this comment

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

The spec says nothing about it and also it does not mention that seq_id should be part of telemetry events payloads at all (it is supposed to be part of common headers)! I will investigate why our payload generation code even depends on seq_id...

Copy link
Member Author

@anmarchenko anmarchenko Jul 2, 2024

Choose a reason for hiding this comment

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

I found where this seq_id is defined in specs: https://github.com/DataDog/instrumentation-telemetry-api-docs/blob/main/GeneratedDocumentation/ApiDocs/v2/SchemaDocumentation/Schemas/conf_key_value.md

This field should incremented each time a new configuration key-value pair is applied in order to track the > active set of configurations. It can be a global value across all configurations keys or local to each key..

This seq_id is in fact different from the seq_id that is used for events:
https://github.com/DataDog/instrumentation-telemetry-api-docs/blob/main/GeneratedDocumentation/ApiDocs/v2/development.md#required-top-level-json-keys

Counter that should be auto incremented every time an API call is being made (our pipeline may not always work in a sequential order.This field will help us identify situations where some messages were being lost. seq_id should start at 1 so that the go backend can detect between non set fields.

I will see how to decouple them from each other in our implementation

Copy link
Member Author

Choose a reason for hiding this comment

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

Solved this by introducing another sequence in Core::Telemetry::Event class for the configuration changes

@anmarchenko anmarchenko merged commit 8081b9d into master Jul 2, 2024
166 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/send_telemetry_in_batch branch July 2, 2024 14:00
@github-actions github-actions bot added this to the 2.2.0 milestone Jul 2, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants