-
Notifications
You must be signed in to change notification settings - Fork 411
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
Metrics SDK: View API #1110
Merged
Merged
Metrics SDK: View API #1110
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c7b92a8
initial view commit
lalitb 98f94e0
Merge branch 'main' into metrics-sdk-views-2
lalitb a6866c6
build fix
lalitb 0d49214
Merge branch 'metrics-sdk-views-2' of github.com:lalitb/opentelemetry…
lalitb c41471a
build issue
lalitb 7a7a57a
regex for gcc4.8
lalitb 34ef0c5
Merge branch 'main' into metrics-sdk-views-2
lalitb 514bd85
fix 4.8 build
lalitb 8af6f2f
Merge branch 'metrics-sdk-views-2' of github.com:lalitb/opentelemetry…
lalitb 4f84e35
fix test
lalitb 9111528
more changes
lalitb 189f293
Merge branch 'main' into metrics-sdk-views-2
lalitb f3e9172
add tests for view_registry
lalitb c013f68
Merge branch 'metrics-sdk-views-2' of github.com:lalitb/opentelemetry…
lalitb c537f8b
more tests for view_registry
lalitb f2f412b
add const variable:
lalitb 918e7f2
disable predicate test for gcc4.8
lalitb 0bd982d
Aggregation API should return reference to Aggregator
lalitb 0ac15a2
Merge branch 'main' into metrics-sdk-views-2
lalitb 0a5863e
Merge branch 'main' into metrics-sdk-views-2
lalitb 7f91b4e
Merge branch 'main' into metrics-sdk-views-2
lalitb bcb43c6
review comments
lalitb 2bfb652
log error for regex for gcc4.8
lalitb cb4d314
compile error
lalitb 447cece
more compiler error
lalitb c28426b
Merge branch 'main' into metrics-sdk-views-2
lalitb 31f681d
Merge branch 'main' into metrics-sdk-views-2
ThomsonTan 5e14816
Merge branch 'main' into metrics-sdk-views-2
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include "opentelemetry/nostd/string_view.h" | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
enum class InstrumentType | ||
{ | ||
kCounter, | ||
kHistogram, | ||
kUpDownCounter, | ||
kObservableCounter, | ||
kObservableGauge, | ||
kObservableUpDownCounter | ||
}; | ||
|
||
enum class InstrumentValueType | ||
{ | ||
kInt, | ||
kLong, | ||
kFloat, | ||
kDouble | ||
}; | ||
|
||
struct InstrumentDescriptor | ||
{ | ||
std::string name_; | ||
std::string description_; | ||
std::string unit_; | ||
InstrumentType type_; | ||
InstrumentValueType valueType_; | ||
}; | ||
|
||
/*class InstrumentSelector { | ||
public: | ||
InstrumentSelector(opentelemetry::nostd::string_view name, | ||
opentelemetry::sdk::metrics::InstrumentType type): name_(name.data()), type_(type) {} InstrumentType | ||
GetType(){return type_;} std::string GetNameFilter() { return name_;} | ||
|
||
private: | ||
std::string name_; | ||
InstrumentType type_; | ||
};*/ | ||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
|
||
# include <memory> | ||
# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" | ||
# include "opentelemetry/sdk/metrics/instruments.h" | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class Aggregation | ||
{ | ||
public: | ||
virtual ~Aggregation() = default; | ||
virtual opentelemetry::sdk::metrics::Aggregator &CreateAggregator( | ||
opentelemetry::sdk::metrics::InstrumentDescriptor instrument_descriptor) noexcept = 0; | ||
}; | ||
|
||
class NoOpAggregation : public Aggregation | ||
{ | ||
|
||
opentelemetry::sdk::metrics::Aggregator &CreateAggregator( | ||
opentelemetry::sdk::metrics::InstrumentDescriptor instrument_descriptor) noexcept override | ||
{ | ||
static opentelemetry::sdk::metrics::NoOpAggregator noop_aggregator; | ||
return noop_aggregator; | ||
} | ||
}; | ||
|
||
class DefaultAggregation : public Aggregation | ||
{ | ||
|
||
opentelemetry::sdk::metrics::Aggregator &CreateAggregator( | ||
opentelemetry::sdk::metrics::InstrumentDescriptor instrument_descriptor) noexcept override | ||
{ | ||
// TBD - This shouldn't return noop_aggregator | ||
static opentelemetry::sdk::metrics::NoOpAggregator noop_aggregator; | ||
return noop_aggregator; | ||
} | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
34 changes: 34 additions & 0 deletions
34
sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include "opentelemetry/sdk/common/attribute_utils.h" | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
using MetricAttributes = opentelemetry::sdk::common::AttributeMap; | ||
|
||
class AttributesProcessor | ||
{ | ||
public: | ||
virtual MetricAttributes process( | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0; | ||
}; | ||
|
||
class DefaultAttributesProcessor : public AttributesProcessor | ||
{ | ||
MetricAttributes process( | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
{ | ||
MetricAttributes result(attributes); | ||
return result; | ||
} | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
36 changes: 36 additions & 0 deletions
36
sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include "opentelemetry/nostd/string_view.h" | ||
# include "opentelemetry/sdk/metrics/instruments.h" | ||
# include "opentelemetry/sdk/metrics/view/predicate.h" | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class InstrumentSelector | ||
{ | ||
public: | ||
InstrumentSelector(opentelemetry::sdk::metrics::InstrumentType instrument_type, | ||
opentelemetry::nostd::string_view name) | ||
: name_filter_{new opentelemetry::sdk::metrics::PatternPredicate(name)}, | ||
instrument_type_{instrument_type} | ||
{} | ||
|
||
// Returns name filter predicate. This shouldn't be deleted | ||
const opentelemetry::sdk::metrics::Predicate *const GetNameFilter() { return name_filter_.get(); } | ||
|
||
// Returns instrument filter. | ||
InstrumentType GetInstrumentType() { return instrument_type_; } | ||
|
||
private: | ||
opentelemetry::sdk::metrics::InstrumentType instrument_type_; | ||
std::unique_ptr<opentelemetry::sdk::metrics::Predicate> name_filter_; | ||
}; | ||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
47 changes: 47 additions & 0 deletions
47
sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/sdk/metrics/view/predicate.h" | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class MeterSelector | ||
{ | ||
public: | ||
MeterSelector(opentelemetry::nostd::string_view name, | ||
opentelemetry::nostd::string_view version, | ||
opentelemetry::nostd::string_view schema) | ||
: name_filter_{new opentelemetry::sdk::metrics::ExactPredicate(name)}, | ||
version_filter_{new opentelemetry::sdk::metrics::ExactPredicate(version)}, | ||
schema_filter_{new opentelemetry::sdk::metrics::ExactPredicate(schema)} | ||
{} | ||
|
||
// Returns name filter predicate. This shouldn't be deleted | ||
const opentelemetry::sdk::metrics::Predicate *const GetNameFilter() { return name_filter_.get(); } | ||
|
||
// Returns version filter predicate. This shouldn't be deleted | ||
const opentelemetry::sdk::metrics::Predicate *const GetVersionFilter() | ||
{ | ||
return version_filter_.get(); | ||
} | ||
|
||
// Returns schema filter predicate. This shouldn't be deleted | ||
const opentelemetry::sdk::metrics::Predicate *const GetSchemaFilter() | ||
{ | ||
return schema_filter_.get(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<opentelemetry::sdk::metrics::Predicate> name_filter_; | ||
std::unique_ptr<opentelemetry::sdk::metrics::Predicate> version_filter_; | ||
std::unique_ptr<opentelemetry::sdk::metrics::Predicate> schema_filter_; | ||
}; | ||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IIUC - by necessity, this API will need to take in an Iterator and return a concrete object. It's likely this would get used on the "hot path" of metrics. Does it make sense to have this API work only against
AttributeMap
, that way in the event you're just passing it through, there isn't a sort + unique step (I forget the details of attribute map).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.
Yes, your understanding is correct here. The metrics API takes non-owning KeyValueIterable object as here, and the plan is to make a copy of this only when required in hot-path. Attribute-processor could be one of the places to create a copy in case of passthrough.
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.
I expect this to (commonly) be a passthrough case. Can deal with it after initial implementation :)