-
Notifications
You must be signed in to change notification settings - Fork 507
[METRICS] Add tag to AggregationConfig for aggregation type validation #3732
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
base: main
Are you sure you want to change the base?
[METRICS] Add tag to AggregationConfig for aggregation type validation #3732
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| switch (aggregation_type_) | ||
| { | ||
| case AggregationType::kHistogram: | ||
| valid = (config_type == AggregationConfigType::kHistogram); | ||
| break; | ||
| case AggregationType::kBase2ExponentialHistogram: | ||
| valid = (config_type == AggregationConfigType::kBase2ExponentialHistogram); | ||
| break; | ||
| case AggregationType::kDefault: | ||
| case AggregationType::kDrop: | ||
| case AggregationType::kLastValue: | ||
| case AggregationType::kSum: | ||
| valid = (config_type == AggregationConfigType::kDefault); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow histogram configs when aggregation type is default
The new validation in View now throws whenever AggregationType::kDefault is paired with a HistogramAggregationConfig. However, kDefault defers the actual aggregation choice to the instrument’s default (GetDefaultAggregationType returns kHistogram for histogram instruments). Existing callers can legitimately pass a histogram config while leaving the aggregation type at kDefault to customize bucket boundaries without overriding the default type; this change will now throw std::invalid_argument and prevent those views from being constructed. The check should accept histogram (and other concrete) config types when aggregation_type_ is kDefault because the concrete aggregation is resolved later based on the instrument descriptor.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is moved to ViweRegistry::AddView, to the deferred handling of kDefault logic is copied there. This is possible because AddView has both AggregationConfig and InstrumentationSelector.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3732 +/- ##
==========================================
- Coverage 90.01% 89.90% -0.11%
==========================================
Files 225 225
Lines 7105 7134 +29
==========================================
+ Hits 6395 6413 +18
- Misses 710 721 +11
🚀 New features to boost your workflow:
|
sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h
Outdated
Show resolved
Hide resolved
| attributes_processor_{std::move(attributes_processor)} | ||
| {} | ||
| { | ||
| // Validate that aggregation_type and aggregation_config match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that aggregation_config contains its proper type, can the aggregation_type parameter be removed instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not for now because the common AggregationConfig can still handle multiple aggregation types, like kDefault, kSum, etc. It is not 1:1 mapping.
marcalff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See some simplification.
|
I guess also here exceptions are not allowed. |
@Reneg973 , where do add the |
On every function, also constructor, like this: virtual AggregationType GetType() const noexcept { return AggregationType::kDefault; } |
| #if defined(__cpp_exceptions) | ||
| throw std::invalid_argument("AggregationType and AggregationConfig type mismatch"); | ||
| #else | ||
| std::abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, someone defines a wrong view, and the process dies ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If exception is not allowed, currently yes, the process dies.
|
|
||
| default: | ||
| // Unreachable: all AggregationType enum values are handled above | ||
| std::abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - this can be a utility method say IsDefaultAggregation(agg_type, inst_type, is_monotinic) in default_aggregation.h, but can be done afterwards if required at other places.
marcalff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For robustness, ignore invalid views / instruments / aggregations / etc.
A broken aggregation definition should not kill the application.
| { | ||
| #if defined(__cpp_exceptions) | ||
| throw std::invalid_argument("instrument_selector, meter_selector, and view cannot be null"); | ||
| #else | ||
| std::abort(); | ||
| #endif | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For every other failures in general, like illegal instrument names, the code just logs an error and ignores the instrument / view.
We should not throw exceptions or worse kill the process here, only ignore invalid configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced throw/abort with internal error log and ignores it.
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <stdexcept> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not needed, to remove.
|
|
||
| default: | ||
| // Unreachable: all AggregationType enum values are handled above | ||
| std::abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(false) instead ?
When building in release mode, should that path ever be seen, the code will fall gracefully with valid = false and an error in the log.
marcalff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, see minor cleanup.
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
Fixes #3731
Changes
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes