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

[Instrumentation.EventCounters] Avoid race condition and performance trap in EventCountersMetrics #703

Merged
merged 3 commits into from
Oct 18, 2022

Conversation

MihaZupan
Copy link
Contributor

This PR fixes two issues with the current implementation:

  • Uses EventLevel.Critical instead of EventLevel.LogAlways
    • Counters don't require a specific log level to work. Depending on the EventSource implementor, this change can avoid a lot of overhead (preparing and serializing event arguments, potentially taking more expensive code paths).
  • Avoids a race condition when initializing the EventCountersMetrics instance
    • As OnEventSourceCreated can run before the constructor is done, you can run into a situation where you fail to enable an EventSource instance. A simple lock avoids this race.
    • Example course of events:
      • Thread A calls into OnEventSourceCreated and sees options aren't set yet
      • Thread B executes the constructor, processing any entries in preInitEventSources
      • Thread A adds the EventSource into preInitEventSources
      • Nothing will process and enable that EventSource instance

@MihaZupan MihaZupan requested a review from a team October 17, 2022 20:07
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 17, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: MihaZupan / name: Miha Zupan (a222ac3)

@github-actions github-actions bot requested review from hananiel and mic-max October 17, 2022 20:07
@utpilla utpilla added the comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters label Oct 17, 2022
@utpilla utpilla changed the title Avoid race condition and performance trap in EventCountersMetrics [Instrumentation.EventCounters] Avoid race condition and performance trap in EventCountersMetrics Oct 17, 2022
@utpilla
Copy link
Contributor

utpilla commented Oct 17, 2022

@MihaZupan Thanks for sending this PR! Could you please fix the build errors?

@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Merging #703 (d3a5c03) into main (841e6e5) will decrease coverage by 0.22%.
The diff coverage is 100.00%.

❗ Current head d3a5c03 differs from pull request most recent head 7c1f538. Consider uploading reports for the commit 7c1f538 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #703      +/-   ##
==========================================
- Coverage   77.89%   77.66%   -0.23%     
==========================================
  Files         175      175              
  Lines        5297     5310      +13     
==========================================
- Hits         4126     4124       -2     
- Misses       1171     1186      +15     
Impacted Files Coverage Δ
...trumentation.EventCounters/EventCountersMetrics.cs 82.75% <100.00%> (+1.98%) ⬆️
...orter.Geneva/MsgPackExporter/MsgPackLogExporter.cs 87.94% <0.00%> (-5.81%) ⬇️
...ry.Exporter.Geneva/Metrics/GenevaMetricExporter.cs 61.00% <0.00%> (-2.22%) ⬇️
....Exporter.Geneva/GenevaExporterHelperExtensions.cs 83.33% <0.00%> (+25.00%) ⬆️
...orter.Geneva/Internal/ServiceProviderExtensions.cs 100.00% <0.00%> (+100.00%) ⬆️

@MihaZupan MihaZupan force-pushed the EventCountersMetrics branch from d3a5c03 to 7c1f538 Compare October 18, 2022 03:09
Copy link
Contributor

@mic-max mic-max left a comment

Choose a reason for hiding this comment

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

LGTM Thanks!

@cijothomas cijothomas merged commit 018e124 into open-telemetry:main Oct 18, 2022
@Yun-Ting Yun-Ting mentioned this pull request Jul 5, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants