dd-trace-rb icon indicating copy to clipboard operation
dd-trace-rb copied to clipboard

[SDTEST-409] Add metrics management capabilities

Open anmarchenko opened this issue 1 year ago • 1 comments
trafficstars

What does this PR do? Adds entities to collect metrics and flush them to telemetry events:

  • MetricsCollection aggregates metrics per namespace and on demand flushes them to a queue passed as a param - this is going to be Telemetry::Worker. At most 2 events are created on flush: one for metrics, one for distributions. The methods of MetricsCollection are synchronized, protecting access to at most one thread at a time.
  • MetricsManager is a central piece of metrics aggregation: it manages collections, one per namespace. It synchronizes access to a hashmap with all collections, but allows concurrent access to a collection after it's fetched from the map. The method flush! locks access to the collections map and flushes each collection in order.

The concerns of managing metrics and managing namespaces are separated for the following reasons:

  • makes it easier to reason about concurrency and thread-safety of each component in isolation
  • allows concurrent access to several metrics namespaces at once, i.e. "civisibility" and "tracing" workers can add metrics without being blocked by each other.

Motivation: Next small step to achieving metrics support for internal DD telemetry.

How to test the change? Only unit tests for now (including several concurrency tests).

anmarchenko avatar Jun 27 '24 15:06 anmarchenko

Codecov Report

Attention: Patch coverage is 99.57537% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.91%. Comparing base (0669dbb) to head (8c023fd). Report is 3140 commits behind head on master.

Files with missing lines Patch % Lines
lib/datadog/core/telemetry/metric.rb 92.85% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3742      +/-   ##
==========================================
+ Coverage   97.90%   97.91%   +0.01%     
==========================================
  Files        1237     1241       +4     
  Lines       74200    74632     +432     
  Branches     3598     3605       +7     
==========================================
+ Hits        72643    73074     +431     
- Misses       1557     1558       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Jun 27 '24 15:06 codecov-commenter