Skip to content

Commit ff58795

Browse files
committed
Merged from upstream. Moved back to the pristine XCode clang compiler
2 parents f0095ea + a025766 commit ff58795

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ build:macos --strip=never --copt=-g --cxxopt=-g
109109
# Does not yet compoile with the Developer command-line tools, needs clang from homebrew
110110
#build:macos --action_env=/Library/Developer/CommandLineTools/usr/bin/clang
111111
#build:macos --host_action_env=/Library/Developer/CommandLineTools/usr/bin/clang
112-
build:macos --action_env=CC=/opt/homebrew/opt/llvm/bin/clang
113-
build:macos --host_action_env=CC=/opt/homebrew/opt/llvm/bin/clang
112+
# build:macos --action_env=CC=/opt/homebrew/opt/llvm/bin/clang
113+
# build:macos --host_action_env=CC=/opt/homebrew/opt/llvm/bin/clang
114114
build:macos --apple_generate_dsym --output_groups=+dsyms
115115
build:macos --objc_generate_linkmap --output_groups=+linkmaps
116116

sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class FilteringAttributesProcessor : public AttributesProcessor
8080
MetricAttributes result;
8181
attributes.ForEachKeyValue(
8282
[&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept {
83-
if (allowed_attribute_keys_.find(key.data()) != allowed_attribute_keys_.end())
83+
if (allowed_attribute_keys_.find(std::string(key)) != allowed_attribute_keys_.end())
8484
{
8585
result.SetAttribute(key, value);
8686
return true;
@@ -94,13 +94,57 @@ class FilteringAttributesProcessor : public AttributesProcessor
9494

9595
bool isPresent(nostd::string_view key) const noexcept override
9696
{
97-
return (allowed_attribute_keys_.find(key.data()) != allowed_attribute_keys_.end());
97+
return (allowed_attribute_keys_.find(std::string(key)) != allowed_attribute_keys_.end());
9898
}
9999

100100
private:
101101
std::unordered_map<std::string, bool> allowed_attribute_keys_;
102102
};
103103

104+
/**
105+
* FilteringExcludeAttributeProcessor filters by exclude attribute list and drops names if they are
106+
* present in the exclude list
107+
*/
108+
109+
class FilteringExcludeAttributesProcessor : public AttributesProcessor
110+
{
111+
public:
112+
FilteringExcludeAttributesProcessor(std::unordered_map<std::string, bool> &&exclude_list = {})
113+
: exclude_list_(std::move(exclude_list))
114+
{}
115+
116+
FilteringExcludeAttributesProcessor(
117+
const std::unordered_map<std::string, bool> &exclude_list = {})
118+
: exclude_list_(exclude_list)
119+
{}
120+
121+
MetricAttributes process(
122+
const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
123+
{
124+
MetricAttributes result;
125+
attributes.ForEachKeyValue(
126+
[&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept {
127+
if (exclude_list_.find(std::string(key)) == exclude_list_.end())
128+
{
129+
result.SetAttribute(key, value);
130+
return true;
131+
}
132+
return true;
133+
});
134+
135+
result.UpdateHash();
136+
return result;
137+
}
138+
139+
bool isPresent(nostd::string_view key) const noexcept override
140+
{
141+
return (exclude_list_.find(std::string(key)) == exclude_list_.end());
142+
}
143+
144+
private:
145+
std::unordered_map<std::string, bool> exclude_list_;
146+
};
147+
104148
} // namespace metrics
105149
} // namespace sdk
106150
OPENTELEMETRY_END_NAMESPACE

sdk/test/metrics/attributes_processor_test.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,40 @@ TEST(AttributesProcessor, FilteringAllAttributesProcessor)
5151
auto filtered_attributes = attributes_processor.process(iterable);
5252
EXPECT_EQ(filter.size(), kNumFilterAttributes);
5353
}
54+
55+
TEST(AttributesProcessor, FilteringExcludeAttributesProcessor)
56+
{
57+
std::unordered_map<std::string, bool> filter = {
58+
{"attr2", true}, {"attr4", true}, {"attr6", true}};
59+
const int kNumAttributes = 7;
60+
std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3", "attr4",
61+
"attr5", "attr6", "attr7"};
62+
int values[kNumAttributes] = {10, 20, 30, 40, 50, 60, 70};
63+
std::map<std::string, int> attributes = {
64+
{keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}, {keys[3], values[3]},
65+
{keys[4], values[4]}, {keys[5], values[5]}, {keys[6], values[6]}};
66+
FilteringExcludeAttributesProcessor attributes_processor(filter);
67+
opentelemetry::common::KeyValueIterableView<std::map<std::string, int>> iterable(attributes);
68+
auto filtered_attributes = attributes_processor.process(iterable);
69+
for (auto &e : filtered_attributes)
70+
{
71+
EXPECT_TRUE(filter.find(e.first) == filter.end());
72+
}
73+
int expected_filtered_attributes_size = 4;
74+
EXPECT_EQ(filtered_attributes.size(), expected_filtered_attributes_size);
75+
}
76+
77+
TEST(AttributesProcessor, FilteringExcludeAllAttributesProcessor)
78+
{
79+
std::unordered_map<std::string, bool> filter = {};
80+
const int kNumAttributes = 6;
81+
std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3", "attr4", "attr5", "attr6"};
82+
int values[kNumAttributes] = {10, 20, 30, 40, 50, 60};
83+
std::map<std::string, int> attributes = {{keys[0], values[0]}, {keys[1], values[1]},
84+
{keys[2], values[2]}, {keys[3], values[3]},
85+
{keys[4], values[4]}, {keys[5], values[5]}};
86+
FilteringExcludeAttributesProcessor attributes_processor(filter);
87+
opentelemetry::common::KeyValueIterableView<std::map<std::string, int>> iterable(attributes);
88+
auto filtered_attributes = attributes_processor.process(iterable);
89+
EXPECT_EQ(filtered_attributes.size(), kNumAttributes);
90+
}

0 commit comments

Comments
 (0)