Skip to content

Commit

Permalink
fix format, and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Nov 17, 2022
1 parent 770dd3a commit bd54556
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions sdk/include/opentelemetry/sdk/metrics/meter_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
* NOTE - INTERNAL method, can change in future.
* Process callback for each meter in thread-safe manner
*/
bool ForEachMeter(nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept;
bool ForEachMeter(nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept;

/**
/**
* NOTE - INTERNAL method, can change in future.
* Obtain the configured meters.
* This method is NOT thread-safe.
* Get the configured meters.
* This method is NOT thread safe, and only called through MeterProvider
*
*/
nostd::span<std::shared_ptr<Meter>> GetMeters() noexcept;
Expand Down Expand Up @@ -104,8 +104,8 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
std::unique_ptr<View> view) noexcept;

/**
* Adds a meter to the list of configured meters.
* Note: This method is INTERNAL to sdk not thread safe.
* NOTE - INTERNAL method, can change in future.
* Adds a meter to the list of configured meters in thread safe manner.
*
* @param meter
*/
Expand Down
15 changes: 8 additions & 7 deletions sdk/src/metrics/meter_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ ViewRegistry *MeterContext::GetViewRegistry() const noexcept
return views_.get();
}

bool MeterContext::ForEachMeter(nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept
bool MeterContext::ForEachMeter(
nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(meter_lock_);
for (auto &meter: meters_)
for (auto &meter : meters_)
{
if (!callback(meter))
{
if (!callback(meter))
{
return false;
}
return false;
}
return true;
}
return true;
}

nostd::span<std::shared_ptr<Meter>> MeterContext::GetMeters() noexcept
Expand Down
5 changes: 2 additions & 3 deletions sdk/src/metrics/state/metric_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ bool MetricCollector::Collect(
return false;
}
ResourceMetrics resource_metrics;
meter_context_->ForEachMeter([&](std::shared_ptr<Meter> meter) noexcept
{
meter_context_->ForEachMeter([&](std::shared_ptr<Meter> meter) noexcept {
auto collection_ts = std::chrono::system_clock::now();
ScopeMetrics scope_metrics;
scope_metrics.metric_data_ = meter->Collect(this, collection_ts);
scope_metrics.scope_ = meter->GetInstrumentationScope();
resource_metrics.scope_metric_data_.push_back(scope_metrics);
resource_metrics.scope_metric_data_.push_back(scope_metrics);
return true;
});
resource_metrics.resource_ = &meter_context_->GetResource();
Expand Down

0 comments on commit bd54556

Please sign in to comment.