]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / sdk / include / opentelemetry / sdk / metrics / export / periodic_exporting_metric_reader.h
CommitLineData
1e59de90
TL
1// Copyright The OpenTelemetry Authors
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5#ifndef ENABLE_METRICS_PREVIEW
6
7# include "opentelemetry/sdk/metrics/metric_reader.h"
8# include "opentelemetry/version.h"
9
10# include <atomic>
11# include <chrono>
12# include <condition_variable>
13# include <thread>
14
15OPENTELEMETRY_BEGIN_NAMESPACE
16namespace sdk
17{
18namespace metrics
19{
20
21class MetricExporter;
22/**
23 * Struct to hold PeriodicExortingMetricReader options.
24 */
25
26constexpr std::chrono::milliseconds kExportIntervalMillis = std::chrono::milliseconds(60000);
27constexpr std::chrono::milliseconds kExportTimeOutMillis = std::chrono::milliseconds(30000);
28struct PeriodicExportingMetricReaderOptions
29{
30
31 /* The time interval between two consecutive exports. */
32 std::chrono::milliseconds export_interval_millis =
33 std::chrono::milliseconds(kExportIntervalMillis);
34
35 /* how long the export can run before it is cancelled. */
36 std::chrono::milliseconds export_timeout_millis = std::chrono::milliseconds(kExportTimeOutMillis);
37};
38
39class PeriodicExportingMetricReader : public MetricReader
40{
41
42public:
43 PeriodicExportingMetricReader(
44 std::unique_ptr<MetricExporter> exporter,
45 const PeriodicExportingMetricReaderOptions &option,
46 AggregationTemporality aggregation_temporality = AggregationTemporality::kCumulative);
47
48private:
49 bool OnForceFlush(std::chrono::microseconds timeout) noexcept override;
50
51 bool OnShutDown(std::chrono::microseconds timeout) noexcept override;
52
53 void OnInitialized() noexcept override;
54
55 std::unique_ptr<MetricExporter> exporter_;
56 std::chrono::milliseconds export_interval_millis_;
57 std::chrono::milliseconds export_timeout_millis_;
58
59 void DoBackgroundWork();
60
61 /* The background worker thread */
62 std::thread worker_thread_;
63
64 /* Synchronization primitives */
65 std::condition_variable cv_;
66 std::mutex cv_m_;
67};
68
69} // namespace metrics
70} // namespace sdk
71OPENTELEMETRY_END_NAMESPACE
72#endif