-
Notifications
You must be signed in to change notification settings - Fork 449
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: Filtering metrics attributes #1191
Merged
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4eab744
filter attribute processor
lalitb 9c969bd
fix bazel
lalitb fd61256
add more tests
lalitb 982e9a4
comments
lalitb d54285f
Merge branch 'main' into filter-attributes
lalitb 8b80e2e
misspell
lalitb dba1962
Merge branch 'filter-attributes' of github.com:lalitb/opentelemetry-c…
lalitb 41ca1c2
fix test
lalitb 46fe572
add attribute hash calculation
lalitb 47eb2bf
Merge branch 'main' into filter-attributes
lalitb ac98cde
fix
lalitb bf436c4
Merge branch 'filter-attributes' of github.com:lalitb/opentelemetry-c…
lalitb 095aacc
load benchmark result
lalitb 49f48e7
fix bazel benchmark
lalitb 49e6d6a
add bazel tags
lalitb 49dc38e
Merge branch 'main' into filter-attributes
lalitb 9cb3deb
fix bazel finally
lalitb 0d47983
Merge branch 'filter-attributes' of github.com:lalitb/opentelemetry-c…
lalitb fa0b7e2
Merge branch 'main' into filter-attributes
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
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 | ||
|
||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include "opentelemetry/sdk/metrics/view/attributes_processor.h" | ||
# include <gtest/gtest.h> | ||
|
||
using namespace opentelemetry::sdk::metrics; | ||
using namespace opentelemetry::common; | ||
using namespace opentelemetry::sdk::common; | ||
|
||
TEST(AttributesProcessor, FilteringAttributesProcessor) | ||
{ | ||
const int kNumFilterAttributes = 3; | ||
std::unordered_map<std::string, bool> filter = { | ||
{"attr2", true}, {"attr4", true}, {"attr6", true}}; | ||
const int kNumAttributes = 6; | ||
std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3", "attr4", "attr5", "attr6"}; | ||
int values[kNumAttributes] = {10, 20, 30, 40, 50, 60}; | ||
std::map<std::string, int> attributes = {{keys[0], values[0]}, {keys[1], values[1]}, | ||
{keys[2], values[2]}, {keys[3], values[3]}, | ||
{keys[4], values[4]}, {keys[5], values[5]}}; | ||
FilteringAttributesProcessor attributes_processor(filter); | ||
opentelemetry::common::KeyValueIterableView<std::map<std::string, int>> iterable(attributes); | ||
auto filtered_attributes = attributes_processor.process(iterable); | ||
for (auto &e : filtered_attributes) | ||
{ | ||
EXPECT_FALSE(filter.find(e.first) == filter.end()); | ||
} | ||
EXPECT_EQ(filter.size(), kNumFilterAttributes); | ||
} | ||
|
||
TEST(AttributesProcessor, FilteringAllAttributesProcessor) | ||
{ | ||
const int kNumFilterAttributes = 0; | ||
std::unordered_map<std::string, bool> filter = {}; | ||
const int kNumAttributes = 6; | ||
std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3", "attr4", "attr5", "attr6"}; | ||
int values[kNumAttributes] = {10, 20, 30, 40, 50, 60}; | ||
std::map<std::string, int> attributes = {{keys[0], values[0]}, {keys[1], values[1]}, | ||
{keys[2], values[2]}, {keys[3], values[3]}, | ||
{keys[4], values[4]}, {keys[5], values[5]}}; | ||
FilteringAttributesProcessor attributes_processor(filter); | ||
opentelemetry::common::KeyValueIterableView<std::map<std::string, int>> iterable(attributes); | ||
auto filtered_attributes = attributes_processor.process(iterable); | ||
EXPECT_EQ(filter.size(), kNumFilterAttributes); | ||
} | ||
|
||
#endif |
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.
I wonder if this can be made internal/private to the SDK for now.
The specification only allows very limited manipulation on attributes (e.g. remove certain attributes from the measurement), this generic solution could work but it comes with perf cost (e.g. the virtual
AttributesProcessor::process
call).Doesn't have to be a blocker though.
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, I do suspect some perf cost associated with virtual and attributes copy. I have added a benchmark test to get cost statistics and would be helpful if have to consider performance improvement.
Also, I realized that we need to calculate the hash on the attribute map to store metrics data. Have added functionality to calculate the hash based on
std::hash
and boost::hash_combine`. As hash should be the same irrespective of the order of key/values in the AttributeMap, I have changed the internal storage for AttributeMap from unordered_map to map. This way we can avoid sorting of keys for every measurement.Let me see how can we make this class
internal/private
to SDK, as C++ doesn't have a direct way of doing it. We can makeAttributeProcessor::process()
as private, and other SDK classes as its friend to it but would like to see a better approach if possible.