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

Fix 1585 - Multiple cumulative metric collections without measurement recording. #1586

Merged
merged 4 commits into from
Sep 7, 2022

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Aug 30, 2022

Fixes #1585

Changes

In case cumulative metric collection is done without any measurement recorded in between, the same metrics should be returned. Merge was not happening properly if there is no unreported metrics. This is fixed now. Also added the tests to validate.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@lalitb lalitb requested a review from a team August 30, 2022 23:54
@codecov
Copy link

codecov bot commented Aug 31, 2022

Codecov Report

Merging #1586 (9d20c60) into main (e27fc88) will increase coverage by 0.11%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1586      +/-   ##
==========================================
+ Coverage   84.96%   85.06%   +0.11%     
==========================================
  Files         156      156              
  Lines        4977     4978       +1     
==========================================
+ Hits         4228     4234       +6     
+ Misses        749      744       -5     
Impacted Files Coverage Δ
sdk/src/metrics/state/temporal_metric_storage.cc 96.67% <100.00%> (+3.45%) ⬆️
ext/src/http/client/curl/http_client_curl.cc 81.44% <0.00%> (+1.14%) ⬆️

@tauseef-ah
Copy link

Hi lalit, I just tested your changes, and I observe the when counter metrics are not sent from application side, then the metrics are displayed as 0. However, when the metrics values are sent the counter correctly accumulates from past data:
{
scope name : ostream_metric_example
schema url :
version : 1.2.0
start time : Thu Sep 1 06:41:35 2022
end time : Thu Sep 1 06:41:36 2022
instrument name : ostream_metric_example
description : description
unit :
type : SumPointData
value : 107
attributes :
resources :
service.name: unknown_service
telemetry.sdk.language: cpp
telemetry.sdk.name: opentelemetry
telemetry.sdk.version: 1.6.0
}
{
scope name : ostream_metric_example
schema url :
version : 1.2.0
start time : Thu Sep 1 06:41:36 2022
end time : Thu Sep 1 06:41:37 2022
instrument name : ostream_metric_example
description : description
unit :
type : SumPointData
value : 0
attributes :
resources :
service.name: unknown_service
telemetry.sdk.language: cpp
telemetry.sdk.name: opentelemetry
telemetry.sdk.version: 1.6.0
}
{
scope name : ostream_metric_example
schema url :
version : 1.2.0
start time : Thu Sep 1 06:41:37 2022
end time : Thu Sep 1 06:41:38 2022
instrument name : ostream_metric_example
description : description
unit :
type : SumPointData
value : 108
attributes :
resources :
service.name: unknown_service
telemetry.sdk.language: cpp
telemetry.sdk.name: opentelemetry
telemetry.sdk.version: 1.6.0
}

@lalitb
Copy link
Member Author

lalitb commented Sep 2, 2022

@tauseef-ah - Thanks for testing this. How can I reproduce the scenario?

Record(2) -> Record(3) -> Collect(5) -> Collect(5) -> Record(4) -> Collect(9) -> Collect(9)

I tested something like the above and got the expected result with this PR.

@tauseef-ah
Copy link

hi @lalitb , sorry there seems to have been an issue with us picking the wrong binaries at runtime. This solution works fine for us too. Thanks

return true;
});
last_aggr_hashmap->GetAllEnteries(
[&merged_metrics, this](const MetricAttributes &attributes, Aggregation &aggregation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this jus reformat?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, this is done by clang-format. The only changes are lines 103, and 104 below. To handle the else scenario when there are no measurements recorded since the last collection.

@ThomsonTan ThomsonTan merged commit e4b0420 into open-telemetry:main Sep 7, 2022
yxue pushed a commit to yxue/opentelemetry-cpp that referenced this pull request Dec 5, 2022
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.

Cumulative Metric Exam
3 participants