Skip to content
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

Add e2e test to asan & tsan CI #1670

Merged
merged 12 commits into from
Oct 24, 2022
4 changes: 4 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,13 @@ elif [[ "$1" == "bazel.nortti" ]]; then
exit 0
elif [[ "$1" == "bazel.asan" ]]; then
bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS_ASYNC //...
bazel $BAZEL_STARTUP_OPTIONS run --config=asan $BAZEL_TEST_OPTIONS_ASYNC \
//examples/metrics_simple:metrics_ostream_example > /dev/null
exit 0
elif [[ "$1" == "bazel.tsan" ]]; then
bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS_ASYNC //...
bazel $BAZEL_STARTUP_OPTIONS run --config=tsan $BAZEL_TEST_OPTIONS_ASYNC \
//examples/metrics_simple:metrics_ostream_example > /dev/null
exit 0
elif [[ "$1" == "bazel.valgrind" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //...
Expand Down
24 changes: 12 additions & 12 deletions examples/common/metrics_foo_library/foo_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ namespace metrics_api = opentelemetry::metrics;
namespace
{

static nostd::shared_ptr<metrics_api::ObservableInstrument> double_observable_counter;

std::map<std::string, std::string> get_random_attr()
{
static const std::vector<std::pair<std::string, std::string>> labels = {{"key1", "value1"},
{"key2", "value2"},
{"key3", "value3"},
{"key4", "value4"},
{"key5", "value5"}};
const std::vector<std::pair<std::string, std::string>> labels = {{"key1", "value1"},
{"key2", "value2"},
{"key3", "value3"},
{"key4", "value4"},
{"key5", "value5"}};
return std::map<std::string, std::string>{labels[rand() % (labels.size() - 1)],
labels[rand() % (labels.size() - 1)]};
}
Expand All @@ -34,8 +36,6 @@ class MeasurementFetcher
public:
static void Fetcher(opentelemetry::metrics::ObserverResult observer_result, void * /* state */)
{
std::map<std::string, std::string> labels = get_random_attr();
auto labelkv = opentelemetry::common::KeyValueIterableView<decltype(labels)>{labels};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the var name in the comment of line 46?

if (nostd::holds_alternative<
nostd::shared_ptr<opentelemetry::metrics::ObserverResultT<double>>>(observer_result))
{
Expand All @@ -58,7 +58,7 @@ void foo_library::counter_example(const std::string &name)
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto double_counter = meter->CreateDoubleCounter(counter_name);

while (true)
for (uint32_t i = 0; i < 20; ++i)
{
double val = (rand() % 700) + 1.1;
double_counter->Add(val);
Expand All @@ -71,9 +71,9 @@ void foo_library::observable_counter_example(const std::string &name)
std::string counter_name = name + "_observable_counter";
auto provider = metrics_api::Provider::GetMeterProvider();
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto counter = meter->CreateDoubleObservableCounter(counter_name);
counter->AddCallback(MeasurementFetcher::Fetcher, nullptr);
while (true)
double_observable_counter = meter->CreateDoubleObservableCounter(counter_name);
double_observable_counter->AddCallback(MeasurementFetcher::Fetcher, nullptr);
for (uint32_t i = 0; i < 20; ++i)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Expand All @@ -86,7 +86,7 @@ void foo_library::histogram_example(const std::string &name)
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto histogram_counter = meter->CreateDoubleHistogram(histogram_name, "des", "unit");
auto context = opentelemetry::context::Context{};
while (true)
for (uint32_t i = 0; i < 20; ++i)
{
double val = (rand() % 700) + 1.1;
std::map<std::string, std::string> labels = get_random_attr();
Expand Down