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

Add Metrics #248

Merged
merged 45 commits into from
Jun 11, 2019
Merged

Add Metrics #248

merged 45 commits into from
Jun 11, 2019

Conversation

gregkalapos
Copy link
Contributor

@gregkalapos gregkalapos commented May 31, 2019

Implements #154.

  • Adds the whole infrastructure to send metrics
  • Implements sending the following metrics:
    • system.process.cpu.total.norm.pct
    • system.process.memory.size
    • system.process.memory.rss.bytes
    • system.memory.actual.free (Windows and Linux only - no macOS support atm)
    • system.memory.total (Windows and Linux only - no macOS support atm)
    • system.cpu.total.norm.pct (Windows and Linux only - we dropped the xplat implementation)
  • Also adds public API interface to send custom metrics decided to drop this part - current plan is to do it in a follow up PR.

@gregkalapos gregkalapos mentioned this pull request May 31, 2019
@gregkalapos gregkalapos self-assigned this May 31, 2019
@codecov-io
Copy link

codecov-io commented Jun 3, 2019

Codecov Report

Merging #248 into master will increase coverage by 3.15%.
The diff coverage is 79.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #248      +/-   ##
==========================================
+ Coverage   76.61%   79.76%   +3.15%     
==========================================
  Files          66       68       +2     
  Lines        2245     2239       -6     
  Branches      443      403      -40     
==========================================
+ Hits         1720     1786      +66     
+ Misses        399      283     -116     
- Partials      126      170      +44
Impacted Files Coverage Δ
src/Elastic.Apm/Api/Tracer.cs 95.79% <ø> (-0.07%) ⬇️
src/Elastic.Apm/Model/Transaction.cs 97.32% <100%> (+0.15%) ⬆️
src/Elastic.Apm/Helpers/StacktraceHelper.cs 74% <69.23%> (-8.76%) ⬇️
src/Elastic.Apm.AspNetCore/ApmMiddleware.cs 82.73% <90.9%> (+0.42%) ⬆️
src/Elastic.Apm/Sampler.cs 56.75% <0%> (-27.03%) ⬇️
.../Elastic.Apm/Config/AbstractConfigurationReader.cs 72.64% <0%> (-10.9%) ⬇️
...Apm.AspNetCore/Config/MicrosoftExtensionsConfig.cs 73.52% <0%> (-9.81%) ⬇️
...gnosticListeners/HttpDiagnosticListenerImplBase.cs 62.16% <0%> (-4.51%) ⬇️
src/Elastic.Apm/Logging/LogValuesFormatter.cs 88.34% <0%> (-0.98%) ⬇️
src/Elastic.Apm/Logging/ConsoleLogger.cs 85.71% <0%> (-0.96%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5628f4e...6929bdd. Read the comment docs.

@gregkalapos gregkalapos changed the title Add Metrics - WIP Add Metrics Jun 4, 2019
@gregkalapos gregkalapos marked this pull request as ready for review June 4, 2019 13:42
@gregkalapos gregkalapos requested a review from SergeyKleyman June 4, 2019 13:42
With this approach the time range in which we measure the CPU usage is smaller than the whole time range (totalMsPassed). With this it's impossible to have higher than 100% CPU usage - this wasn't the case previously.
@gregkalapos
Copy link
Contributor Author

Failing test fixed.

Decided to remove the public API part. Also, this is something most agents don’t have, so this time it wouldn't be just copying ideas :)

I think it’s better to leave it out now and reiterate on this.

I made everything internal, except IMetricSet and MetricSample.

Reason is that the IPayloadSender has a new class that accepts IMetrics (which contains an MetricSample property). I think it’s fine, or actually necessary to make this public: the point of IPayloadSender is to replace how the agents reports events, e.g. in tests instead of sending to the APM Server we keep events in memory - also valid use case for users to inject another implementation (although I think no one really does this) that let’s say just writes events into a files - the API enables this. So users can see the metrics in case they provide the agent a custom IPayloadSender implementation, but they cannot send custom metrics. So I try not to hide event reporting on the PayloadSender, there won’t be any benefit of that.

Obviously sending custom metrics will be the interesting use case - and that will be implemented in a future PR.

@gregkalapos
Copy link
Contributor Author

gregkalapos commented Jun 7, 2019

The SystemCPU calculation is atm wrong, will reiterate on that - it's already too late here to start working on it, I need a sleep before that.

@gregkalapos
Copy link
Contributor Author

The SystemCPU calculation is atm wrong, will reiterate on that - it's already too late here to start working on it, I need a sleep before that.

Fixed.

@gregkalapos
Copy link
Contributor Author

@SergeyKleyman please take another look. Thanks.

@gregkalapos
Copy link
Contributor Author

Tests fail on Linux, and calling virtual from a .ctor is a terrible idea. Working on it...

@gregkalapos
Copy link
Contributor Author

Tests fail on Linux, and calling virtual from a .ctor is a terrible idea. Working on it...

That issue is fixed.

I made the SystemCpu test more strict (not accepting 0), which fails on Windows:

[2019-06-10T16:20:36.603Z] Failed   Elastic.Apm.Tests.MetricsTests.SystemCpu
[2019-06-10T16:20:36.603Z] Error Message:
[2019-06-10T16:20:36.603Z]  Expected metricSamples.First().KeyValue.Value to be greater than 0.0, but found 0.0.

...working on this one.

The perf. counter API seems to return 0 for the 1. call, so we simply call it 2 times - the MetricsCollector can deal with this.
Copy link
Contributor

@SergeyKleyman SergeyKleyman left a comment

Choose a reason for hiding this comment

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

LGTM

@gregkalapos
Copy link
Contributor Author

Tests fail on Linux, and calling virtual from a .ctor is a terrible idea. Working on it...

That issue is fixed.

I made the SystemCpu test more strict (not accepting 0), which fails on Windows:

[2019-06-10T16:20:36.603Z] Failed   Elastic.Apm.Tests.MetricsTests.SystemCpu
[2019-06-10T16:20:36.603Z] Error Message:
[2019-06-10T16:20:36.603Z]  Expected metricSamples.First().KeyValue.Value to be greater than 0.0, but found 0.0.

...working on this one.

Failing test on Windows also fixed - the perfcounter API seems to simply return 0 for the 1. call. We had 2 calls previously there, so that's why we never noticed it.

I also have some ideas why they return 0 the first time... we had the same discussion 😄

@gregkalapos
Copy link
Contributor Author

Awesome, I think we are good here. I'll resolve the conflict tomorrow and merge. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants