-
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
Changes from 23 commits
a2c48c6
d2330d1
177d85a
db221d8
7ec33ec
4d9331c
5dfc194
2c4266b
6f04f06
363eb46
b500f61
af73f3a
f28235c
6179d6f
d3b4c42
8e2a1b0
9dd5eae
36ef49a
5e96531
f30cea6
f150c4a
4b27470
4400651
a530053
01889b2
3867d1d
c1c5d0a
83f6394
b61e528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,14 @@ | |
|
|
||
| #include <algorithm> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "opentelemetry/nostd/function_ref.h" | ||
| #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" | ||
| #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" | ||
| #include "opentelemetry/sdk/metrics/instruments.h" | ||
| #include "opentelemetry/sdk/metrics/view/instrument_selector.h" | ||
| #include "opentelemetry/sdk/metrics/view/meter_selector.h" | ||
|
|
@@ -47,6 +49,61 @@ class ViewRegistry | |
| { | ||
| // TBD - thread-safe ? | ||
|
|
||
| // Validate parameters | ||
| if (!instrument_selector || !meter_selector || !view) | ||
| { | ||
| #if defined(__cpp_exceptions) | ||
| throw std::invalid_argument("instrument_selector, meter_selector, and view cannot be null"); | ||
| #else | ||
| std::abort(); | ||
| #endif | ||
| } | ||
|
Comment on lines
55
to
60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced |
||
|
|
||
| auto aggregation_config = view->GetAggregationConfig(); | ||
| if (aggregation_config) | ||
| { | ||
| bool valid = false; | ||
| auto aggregation_config_type = aggregation_config->GetType(); | ||
| auto aggregation_type = view->GetAggregationType(); | ||
|
|
||
| if (aggregation_type == AggregationType::kDefault) | ||
| { | ||
| bool is_monotonic; | ||
| aggregation_type = DefaultAggregation::GetDefaultAggregationType( | ||
| instrument_selector->GetInstrumentType(), is_monotonic); | ||
| } | ||
|
|
||
| switch (aggregation_type) | ||
| { | ||
| case AggregationType::kHistogram: | ||
| valid = (aggregation_config_type == AggregationType::kHistogram); | ||
| break; | ||
|
|
||
| case AggregationType::kBase2ExponentialHistogram: | ||
| valid = (aggregation_config_type == AggregationType::kBase2ExponentialHistogram); | ||
| break; | ||
|
|
||
| case AggregationType::kDrop: | ||
| case AggregationType::kLastValue: | ||
| case AggregationType::kSum: | ||
| valid = (aggregation_config_type == AggregationType::kDefault); | ||
| break; | ||
|
|
||
| default: | ||
| // Unreachable: all AggregationType enum values are handled above | ||
| std::abort(); | ||
|
||
| } | ||
|
|
||
| if (!valid) | ||
| { | ||
| #if defined(__cpp_exceptions) | ||
| throw std::invalid_argument("AggregationType and AggregationConfig type mismatch"); | ||
| #else | ||
| std::abort(); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| auto registered_view = std::unique_ptr<RegisteredView>(new RegisteredView{ | ||
| std::move(instrument_selector), std::move(meter_selector), std::move(view)}); | ||
| registered_views_.push_back(std::move(registered_view)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.