Use HashSet for MetricSreamNames (#2545)

Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com>
This commit is contained in:
Utkarsh Umesan Pillai 2021-10-28 17:52:09 -07:00 committed by GitHub
parent c2f65108e9
commit ac7b8d623e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -34,7 +34,7 @@ namespace OpenTelemetry.Metrics
private readonly List<Func<Instrument, MetricStreamConfiguration>> viewConfigs;
private readonly object collectLock = new object();
private readonly object instrumentCreationLock = new object();
private readonly Dictionary<string, bool> metricStreamNames = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> metricStreamNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly MeterListener listener;
private readonly MetricReader reader;
private int metricIndex = -1;
@ -152,7 +152,7 @@ namespace OpenTelemetry.Metrics
{
var metricStreamConfig = metricStreamConfigs[i];
var metricStreamName = metricStreamConfig?.Name ?? instrument.Name;
if (this.metricStreamNames.ContainsKey(metricStreamName))
if (this.metricStreamNames.Contains(metricStreamName))
{
// TODO: Log that instrument is ignored
// as the resulting Metric name is conflicting
@ -185,7 +185,7 @@ namespace OpenTelemetry.Metrics
this.metrics[index] = metric;
metrics.Add(metric);
this.metricStreamNames.Add(metricStreamName, true);
this.metricStreamNames.Add(metricStreamName);
}
}
@ -222,7 +222,7 @@ namespace OpenTelemetry.Metrics
Metric metric = null;
lock (this.instrumentCreationLock)
{
if (this.metricStreamNames.ContainsKey(metricName))
if (this.metricStreamNames.Contains(metricName))
{
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(metricName, instrument.Meter.Name, "Metric name conflicting with existing name.", "Either change the name of the instrument or change name using View.");
return;
@ -238,7 +238,7 @@ namespace OpenTelemetry.Metrics
{
metric = new Metric(instrument, temporality, metricName, instrument.Description);
this.metrics[index] = metric;
this.metricStreamNames.Add(metricName, true);
this.metricStreamNames.Add(metricName);
}
}