Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix metrics race condition #1552

Merged
merged 5 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LongHistogramAggregation : public Aggregation
PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
mutable opentelemetry::common::SpinLockMutex lock_;
HistogramPointData point_data_;
bool record_min_max_ = true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LongLastValueAggregation : public Aggregation
PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
mutable opentelemetry::common::SpinLockMutex lock_;
LastValuePointData point_data_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LongSumAggregation : public Aggregation
PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
mutable opentelemetry::common::SpinLockMutex lock_;
SumPointData point_data_;
};

Expand Down
2 changes: 2 additions & 0 deletions sdk/src/metrics/aggregation/histogram_aggregation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::unique_ptr<Aggregation> LongHistogramAggregation::Diff(const Aggregation &n

PointType LongHistogramAggregation::ToPoint() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return point_data_;
}

Expand Down Expand Up @@ -176,6 +177,7 @@ std::unique_ptr<Aggregation> DoubleHistogramAggregation::Diff(

PointType DoubleHistogramAggregation::ToPoint() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
return point_data_;
}

Expand Down
2 changes: 2 additions & 0 deletions sdk/src/metrics/aggregation/lastvalue_aggregation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ std::unique_ptr<Aggregation> LongLastValueAggregation::Diff(const Aggregation &n

PointType LongLastValueAggregation::ToPoint() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return point_data_;
}

Expand Down Expand Up @@ -126,6 +127,7 @@ std::unique_ptr<Aggregation> DoubleLastValueAggregation::Diff(

PointType DoubleLastValueAggregation::ToPoint() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return point_data_;
}
} // namespace metrics
Expand Down
1 change: 1 addition & 0 deletions sdk/src/metrics/aggregation/sum_aggregation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ std::unique_ptr<Aggregation> LongSumAggregation::Diff(const Aggregation &next) c

PointType LongSumAggregation::ToPoint() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return point_data_;
}

Expand Down