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

Metrics: Avoid defensive copies of MetricPoint struct #3065

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
to `-1`.
([#3038](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3038))

* Marked members of the `MetricPoint` `struct` which do not mutate state as
`readonly`
([#3065](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3065))

## 1.2.0-rc3

Released 2022-Mar-04
Expand Down
24 changes: 12 additions & 12 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal MetricPoint(
/// <summary>
/// Gets the tags associated with the metric point.
/// </summary>
public ReadOnlyTagCollection Tags
public readonly ReadOnlyTagCollection Tags
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
Expand All @@ -86,7 +86,7 @@ public ReadOnlyTagCollection Tags
public DateTimeOffset StartTime
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
readonly get;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal set;
Expand All @@ -98,7 +98,7 @@ public DateTimeOffset StartTime
public DateTimeOffset EndTime
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
readonly get;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal set;
Expand All @@ -107,7 +107,7 @@ public DateTimeOffset EndTime
internal MetricPointStatus MetricPointStatus
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
readonly get;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private set;
Expand All @@ -121,7 +121,7 @@ internal MetricPointStatus MetricPointStatus
/// </remarks>
/// <returns>Long sum value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetSumLong()
public readonly long GetSumLong()
{
if (this.aggType != AggregationType.LongSumIncomingDelta && this.aggType != AggregationType.LongSumIncomingCumulative)
{
Expand All @@ -139,7 +139,7 @@ public long GetSumLong()
/// </remarks>
/// <returns>Double sum value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double GetSumDouble()
public readonly double GetSumDouble()
{
if (this.aggType != AggregationType.DoubleSumIncomingDelta && this.aggType != AggregationType.DoubleSumIncomingCumulative)
{
Expand All @@ -157,7 +157,7 @@ public double GetSumDouble()
/// </remarks>
/// <returns>Long gauge value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetGaugeLastValueLong()
public readonly long GetGaugeLastValueLong()
{
if (this.aggType != AggregationType.LongGauge)
{
Expand All @@ -175,7 +175,7 @@ public long GetGaugeLastValueLong()
/// </remarks>
/// <returns>Double gauge value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double GetGaugeLastValueDouble()
public readonly double GetGaugeLastValueDouble()
{
if (this.aggType != AggregationType.DoubleGauge)
{
Expand All @@ -193,7 +193,7 @@ public double GetGaugeLastValueDouble()
/// </remarks>
/// <returns>Count value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetHistogramCount()
public readonly long GetHistogramCount()
{
if (this.aggType != AggregationType.Histogram && this.aggType != AggregationType.HistogramSumCount)
{
Expand All @@ -211,7 +211,7 @@ public long GetHistogramCount()
/// </remarks>
/// <returns>Sum value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double GetHistogramSum()
public readonly double GetHistogramSum()
{
if (this.aggType != AggregationType.Histogram && this.aggType != AggregationType.HistogramSumCount)
{
Expand All @@ -229,7 +229,7 @@ public double GetHistogramSum()
/// </remarks>
/// <returns><see cref="HistogramBuckets"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HistogramBuckets GetHistogramBuckets()
public readonly HistogramBuckets GetHistogramBuckets()
{
if (this.aggType != AggregationType.Histogram && this.aggType != AggregationType.HistogramSumCount)
{
Expand Down Expand Up @@ -542,7 +542,7 @@ internal void TakeSnapshot(bool outputDelta)
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void ThrowNotSupportedMetricTypeException(string methodName)
private readonly void ThrowNotSupportedMetricTypeException(string methodName)
{
throw new NotSupportedException($"{methodName} is not supported for this metric type.");
}
Expand Down