Skip to content

Commit 4762910

Browse files
authored
Merge branch 'merge_main_into_async-changes' into merge_async-changes_into_main (#1413)
1 parent 9efb7a1 commit 4762910

39 files changed

+4027
-1252
lines changed

.github/workflows/ci.yml

+55
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ jobs:
2323
sudo ./ci/setup_thrift.sh
2424
./ci/do_ci.sh cmake.test
2525
26+
cmake_with_async_export_test:
27+
name: CMake test (without otlp-exporter and with async export)
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
with:
32+
submodules: 'recursive'
33+
- name: setup
34+
run: |
35+
sudo ./ci/setup_cmake.sh
36+
sudo ./ci/setup_ci_environment.sh
37+
- name: run cmake tests (without otlp-exporter)
38+
run: |
39+
sudo ./ci/setup_thrift.sh
40+
./ci/do_ci.sh cmake.with_async_export.test
41+
2642
cmake_absel_stl_test:
2743
name: CMake test (with abseil)
2844
runs-on: ubuntu-latest
@@ -150,6 +166,28 @@ jobs:
150166
- name: run tests
151167
run: ./ci/do_ci.sh bazel.test
152168

169+
bazel_test_async:
170+
name: Bazel with async export
171+
runs-on: ubuntu-latest
172+
steps:
173+
- uses: actions/checkout@v3
174+
with:
175+
submodules: 'recursive'
176+
- name: Mount Bazel Cache
177+
uses: actions/cache@v3
178+
env:
179+
cache-name: bazel_cache
180+
with:
181+
path: /home/runner/.cache/bazel
182+
key: bazel_test
183+
- name: setup
184+
run: |
185+
sudo ./ci/setup_thrift.sh dependencies_only
186+
sudo ./ci/setup_ci_environment.sh
187+
sudo ./ci/install_bazelisk.sh
188+
- name: run tests
189+
run: ./ci/do_ci.sh bazel.with_async_export.test
190+
153191
bazel_with_abseil:
154192
name: Bazel with external abseil
155193
runs-on: ubuntu-latest
@@ -355,6 +393,23 @@ jobs:
355393
- name: run otprotocol test
356394
run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.test
357395

396+
windows_with_async_export:
397+
name: CMake (With async export) -> exporter proto
398+
runs-on: windows-2019
399+
steps:
400+
- uses: actions/checkout@v3
401+
with:
402+
submodules: 'recursive'
403+
- name: setup
404+
run: |
405+
./ci/setup_windows_cmake.ps1
406+
./ci/setup_windows_ci_environment.ps1
407+
./ci/install_windows_protobuf.ps1
408+
- name: run cmake test
409+
run: ./ci/do_ci.ps1 cmake.with_async_export.test
410+
- name: run otprotocol test
411+
run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.with_async_export.test
412+
358413
windows_bazel:
359414
name: Bazel Windows
360415
runs-on: windows-2019

.github/workflows/stale.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: 'Mark and close stale issues'
1+
name: "Mark and close stale issues"
22
on:
33
schedule:
4-
- cron: '30 1 * * *'
4+
- cron: "30 1 * * *"
55

66
jobs:
77
stale:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/stale@v5
1111
with:
12-
stale-issue-message: 'This issue was marked as stale due to lack of activity.'
12+
stale-issue-message: "This issue was marked as stale due to lack of activity."
1313
days-before-issue-stale: 60
14-
exempt-issue-labels: 'do-not-stale'
14+
exempt-issue-labels: "do-not-stale"

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [EXPORTER] OTLP http exporter allow concurrency session ([#1209](https://github.com/open-telemetry/opentelemetry-cpp/pull/1209))
19+
* [EXT] `curl::HttpClient` use `curl_multi_handle` instead of creating a thread
20+
for every request and it's able to reuse connections now. ([#1317](https://github.com/open-telemetry/opentelemetry-cpp/pull/1317))
21+
1822
## [1.4.1] 2022-06-19
1923

2024
* [METRICS SDK] Fix variables inizialization [#1430](https://github.com/open-telemetry/opentelemetry-cpp/pull/1430)

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ option(WITH_EXAMPLES "Whether to build examples" ON)
186186

187187
option(WITH_METRICS_PREVIEW "Whether to build metrics preview" OFF)
188188
option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF)
189+
option(WITH_ASYNC_EXPORT_PREVIEW "Whether enable async export" OFF)
189190

190191
find_package(Threads)
191192

api/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ if(WIN32)
9292
target_compile_definitions(opentelemetry_api INTERFACE HAVE_MSGPACK)
9393
endif()
9494
endif()
95+
96+
if(WITH_ASYNC_EXPORT_PREVIEW)
97+
target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT)
98+
endif()

api/include/opentelemetry/common/spin_lock_mutex.h

+19-14
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ class SpinLockMutex
5959
SpinLockMutex &operator=(const SpinLockMutex &) = delete;
6060
SpinLockMutex &operator=(const SpinLockMutex &) volatile = delete;
6161

62+
static inline void fast_yield() noexcept
63+
{
64+
// Issue a Pause/Yield instruction while spinning.
65+
#if defined(_MSC_VER)
66+
YieldProcessor();
67+
#elif defined(__i386__) || defined(__x86_64__)
68+
# if defined(__clang__)
69+
_mm_pause();
70+
# else
71+
__builtin_ia32_pause();
72+
# endif
73+
#elif defined(__arm__)
74+
__asm__ volatile("yield" ::: "memory");
75+
#else
76+
// TODO: Issue PAGE/YIELD on other architectures.
77+
#endif
78+
}
79+
6280
/**
6381
* Attempts to lock the mutex. Return immediately with `true` (success) or `false` (failure).
6482
*/
@@ -91,20 +109,7 @@ class SpinLockMutex
91109
{
92110
return;
93111
}
94-
// Issue a Pause/Yield instruction while spinning.
95-
#if defined(_MSC_VER)
96-
YieldProcessor();
97-
#elif defined(__i386__) || defined(__x86_64__)
98-
# if defined(__clang__)
99-
_mm_pause();
100-
# else
101-
__builtin_ia32_pause();
102-
# endif
103-
#elif defined(__arm__)
104-
__asm__ volatile("yield" ::: "memory");
105-
#else
106-
// TODO: Issue PAGE/YIELD on other architectures.
107-
#endif
112+
fast_yield();
108113
}
109114
// Yield then try again (goal ~100ns)
110115
std::this_thread::yield();

api/include/opentelemetry/common/timestamp.h

+34
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,39 @@ class SteadyTimestamp
169169
private:
170170
int64_t nanos_since_epoch_;
171171
};
172+
173+
class DurationUtil
174+
{
175+
public:
176+
template <class Rep, class Period>
177+
static std::chrono::duration<Rep, Period> AdjustWaitForTimeout(
178+
std::chrono::duration<Rep, Period> timeout,
179+
std::chrono::duration<Rep, Period> indefinite_value) noexcept
180+
{
181+
// Do not call now() when this duration is max value, now() may have a expensive cost.
182+
if (timeout == std::chrono::duration<Rep, Period>::max())
183+
{
184+
return indefinite_value;
185+
}
186+
187+
// std::future<T>::wait_for, std::this_thread::sleep_for, and std::condition_variable::wait_for
188+
// may use steady_clock or system_clock.We need make sure now() + timeout do not overflow.
189+
auto max_timeout = std::chrono::duration_cast<std::chrono::duration<Rep, Period>>(
190+
std::chrono::steady_clock::time_point::max() - std::chrono::steady_clock::now());
191+
if (timeout >= max_timeout)
192+
{
193+
return indefinite_value;
194+
}
195+
max_timeout = std::chrono::duration_cast<std::chrono::duration<Rep, Period>>(
196+
std::chrono::system_clock::time_point::max() - std::chrono::system_clock::now());
197+
if (timeout >= max_timeout)
198+
{
199+
return indefinite_value;
200+
}
201+
202+
return timeout;
203+
}
204+
};
205+
172206
} // namespace common
173207
OPENTELEMETRY_END_NAMESPACE

ci/do_ci.ps1

+46-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $action = $args[0]
55

66
$SRC_DIR = (Get-Item -Path ".\").FullName
77

8-
$BAZEL_OPTIONS = "--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW"
8+
$BAZEL_OPTIONS = "--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_ASYNC_EXPORT"
99
$BAZEL_TEST_OPTIONS = "$BAZEL_OPTIONS --test_output=errors"
1010

1111
if (!(test-path build)) {
@@ -48,6 +48,27 @@ switch ($action) {
4848
exit $exit
4949
}
5050
}
51+
"cmake.with_async_export.test" {
52+
cd "$BUILD_DIR"
53+
cmake $SRC_DIR `
54+
-DVCPKG_TARGET_TRIPLET=x64-windows `
55+
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
56+
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
57+
$exit = $LASTEXITCODE
58+
if ($exit -ne 0) {
59+
exit $exit
60+
}
61+
cmake --build .
62+
$exit = $LASTEXITCODE
63+
if ($exit -ne 0) {
64+
exit $exit
65+
}
66+
ctest -C Debug
67+
$exit = $LASTEXITCODE
68+
if ($exit -ne 0) {
69+
exit $exit
70+
}
71+
}
5172
"cmake.exporter.otprotocol.test" {
5273
cd "$BUILD_DIR"
5374
cmake $SRC_DIR `
@@ -69,10 +90,33 @@ switch ($action) {
6990
exit $exit
7091
}
7192
}
93+
"cmake.exporter.otprotocol.with_async_export.test" {
94+
cd "$BUILD_DIR"
95+
cmake $SRC_DIR `
96+
-DVCPKG_TARGET_TRIPLET=x64-windows `
97+
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
98+
-DWITH_OTPROTCOL=ON `
99+
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
100+
$exit = $LASTEXITCODE
101+
if ($exit -ne 0) {
102+
exit $exit
103+
}
104+
cmake --build .
105+
$exit = $LASTEXITCODE
106+
if ($exit -ne 0) {
107+
exit $exit
108+
}
109+
ctest -C Debug
110+
$exit = $LASTEXITCODE
111+
if ($exit -ne 0) {
112+
exit $exit
113+
}
114+
}
72115
"cmake.build_example_plugin" {
73116
cd "$BUILD_DIR"
74117
cmake $SRC_DIR `
75118
-DVCPKG_TARGET_TRIPLET=x64-windows `
119+
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
76120
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
77121
$exit = $LASTEXITCODE
78122
if ($exit -ne 0) {
@@ -89,6 +133,7 @@ switch ($action) {
89133
cd "$BUILD_DIR"
90134
cmake $SRC_DIR `
91135
-DVCPKG_TARGET_TRIPLET=x64-windows `
136+
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
92137
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
93138
$exit = $LASTEXITCODE
94139
if ($exit -ne 0) {

0 commit comments

Comments
 (0)