MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Flush

Method Flush

lib/perfdata/otlpmetricswriter.cpp:237–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237void OTLPMetricsWriter::Flush(bool fromTimer)
238{
239 // If previous export is still in progress and this flush is requested from timer, skip it.
240 // For manual flushes (e.g., due to reaching flush threshold), we want to block until
241 // the previous export is done before returning to the caller (blocking is handled in OTel::Export()).
242 if (fromTimer && m_Exporter->Exporting()) {
243 return;
244 }
245
246 Log(LogDebug, "OTLPMetricsWriter")
247 << "Flushing OTel metrics to OpenTelemetry backend" << (fromTimer ? " (timer expired)." : ".");
248
249 auto request = std::make_unique<OTel::MetricsRequest>();
250 for (auto& [checkable, resourceMetrics] : m_Metrics) {
251 if (resourceMetrics) {
252 request->mutable_resource_metrics()->AddAllocated(resourceMetrics.release());
253 }
254 }
255 if (request->resource_metrics_size() == 0) {
256 Log(LogDebug, "OTLPMetricsWriter")
257 << "Not flushing OTel metrics: No data points recorded.";
258 return;
259 }
260 m_Exporter->Export(std::move(request));
261 m_RecordedBytes.store(0, std::memory_order_relaxed);
262 m_DataPointsCount.store(0, std::memory_order_relaxed);
263}
264
265void OTLPMetricsWriter::AddBytesAndFlushIfNeeded(std::size_t newBytes)
266{

Callers

nothing calls this directly

Calls 4

LogClass · 0.85
ExportingMethod · 0.80
ExportMethod · 0.80
storeMethod · 0.80

Tested by

no test coverage detected