Skip to content

Commit

Permalink
Combine scope writing with hashset
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed Dec 15, 2023
1 parent 22bfa08 commit 026cfeb
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,27 @@ private ExportResult OnCollect(Batch<Metric> metrics)
{
if (PrometheusSerializer.CanWriteMetric(metric))
{
this.scopes.Add(metric.MeterName);
}
}

foreach (var scope in this.scopes)
{
try
{
cursor = PrometheusSerializer.WriteScopeInfo(this.buffer, cursor, scope);

break;
}
catch (IndexOutOfRangeException)
{
if (!this.IncreaseBufferSize())
if (this.scopes.Add(metric.MeterName))
{
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want
// to put some upper limit and allow the user to configure it.
// 2. we got an IndexOutOfRangeException which was triggered by some other
// code instead of the buffer[cursor++] - in this case we should give up
// at certain point rather than allocating like crazy.
throw;
try
{
cursor = PrometheusSerializer.WriteScopeInfo(this.buffer, cursor, metric.MeterName);

break;
}
catch (IndexOutOfRangeException)
{
if (!this.IncreaseBufferSize())
{
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want
// to put some upper limit and allow the user to configure it.
// 2. we got an IndexOutOfRangeException which was triggered by some other
// code instead of the buffer[cursor++] - in this case we should give up
// at certain point rather than allocating like crazy.
throw;
}
}
}
}
}
Expand Down

0 comments on commit 026cfeb

Please sign in to comment.