Skip to content

Commit

Permalink
Fix build and reuse scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed Nov 29, 2023
1 parent 44eaa4d commit f8ee51b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int ScrapeResponseCacheDurationMilliseconds
}

/// <summary>
/// Gets or sets the ability to export metric scope info. Default value: true.
/// Gets or sets a value indicating whether to export metric scope info. Default value: true.
/// </summary>
public bool ScopeInfoEnabled
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal sealed class PrometheusCollectionManager
private readonly int scrapeResponseCacheDurationMilliseconds;
private readonly Func<Batch<Metric>, ExportResult> onCollectRef;
private readonly Dictionary<Metric, PrometheusMetric> metricsCache;
private readonly HashSet<string> scopes;
private int metricsCacheCount;
private byte[] buffer = new byte[85000]; // encourage the object to live in LOH (large object heap)
private int globalLockState;
Expand All @@ -42,6 +43,7 @@ public PrometheusCollectionManager(PrometheusExporter exporter)
this.scrapeResponseCacheDurationMilliseconds = this.exporter.ScrapeResponseCacheDurationMilliseconds;
this.onCollectRef = this.OnCollect;
this.metricsCache = new Dictionary<Metric, PrometheusMetric>();
this.scopes = new HashSet<string>();
}

#if NET6_0_OR_GREATER
Expand Down Expand Up @@ -184,17 +186,17 @@ private ExportResult OnCollect(Batch<Metric> metrics)
{
if (this.exporter.ScopeInfoEnabled)
{
var scopes = new HashSet<string>();
this.scopes.Clear();

foreach (var metric in metrics)
{
if (PrometheusSerializer.CanWriteMetric(metric))
{
scopes.Add(metric.MeterName);
this.scopes.Add(metric.MeterName);
}
}

foreach (var scope in scopes)
foreach (var scope in this.scopes)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int ScrapeResponseCacheDurationMilliseconds
}

/// <summary>
/// Gets or sets the ability to export metric scope info. Default value: true.
/// Gets or sets a value indicating whether to export metric scope info. Default value: true.
/// </summary>
public bool ScopeInfoEnabled { get; set; } = true;
}

0 comments on commit f8ee51b

Please sign in to comment.