-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metrics SDK: Filtering metrics attributes (#1191)
- Loading branch information
Showing
12 changed files
with
386 additions
and
6 deletions.
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,62 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include "opentelemetry/sdk/common/attribute_utils.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace common | ||
{ | ||
|
||
template <class T> | ||
inline void GetHashForAttributeValue(size_t &seed, const T arg) | ||
{ | ||
std::hash<T> hasher; | ||
// reference - | ||
// https://www.boost.org/doc/libs/1_37_0/doc/html/hash/reference.html#boost.hash_combine | ||
seed ^= hasher(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||
} | ||
|
||
template <class T> | ||
inline void GetHashForAttributeValue(size_t &seed, const std::vector<T> &arg) | ||
{ | ||
for (auto v : arg) | ||
{ | ||
GetHashForAttributeValue<T>(seed, v); | ||
} | ||
} | ||
|
||
struct GetHashForAttributeValueVisitor | ||
{ | ||
GetHashForAttributeValueVisitor(size_t &seed) : seed_(seed) {} | ||
template <class T> | ||
void operator()(T &v) | ||
{ | ||
GetHashForAttributeValue(seed_, v); | ||
} | ||
size_t &seed_; | ||
}; | ||
|
||
// Calculate hash of keys and values of attribute map | ||
inline size_t GetHashForAttributeMap(const OrderedAttributeMap &attribute_map) | ||
{ | ||
size_t seed = 0UL; | ||
for (auto &kv : attribute_map) | ||
{ | ||
std::hash<std::string> hasher; | ||
// reference - | ||
// https://www.boost.org/doc/libs/1_37_0/doc/html/hash/reference.html#boost.hash_combine | ||
seed ^= hasher(kv.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||
nostd::visit(GetHashForAttributeValueVisitor(seed), kv.second); | ||
} | ||
return seed; | ||
} | ||
|
||
} // namespace common | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
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
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,22 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <benchmark/benchmark.h> | ||
#include "opentelemetry/sdk/common/attributemap_hash.h" | ||
|
||
using namespace opentelemetry::sdk::common; | ||
namespace | ||
{ | ||
void BM_AttributeMapHash(benchmark::State &state) | ||
{ | ||
OrderedAttributeMap map1 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}, {"k4", "v4"}, | ||
{"k5", true}, {"k6", 12}, {"k7", 12.209}}; | ||
while (state.KeepRunning()) | ||
{ | ||
benchmark::DoNotOptimize(GetHashForAttributeMap(map1)); | ||
} | ||
} | ||
BENCHMARK(BM_AttributeMapHash); | ||
|
||
} // namespace | ||
BENCHMARK_MAIN(); |
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,32 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "opentelemetry/sdk/common/attributemap_hash.h" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace opentelemetry::sdk::common; | ||
TEST(AttributeMapHashTest, BasicTests) | ||
{ | ||
{ | ||
OrderedAttributeMap map1 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; | ||
OrderedAttributeMap map2 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}, {"k4", "v4"}}; | ||
OrderedAttributeMap map3 = {{"k3", "v3"}, {"k1", "v1"}, {"k2", "v2"}}; | ||
|
||
EXPECT_TRUE(GetHashForAttributeMap(map1) != 0); | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) == GetHashForAttributeMap(map1)); | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) != GetHashForAttributeMap(map2)); | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) == GetHashForAttributeMap(map3)); | ||
} | ||
|
||
{ | ||
OrderedAttributeMap map1 = {{"k1", 10}, {"k2", true}, {"k3", 12.22}}; | ||
OrderedAttributeMap map2 = {{"k3", 12.22}, {"k1", 10}, {"k2", true}}; | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) == GetHashForAttributeMap(map2)); | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) != 0); | ||
} | ||
|
||
{ | ||
OrderedAttributeMap map1 = {}; | ||
EXPECT_TRUE(GetHashForAttributeMap(map1) == 0); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,46 @@ | ||
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") | ||
|
||
cc_test( | ||
name = "meter_provider_sdk_test", | ||
srcs = [ | ||
"meter_provider_sdk_test.cc", | ||
], | ||
tags = [ | ||
"metrics", | ||
"test", | ||
], | ||
deps = [ | ||
"//sdk/src/metrics", | ||
"//sdk/src/resource", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
cc_test( | ||
name = "attributes_processor_test", | ||
srcs = [ | ||
"attributes_processor_test.cc", | ||
], | ||
tags = [ | ||
"metrics", | ||
"test", | ||
], | ||
deps = [ | ||
"//sdk/src/metrics", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
otel_cc_benchmark( | ||
name = "attributes_processor_benchmark", | ||
srcs = [ | ||
"attributes_processor_benchmark.cc", | ||
], | ||
tags = [ | ||
"metrics", | ||
"test", | ||
], | ||
deps = [ | ||
"//sdk/src/metrics", | ||
], | ||
) |
Oops, something went wrong.
b6a28df
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.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_BaselineBuffer/1
11502797.603607178
ns/iter564463.8753465419
ns/iter20.38
BM_BaselineBuffer/2
7753102.779388428
ns/iter3120694.875717163
ns/iter2.48
BM_LockFreeBuffer/1
3398835.8974456787
ns/iter453277.5417680796
ns/iter7.50
This comment was automatically generated by workflow using github-action-benchmark.