-
Notifications
You must be signed in to change notification settings - Fork 547
feat: add YAML parsing support for Composable Samplers #3966
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?
Changes from all commits
ae0c9dd
659aafe
4f801aa
813a6d4
4cf8d39
1a4617d
e22556d
30be1a0
db8b88f
5b3d911
e8750da
4d117b0
f91eb58
678b6f9
58b5837
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
|
|
||
| class ComposableAlwaysOffSamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableAlwaysOffSamplerConfiguration() = default; | ||
|
|
||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
| }; | ||
|
|
||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
|
|
||
| class ComposableAlwaysOnSamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableAlwaysOnSamplerConfiguration() = default; | ||
|
|
||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
| }; | ||
|
|
||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #include <memory> | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| class ComposableParentThresholdSamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableParentThresholdSamplerConfiguration() = default; | ||
| std::unique_ptr<SamplerConfiguration> root; | ||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
| }; | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
|
|
||
| class ComposableProbabilitySamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableProbabilitySamplerConfiguration() = default; | ||
| double ratio{1.0}; | ||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
| }; | ||
|
|
||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #include <memory> | ||
| #include <vector> | ||
| #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
|
|
||
| class ComposableRuleBasedSamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableRuleBasedSamplerConfiguration() = default; | ||
| std::vector<std::unique_ptr<ComposableRuleBasedSamplerRuleConfiguration>> rules; | ||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
| }; | ||
|
|
||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
| #include <string> | ||
| #include <vector> | ||
| #include "opentelemetry/version.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| class ComposableRuleBasedSamplerRuleAttributePatternsConfiguration | ||
| { | ||
| public: | ||
| ComposableRuleBasedSamplerRuleAttributePatternsConfiguration() = default; | ||
| std::string key; | ||
| std::vector<std::string> included; | ||
| std::vector<std::string> excluded; | ||
| }; | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
| #include <string> | ||
| #include <vector> | ||
| #include "opentelemetry/version.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| class ComposableRuleBasedSamplerRuleAttributeValuesConfiguration | ||
| { | ||
| public: | ||
| ComposableRuleBasedSamplerRuleAttributeValuesConfiguration() = default; | ||
| std::string key; | ||
| std::vector<std::string> values; | ||
| }; | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
| #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_patterns_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/version.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| class ComposableRuleBasedSamplerRuleConfiguration | ||
| { | ||
| public: | ||
| ComposableRuleBasedSamplerRuleConfiguration() = default; | ||
| std::unique_ptr<ComposableRuleBasedSamplerRuleAttributeValuesConfiguration> attribute_values; | ||
| std::unique_ptr<ComposableRuleBasedSamplerRuleAttributePatternsConfiguration> attribute_patterns; | ||
|
|
||
| bool match_parent_none{false}; | ||
| bool match_parent_remote{false}; | ||
| bool match_parent_local{false}; | ||
|
|
||
| bool match_span_kind_internal{false}; | ||
| bool match_span_kind_server{false}; | ||
| bool match_span_kind_client{false}; | ||
| bool match_span_kind_producer{false}; | ||
| bool match_span_kind_consumer{false}; | ||
|
|
||
| std::unique_ptr<SamplerConfiguration> sampler; | ||
|
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. sampler is a ComposableSamplerConfiguration, not just a SamplerConfiguration |
||
| }; | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
| #include <memory> | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| #include "opentelemetry/version.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| class ComposableSamplerConfiguration : public SamplerConfiguration | ||
| { | ||
| public: | ||
| ComposableSamplerConfiguration() = default; | ||
| std::unique_ptr<SamplerConfiguration> inner; | ||
|
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. Remove inner |
||
| void Accept(SamplerConfigurationVisitor *visitor) const override; | ||
|
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. Remove Accept. ComposableSamplerConfiguration should be an abstract class, children will implement Accept for each composable sampler type supported. |
||
| }; | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,12 @@ | |
| #include "opentelemetry/sdk/configuration/boolean_array_attribute_value_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/boolean_attribute_value_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/cardinality_limits_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/configuration.h" | ||
| #include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" | ||
|
|
@@ -313,6 +319,42 @@ class ConfigurationParser | |
| const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableAlwaysOffSamplerConfiguration> | ||
| ParseComposableAlwaysOffSamplerConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableAlwaysOnSamplerConfiguration> | ||
| ParseComposableAlwaysOnSamplerConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableProbabilitySamplerConfiguration> | ||
| ParseComposableProbabilitySamplerConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableParentThresholdSamplerConfiguration> | ||
| ParseComposableParentThresholdSamplerConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableRuleBasedSamplerRuleAttributeValuesConfiguration> | ||
| ParseComposableRuleBasedSamplerRuleAttributeValuesConfiguration( | ||
| const std::unique_ptr<DocumentNode> &node) const; | ||
|
|
||
| std::unique_ptr<ComposableRuleBasedSamplerRuleAttributePatternsConfiguration> | ||
| ParseComposableRuleBasedSamplerRuleAttributePatternsConfiguration( | ||
| const std::unique_ptr<DocumentNode> &node) const; | ||
|
|
||
| std::unique_ptr<ComposableRuleBasedSamplerRuleConfiguration> | ||
| ParseComposableRuleBasedSamplerRuleConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ComposableRuleBasedSamplerConfiguration> | ||
| ParseComposableRuleBasedSamplerConfiguration(const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<SamplerConfiguration> ParseComposableSamplerConfiguration( | ||
|
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. This should return a ComposableSamplerConfiguration. |
||
| const std::unique_ptr<DocumentNode> &node, | ||
| size_t depth) const; | ||
|
|
||
| std::unique_ptr<ExtensionSamplerConfiguration> ParseSamplerExtensionConfiguration( | ||
| const std::string &name, | ||
| std::unique_ptr<DocumentNode> node, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,12 @@ class JaegerRemoteSamplerConfiguration; | |
| class ParentBasedSamplerConfiguration; | ||
| class TraceIdRatioBasedSamplerConfiguration; | ||
| class ExtensionSamplerConfiguration; | ||
| class ComposableAlwaysOffSamplerConfiguration; | ||
| class ComposableAlwaysOnSamplerConfiguration; | ||
| class ComposableProbabilitySamplerConfiguration; | ||
| class ComposableParentThresholdSamplerConfiguration; | ||
| class ComposableRuleBasedSamplerConfiguration; | ||
| class ComposableSamplerConfiguration; | ||
|
|
||
| class SamplerConfigurationVisitor | ||
| { | ||
|
|
@@ -34,6 +40,18 @@ class SamplerConfigurationVisitor | |
| virtual void VisitParentBased(const ParentBasedSamplerConfiguration *model) = 0; | ||
| virtual void VisitTraceIdRatioBased(const TraceIdRatioBasedSamplerConfiguration *model) = 0; | ||
| virtual void VisitExtension(const ExtensionSamplerConfiguration *model) = 0; | ||
| virtual void VisitComposableAlwaysOff(const ComposableAlwaysOffSamplerConfiguration * /*model*/) | ||
| {} | ||
| virtual void VisitComposableAlwaysOn(const ComposableAlwaysOnSamplerConfiguration * /*model*/) {} | ||
| virtual void VisitComposableProbability( | ||
| const ComposableProbabilitySamplerConfiguration * /*model*/) | ||
| {} | ||
| virtual void VisitComposableParentThreshold( | ||
| const ComposableParentThresholdSamplerConfiguration * /*model*/) | ||
| {} | ||
| virtual void VisitComposableRuleBased(const ComposableRuleBasedSamplerConfiguration * /*model*/) | ||
| {} | ||
| virtual void VisitComposable(const ComposableSamplerConfiguration * /*model*/) {} | ||
|
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. Remove VisitComposable. |
||
| }; | ||
|
|
||
| } // namespace configuration | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #include "opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| void ComposableAlwaysOffSamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const | ||
| { | ||
| visitor->VisitComposableAlwaysOff(this); | ||
| } | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #include "opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h" | ||
| #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace configuration | ||
| { | ||
| void ComposableAlwaysOnSamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const | ||
| { | ||
| visitor->VisitComposableAlwaysOn(this); | ||
| } | ||
| } // namespace configuration | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
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.
In the yaml spec:
root is a ComposableSampler, meaning it allows only some types but not all samplers.
For example, root can not point to a jaeger remote sampler, which
SamplerConfigurationallows.Change root to ComposableSamplerConfiguration, which means in turn that classes like ComposableAlwaysOnSamplerConfiguration must be a subclass of ComposableSamplerConfiguration, not SamplerConfiguration.