Skip to content

Commit

Permalink
Cocurrency otlp http session (open-telemetry#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Mar 29, 2022
1 parent 729c2f8 commit 15e7725
Show file tree
Hide file tree
Showing 64 changed files with 1,990 additions and 983 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand Down Expand Up @@ -67,6 +67,6 @@ jobs:
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
fail-on-alert: false
gh-pages-branch: gh-pages
benchmark-data-dir-path: benchmarks
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -158,7 +158,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -180,7 +180,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -202,7 +202,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -224,7 +224,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -246,7 +246,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -268,7 +268,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand All @@ -285,7 +285,7 @@ jobs:
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: bazel_cache
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Increment the:

## [Unreleased]

* [SDK] Bugfix: span SetAttribute crash ([#1283](https://github.com/open-telemetry/opentelemetry-cpp/pull/1283))
* [EXPORTER] Jaeger Exporter - Populate Span Links ([#1251](https://github.com/open-telemetry/opentelemetry-cpp/pull/1251))
* [EXPORTER] OTLP http exporter allow concurrency session ([#1209](https://github.com/open-telemetry/opentelemetry-cpp/pull/1209))

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ For edit access, get in touch on

* [Josh Suereth](https://github.com/jsuereth), Google
* [Reiley Yang](https://github.com/reyang), Microsoft
* [WenTao Ou](https://github.com/owent), Tencent

[Emeritus
Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/main/community-membership.md#emeritus-maintainerapprovertriager):
Expand Down
37 changes: 21 additions & 16 deletions api/include/opentelemetry/common/spin_lock_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ class SpinLockMutex
SpinLockMutex &operator=(const SpinLockMutex &) = delete;
SpinLockMutex &operator=(const SpinLockMutex &) volatile = delete;

static inline void fast_yield() noexcept
{
// Issue a Pause/Yield instruction while spinning.
#if defined(_MSC_VER)
YieldProcessor();
#elif defined(__i386__) || defined(__x86_64__)
# if defined(__clang__)
_mm_pause();
# else
__builtin_ia32_pause();
# endif
#elif defined(__arm__)
// This intrinsic should fail to be found if YIELD is not supported on the current
// processor.
__yield();
#else
// TODO: Issue PAGE/YIELD on other architectures.
#endif
}

/**
* Attempts to lock the mutex. Return immediately with `true` (success) or `false` (failure).
*/
Expand Down Expand Up @@ -91,22 +111,7 @@ class SpinLockMutex
{
return;
}
// Issue a Pause/Yield instruction while spinning.
#if defined(_MSC_VER)
YieldProcessor();
#elif defined(__i386__) || defined(__x86_64__)
# if defined(__clang__)
_mm_pause();
# else
__builtin_ia32_pause();
# endif
#elif defined(__arm__)
// This intrinsic should fail to be found if YIELD is not supported on the current
// processor.
__yield();
#else
// TODO: Issue PAGE/YIELD on other architectures.
#endif
fast_yield();
}
// Yield then try again (goal ~100ns)
std::this_thread::yield();
Expand Down
17 changes: 15 additions & 2 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ class NoopCounter : public Counter<T>
nostd::string_view unit) noexcept
{}
void Add(T value) noexcept override {}
void Add(T value, const opentelemetry::context::Context &context) noexcept override {}
void Add(T value, const common::KeyValueIterable &attributes) noexcept override {}
void Add(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept override
{}
};

template <class T>
Expand All @@ -35,8 +40,11 @@ class NoopHistogram : public Histogram<T>
nostd::string_view description,
nostd::string_view unit) noexcept
{}
void Record(T value) noexcept override {}
void Record(T value, const common::KeyValueIterable &attributes) noexcept override {}
void Record(T value, const opentelemetry::context::Context &context) noexcept override {}
void Record(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept override
{}
};

template <class T>
Expand All @@ -48,7 +56,12 @@ class NoopUpDownCounter : public UpDownCounter<T>
nostd::string_view unit) noexcept
{}
void Add(T value) noexcept override {}
void Add(T value, const opentelemetry::context::Context &context) noexcept override {}
void Add(T value, const common::KeyValueIterable &attributes) noexcept override {}
void Add(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept override
{}
};

template <class T>
Expand Down
90 changes: 75 additions & 15 deletions api/include/opentelemetry/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# include "opentelemetry/common/attribute_value.h"
# include "opentelemetry/common/key_value_iterable_view.h"
# include "opentelemetry/context/context.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/nostd/type_traits.h"
Expand All @@ -29,6 +30,8 @@ class Counter : public SynchronousInstrument
*/
virtual void Add(T value) noexcept = 0;

virtual void Add(T value, const opentelemetry::context::Context &context) noexcept = 0;

/**
* Add adds the value to the counter's sum. The attributes should contain
* the keys and values to be associated with this value. Counters only
Expand All @@ -40,19 +43,44 @@ class Counter : public SynchronousInstrument

virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;

virtual void Add(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept = 0;

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes});
auto context = opentelemetry::context::Context{};
this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
}

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
}

void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
auto context = opentelemetry::context::Context{};
this->Add(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}

void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
const opentelemetry::context::Context &context) noexcept
{
this->Add(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}
};

Expand All @@ -67,29 +95,34 @@ class Histogram : public SynchronousInstrument
*
* @param value The increment amount. May be positive, negative or zero.
*/
virtual void Record(T value) noexcept = 0;
virtual void Record(T value, const opentelemetry::context::Context &context) noexcept = 0;

/**
* Records a value with a set of attributes.
*
* @param value The increment amount. May be positive, negative or zero.
* @param attributes A set of attributes to associate with the count.
*/
virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0;
virtual void Record(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept = 0;

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Record(T value, const U &attributes) noexcept
void Record(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept
{
this->Record(value, common::KeyValueIterableView<U>{attributes});
this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
}

void Record(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
void Record(
T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
const opentelemetry::context::Context &context) noexcept
{
this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
this->Record(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}
};

Expand All @@ -106,6 +139,8 @@ class UpDownCounter : public SynchronousInstrument
*/
virtual void Add(T value) noexcept = 0;

virtual void Add(T value, const opentelemetry::context::Context &context) noexcept = 0;

/**
* Add a value with a set of attributes.
*
Expand All @@ -114,19 +149,44 @@ class UpDownCounter : public SynchronousInstrument
*/
virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;

virtual void Add(T value,
const common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept = 0;

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes});
auto context = opentelemetry::context::Context{};
this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
}

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
}

void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
auto context = opentelemetry::context::Context{};
this->Add(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}

void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
const opentelemetry::context::Context &context) noexcept
{
this->Add(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}
};

Expand Down
31 changes: 31 additions & 0 deletions api/test/metrics/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark")

cc_test(
name = "noop_sync_instrument_test",
srcs = [
"noop_sync_instrument_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"//api",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "meter_provider_test",
srcs = [
"meter_provider_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"//api",
"@com_google_googletest//:gtest_main",
],
)
Loading

0 comments on commit 15e7725

Please sign in to comment.