Skip to content

Commit 0f5a720

Browse files
committed
apply formatting
1 parent 64719c7 commit 0f5a720

File tree

7 files changed

+212
-159
lines changed

7 files changed

+212
-159
lines changed

sdk/include/opentelemetry/sdk/common/attribute_utils.h

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -106,52 +106,58 @@ struct AttributeConverter
106106
};
107107

108108
/**
109-
* Evaluates if an owned value (from an OwnedAttributeValue) is equal to another value (from a non-owning AttributeValue).
110-
* This only supports the checking equality with nostd::visit(AttributeEqualToVisitor, OwnedAttributeValue, AttributeValue).
109+
* Evaluates if an owned value (from an OwnedAttributeValue) is equal to another value (from a
110+
* non-owning AttributeValue). This only supports the checking equality with
111+
* nostd::visit(AttributeEqualToVisitor, OwnedAttributeValue, AttributeValue).
111112
*/
112113
struct AttributeEqualToVisitor
113114
{
114-
// Different types are not equal including containers of different element types
115-
template <typename T, typename U>
116-
bool operator()(const T &, const U &) const noexcept
117-
{
118-
return false;
119-
}
115+
// Different types are not equal including containers of different element types
116+
template <typename T, typename U>
117+
bool operator()(const T &, const U &) const noexcept
118+
{
119+
return false;
120+
}
120121

121-
// Compare the same arithmatic types
122-
template <typename T>
123-
bool operator()(const T &owned_value, const T &value) const noexcept
124-
{
125-
return owned_value == value;
126-
}
127-
128-
// Compare std::string and const char*
129-
bool operator()(const std::string &owned_value, const char* value) const noexcept
130-
{
131-
return owned_value == value;
132-
}
122+
// Compare the same arithmatic types
123+
template <typename T>
124+
bool operator()(const T &owned_value, const T &value) const noexcept
125+
{
126+
return owned_value == value;
127+
}
133128

134-
// Compare std::string and nostd::string_view
135-
bool operator()(const std::string &owned_value, nostd::string_view value) const noexcept
136-
{
137-
return owned_value == value;
138-
}
129+
// Compare std::string and const char*
130+
bool operator()(const std::string &owned_value, const char *value) const noexcept
131+
{
132+
return owned_value == value;
133+
}
139134

140-
// Compare std::vector<std::string> and nostd::span<const nostd::string_view>
141-
bool operator()(const std::vector<std::string> &owned_value, const nostd::span<const nostd::string_view> &value) const noexcept
142-
{
143-
return owned_value.size() == value.size() && std::equal(owned_value.begin(), owned_value.end(), value.begin(),
144-
[](const std::string &owned_element, nostd::string_view element) { return owned_element == element; });
145-
}
135+
// Compare std::string and nostd::string_view
136+
bool operator()(const std::string &owned_value, nostd::string_view value) const noexcept
137+
{
138+
return owned_value == value;
139+
}
146140

147-
// Compare nostd::span<const T> and std::vector<T> for arithmatic types
148-
template <typename T>
149-
bool operator()(const std::vector<T> &owned_value, const nostd::span<const T> &value) const noexcept
150-
{
151-
return owned_value.size() == value.size() && std::equal(owned_value.begin(), owned_value.end(), value.begin());
152-
}
153-
};
141+
// Compare std::vector<std::string> and nostd::span<const nostd::string_view>
142+
bool operator()(const std::vector<std::string> &owned_value,
143+
const nostd::span<const nostd::string_view> &value) const noexcept
144+
{
145+
return owned_value.size() == value.size() &&
146+
std::equal(owned_value.begin(), owned_value.end(), value.begin(),
147+
[](const std::string &owned_element, nostd::string_view element) {
148+
return owned_element == element;
149+
});
150+
}
154151

152+
// Compare nostd::span<const T> and std::vector<T> for arithmatic types
153+
template <typename T>
154+
bool operator()(const std::vector<T> &owned_value,
155+
const nostd::span<const T> &value) const noexcept
156+
{
157+
return owned_value.size() == value.size() &&
158+
std::equal(owned_value.begin(), owned_value.end(), value.begin());
159+
}
160+
};
155161

156162
/**
157163
* Class for storing attributes.
@@ -210,30 +216,30 @@ class AttributeMap : public std::unordered_map<std::string, OwnedAttributeValue>
210216
(*this)[std::string(key)] = nostd::visit(converter_, value);
211217
}
212218

213-
bool EqualTo(const opentelemetry::common::KeyValueIterable& attributes) const noexcept
219+
bool EqualTo(const opentelemetry::common::KeyValueIterable &attributes) const noexcept
214220
{
215-
if(attributes.size() != this->size())
221+
if (attributes.size() != this->size())
216222
{
217223
return false;
218224
}
219225

220226
const bool is_equal = attributes.ForEachKeyValue(
221-
[this](nostd::string_view key, const opentelemetry::common::AttributeValue& value) noexcept
222-
{
223-
// Perform a linear search to find the key assuming the map is small
227+
[this](nostd::string_view key,
228+
const opentelemetry::common::AttributeValue &value) noexcept {
229+
// Perform a linear search to find the key assuming the map is small
224230
// This avoids temporary string creation from this->find(std::string(key))
225231
for (const auto &kv : *this)
226232
{
227-
if (kv.first == key)
233+
if (kv.first == key)
228234
{
229-
// Order of arguments is important here. OwnedAttributeValue is first then AttributeValue
230-
// AttributeEqualToVisitor does not support the reverse order
235+
// Order of arguments is important here. OwnedAttributeValue is first then
236+
// AttributeValue AttributeEqualToVisitor does not support the reverse order
231237
return nostd::visit(equal_to_visitor_, kv.second, value);
232238
}
233239
}
234-
return false;
240+
return false;
235241
});
236-
242+
237243
return is_equal;
238244
}
239245

sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ class InstrumentationScope
117117
*/
118118
bool equal(const nostd::string_view name,
119119
const nostd::string_view version,
120-
const nostd::string_view schema_url = "",
120+
const nostd::string_view schema_url = "",
121121
const opentelemetry::common::KeyValueIterable *attributes = nullptr) const noexcept
122122
{
123-
123+
124124
if (this->name_ != name || this->version_ != version || this->schema_url_ != schema_url)
125125
{
126-
return false;
126+
return false;
127127
}
128128

129-
if (attributes == nullptr)
129+
if (attributes == nullptr)
130130
{
131131
if (attributes_.empty())
132132
{

sdk/test/common/attribute_utils_test.cc

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#include <gtest/gtest.h>
5-
#include <array>
5+
#include <array>
66
#include <map>
77
#include <string>
88
#include <unordered_map>
99

1010
#include "opentelemetry/common/key_value_iterable_view.h"
11-
#include "opentelemetry/nostd/variant.h"
1211
#include "opentelemetry/nostd/span.h"
1312
#include "opentelemetry/nostd/string_view.h"
13+
#include "opentelemetry/nostd/variant.h"
1414
#include "opentelemetry/sdk/common/attribute_utils.h"
1515

1616
TEST(AttributeMapTest, DefaultConstruction)
@@ -61,96 +61,122 @@ TEST(OrderedAttributeMapTest, AttributesConstruction)
6161

6262
TEST(AttributeEqualToVisitorTest, AttributeValueEqualTo)
6363
{
64-
namespace sdk = opentelemetry::sdk::common;
65-
namespace api = opentelemetry::common;
64+
namespace sdk = opentelemetry::sdk::common;
65+
namespace api = opentelemetry::common;
6666
namespace nostd = opentelemetry::nostd;
67-
67+
6868
using AV = api::AttributeValue;
69-
using OV = sdk::OwnedAttributeValue;
69+
using OV = sdk::OwnedAttributeValue;
7070

7171
sdk::AttributeEqualToVisitor equal_to_visitor;
72-
72+
7373
// arithmetic types
7474
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{bool(true)}, AV{bool(true)}));
7575
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{int32_t(22)}, AV{int32_t(22)}));
7676
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{int64_t(22)}, AV{int64_t(22)}));
7777
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{uint32_t(22)}, AV{uint32_t(22)}));
7878
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{uint64_t(22)}, AV{uint64_t(22)}));
79-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{double(22.0)}, AV{double(22.0)}));
80-
81-
// string types
82-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string to const char*")}, AV{"string to const char*"}));
83-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string to string_view")}, AV{nostd::string_view("string to string_view")}));
84-
85-
//container types
86-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<bool>{true, false}}, AV{std::array<const bool, 2>{true, false}}));
87-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint8_t>{33, 44}}, AV{std::array<const uint8_t, 2>{33, 44}}));
88-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{33, 44}}, AV{std::array<const int32_t, 2>{33, 44}}));
89-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int64_t>{33, 44}}, AV{std::array<const int64_t, 2>{33, 44}}));
90-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint32_t>{33, 44}}, AV{std::array<const uint32_t, 2>{33, 44}}));
91-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint64_t>{33, 44}}, AV{std::array<const uint64_t, 2>{33, 44}}));
92-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<double>{33.0, 44.0}}, AV{std::array<const double, 2>{33.0, 44.0}}));
93-
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<std::string>{"a string", "another string"}}, AV{std::array<const nostd::string_view, 2>{"a string", "another string"}}));
79+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{double(22.0)}, AV{double(22.0)}));
80+
81+
// string types
82+
EXPECT_TRUE(opentelemetry::nostd::visit(
83+
equal_to_visitor, OV{std::string("string to const char*")}, AV{"string to const char*"}));
84+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor,
85+
OV{std::string("string to string_view")},
86+
AV{nostd::string_view("string to string_view")}));
87+
88+
// container types
89+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<bool>{true, false}},
90+
AV{std::array<const bool, 2>{true, false}}));
91+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint8_t>{33, 44}},
92+
AV{std::array<const uint8_t, 2>{33, 44}}));
93+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{33, 44}},
94+
AV{std::array<const int32_t, 2>{33, 44}}));
95+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int64_t>{33, 44}},
96+
AV{std::array<const int64_t, 2>{33, 44}}));
97+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint32_t>{33, 44}},
98+
AV{std::array<const uint32_t, 2>{33, 44}}));
99+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<uint64_t>{33, 44}},
100+
AV{std::array<const uint64_t, 2>{33, 44}}));
101+
EXPECT_TRUE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<double>{33.0, 44.0}},
102+
AV{std::array<const double, 2>{33.0, 44.0}}));
103+
EXPECT_TRUE(opentelemetry::nostd::visit(
104+
equal_to_visitor, OV{std::vector<std::string>{"a string", "another string"}},
105+
AV{std::array<const nostd::string_view, 2>{"a string", "another string"}}));
94106
}
95107

96108
TEST(AttributeEqualToVisitorTest, AttributeValueNotEqualTo)
97109
{
98-
namespace sdk = opentelemetry::sdk::common;
99-
namespace api = opentelemetry::common;
110+
namespace sdk = opentelemetry::sdk::common;
111+
namespace api = opentelemetry::common;
100112
namespace nostd = opentelemetry::nostd;
101-
113+
102114
using AV = api::AttributeValue;
103-
using OV = sdk::OwnedAttributeValue;
115+
using OV = sdk::OwnedAttributeValue;
104116

105117
sdk::AttributeEqualToVisitor equal_to_visitor;
106-
107-
// check different values of the same type
118+
119+
// check different values of the same type
108120
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{bool(true)}, AV{bool(false)}));
109121
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{int32_t(22)}, AV{int32_t(33)}));
110122
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{int64_t(22)}, AV{int64_t(33)}));
111123
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{uint32_t(22)}, AV{uint32_t(33)}));
112124
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{double(22.2)}, AV{double(33.3)}));
113-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string one")}, AV{"another string"}));
114-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string one")}, AV{nostd::string_view("another string")}));
125+
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string one")},
126+
AV{"another string"}));
127+
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::string("string one")},
128+
AV{nostd::string_view("another string")}));
115129

116-
// check different value types
130+
// check different value types
117131
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{bool(true)}, AV{uint32_t(0)}));
118132
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{int32_t(22)}, AV{uint32_t(22)}));
119133

120134
// check containers of different element values
121-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<bool>{true, false}}, AV{std::array<const bool, 2>{false, true}}));
122-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{22, 33}}, AV{std::array<const int32_t, 2>{33, 44}}));
123-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<std::string>{"a string", "another string"}}, AV{std::array<const nostd::string_view, 2>{"a string", "a really different string"}}));
135+
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<bool>{true, false}},
136+
AV{std::array<const bool, 2>{false, true}}));
137+
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{22, 33}},
138+
AV{std::array<const int32_t, 2>{33, 44}}));
139+
EXPECT_FALSE(opentelemetry::nostd::visit(
140+
equal_to_visitor, OV{std::vector<std::string>{"a string", "another string"}},
141+
AV{std::array<const nostd::string_view, 2>{"a string", "a really different string"}}));
124142

125143
// check containers of different element types
126-
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{22, 33}}, AV{std::array<const uint32_t, 2>{22, 33}}));
144+
EXPECT_FALSE(opentelemetry::nostd::visit(equal_to_visitor, OV{std::vector<int32_t>{22, 33}},
145+
AV{std::array<const uint32_t, 2>{22, 33}}));
127146
}
128147

129148
TEST(AttributeMapTest, EqualTo)
130149
{
131-
using Attributes = std::initializer_list<std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue>>;
132-
150+
using Attributes = std::initializer_list<
151+
std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue>>;
152+
133153
// check for case where both are empty
134-
Attributes attributes_empty = {};
135-
auto kv_iterable_empty = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_empty);
154+
Attributes attributes_empty = {};
155+
auto kv_iterable_empty =
156+
opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_empty);
136157
opentelemetry::sdk::common::AttributeMap attribute_map_empty(kv_iterable_empty);
137158
EXPECT_TRUE(attribute_map_empty.EqualTo(kv_iterable_empty));
138159

139-
// check for equality with a range of attributes and types
140-
Attributes attributes = {{"key0", "some value"}, {"key1", 1}, {"key2", 2.0}, {"key3", true}};
160+
// check for equality with a range of attributes and types
161+
Attributes attributes = {{"key0", "some value"}, {"key1", 1}, {"key2", 2.0}, {"key3", true}};
141162
auto kv_iterable_match = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes);
142163
opentelemetry::sdk::common::AttributeMap attribute_map(attributes);
143164
EXPECT_TRUE(attribute_map.EqualTo(kv_iterable_match));
144165

145-
// check for several cases where the attributes are different
146-
Attributes attributes_different_value = {{"key0", "some value"}, {"key1", 1}, {"key2", 2.0}, {"key3", false}};
147-
Attributes attributes_different_type = {{"key0", "some value"}, {"key1", 1.0} ,{"key2", 2.0}, {"key3", true}};
148-
Attributes attributes_different_size = {{"key0", "some value"}};
149-
auto kv_iterable_different_value = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_value);
150-
auto kv_iterable_different_type = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_type);
151-
auto kv_iterable_different_size = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_size);
152-
166+
// check for several cases where the attributes are different
167+
Attributes attributes_different_value = {
168+
{"key0", "some value"}, {"key1", 1}, {"key2", 2.0}, {"key3", false}};
169+
Attributes attributes_different_type = {
170+
{"key0", "some value"}, {"key1", 1.0}, {"key2", 2.0}, {"key3", true}};
171+
Attributes attributes_different_size = {{"key0", "some value"}};
172+
auto kv_iterable_different_value =
173+
opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_value);
174+
auto kv_iterable_different_type =
175+
opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_type);
176+
auto kv_iterable_different_size =
177+
opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_size);
178+
153179
EXPECT_FALSE(attribute_map.EqualTo(kv_iterable_different_value));
154-
EXPECT_FALSE(attribute_map.EqualTo(kv_iterable_different_type));
155-
EXPECT_FALSE(attribute_map.EqualTo(kv_iterable_different_size));
180+
EXPECT_FALSE(attribute_map.EqualTo(kv_iterable_different_type));
181+
EXPECT_FALSE(attribute_map.EqualTo(kv_iterable_different_size));
156182
}

0 commit comments

Comments
 (0)