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:1674, Add Monotonic Property to Sum Aggregation, and unit tests for Up Down Counter #1675

Merged
merged 18 commits into from
Oct 26, 2022

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Oct 12, 2022

Fixes #1674

Changes

  • Add monotonic properly for Sum Aggregation
  • Select correct metric family for UpDownCounter in prometheus exporter
  • Add unit test for UpDownCounter.

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 October 12, 2022 02:43
@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Merging #1675 (6ff7036) into main (419e2d6) will decrease coverage by 0.12%.
The diff coverage is 82.76%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1675      +/-   ##
==========================================
- Coverage   86.38%   86.26%   -0.11%     
==========================================
  Files         169      169              
  Lines        5146     5160      +14     
==========================================
+ Hits         4445     4451       +6     
- Misses        701      709       +8     
Impacted Files Coverage Δ
...elemetry/sdk/metrics/aggregation/sum_aggregation.h 0.00% <ø> (ø)
...nclude/opentelemetry/sdk/metrics/data/point_data.h 100.00% <ø> (ø)
sdk/src/metrics/aggregation/sum_aggregation.cc 75.81% <68.75%> (-4.55%) ⬇️
...etry/sdk/metrics/aggregation/default_aggregation.h 78.69% <100.00%> (+3.22%) ⬆️
ext/src/http/client/curl/http_client_curl.cc 80.31% <0.00%> (-1.13%) ⬇️
sdk/src/trace/batch_span_processor.cc 90.63% <0.00%> (-0.78%) ⬇️

OTEL_INTERNAL_LOG_WARN(" Negative value ignored for Monotonic increasing measurement. Value"
<< value);
return;
}
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
point_data_.value_ = nostd::get<long>(point_data_.value_) + value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does overflow need to be handled here for the sum operation?

Copy link
Member Author

@lalitb lalitb Oct 18, 2022

Choose a reason for hiding this comment

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

With #1686 we use int64_t to store the sum. The numeric range limit of signed 64-bit is enormous, while it can still eventually overflow if the system generating measurement keeps running for long, without resetting. Unless there are real-world scenarios for the overflow, I think we can let go for now the overflow scenario (and so avoid extra validation for every measurement added). Even in the case of such real-world examples, the exporter can be configured with Delta temporality (if the backend system supports it), and so it would bypass adding the values. Otherwise, we can rely on the backend system to detect any such overflow and handle it accordingly.

@lalitb
Copy link
Member Author

lalitb commented Oct 20, 2022

Have fixed the CI errors. This should be good to review now.

@esigo esigo added the metrics label Oct 21, 2022
Copy link
Member

@esigo esigo left a comment

Choose a reason for hiding this comment

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

LGTM
just had a few minor comments
Thanks for the PR :)

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM

if (point_data_.is_monotonic_ && value < 0)
{
OTEL_INTERNAL_LOG_WARN(" Negative value ignored for Monotonic increasing measurement. Value"
<< value);
Copy link
Member

Choose a reason for hiding this comment

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

Ok for now.

In the long term, to be of any use, the warning message will need to add some context, like the name of the meter / metric involved that causes the warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. added slightly more context here.


using namespace opentelemetry::sdk::metrics;
using namespace opentelemetry::common;
using M = std::map<std::string, std::string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using M as namespace alias from some convention?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I don't think there is any convention. What do you recommend ?

instr_desc, AggregationType::kSum, default_attributes_processor.get(),
ExemplarReservoir::GetNoExemplarReservoir(), nullptr);

storage.RecordLong(10l, KeyValueIterableView<std::map<std::string, std::string>>(attributes_get),
Copy link
Contributor

Choose a reason for hiding this comment

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

define the number 10l as a variable as it is shared between this and the following line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, done

@lalitb lalitb merged commit f17043f into open-telemetry:main Oct 26, 2022
ays7 added a commit to ays7/opentelemetry-cpp that referenced this pull request Oct 29, 2022
…ad-local-stack

* commit '9acde87b08b225ce511fa8a20c6cba14f2921518': (36 commits)
  Prepare v1.7.0 release with Metrics API/SDK GA. (open-telemetry#1721)
  Fix: 1712 -  Validate Instrument meta data (name, unit, description) (open-telemetry#1713)
  Document libthrift 0.12.0 doesn't work with Jaeger exporter (open-telemetry#1714)
  Fix:1674, Add Monotonic Property to Sum Aggregation, and unit tests for Up Down Counter (open-telemetry#1675)
  [Metrics SDK] Move Metrics Exemplar processing behind feature flag (open-telemetry#1710)
  [Metrics API/SDK] Change Meter API/SDK to return nostd::unique_ptr for Sync Instruments (open-telemetry#1707)
  [Metrics] Switch to explicit 64 bit integers (open-telemetry#1686)
  Add metrics e2e test to asan & tsan CI (open-telemetry#1670)
  Add otlp-grpc example bazel (open-telemetry#1708)
  [Metrics SDK] Add support for Pull Metric Reader (open-telemetry#1701)
  Fix debug log of OTLP HTTP exporter and ES log exporter (open-telemetry#1703)
  [SEMANTIC CONVENTIONS] Upgrade to version 1.14.0 (open-telemetry#1697)
  Fix a potential precision loss on integer in ReservoirCellIndexFor (open-telemetry#1696)
  fix Histogram crash (open-telemetry#1685)
  Fix:1676 Segfault when short export period is used for metrics  (open-telemetry#1682)
  Add timeout support to MeterContext::ForceFlush (open-telemetry#1673)
  Add CMake OTELCPP_MAINTAINER_MODE (open-telemetry#1650)
  [DOCS] - Minor updates to OStream Metrics exporter documentation (open-telemetry#1679)
  Fix:open-telemetry#1575 API Documentation for Metrics SDK and API (open-telemetry#1678)
  Fixes open-telemetry#249 (open-telemetry#1677)
  ...
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Metrics SDK] - Add monotonicity property to Sum Aggregation
4 participants