Skip to content

Commit

Permalink
Refactor from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
victlu committed Jun 11, 2021
1 parent f7d01d4 commit 786c636
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 22 deletions.
12 changes: 3 additions & 9 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,18 @@ internal MetricAgg[] MapToMetrics(string[] seqKey, object[] seqVal)
{
metricpairs.Add(new MetricAgg(timeperiod, new SumMetricAggregator(name, dt, tags, false, true)));
metricpairs.Add(new MetricAgg(timeperiod, new SumMetricAggregator(name, dt, tags, true, true)));
metricpairs.Add(new MetricAgg(timeperiod, new SummaryMetricAggregator(name, dt, tags, false)));
}
else if (this.instrument.GetType().Name.Contains("Gauge"))
{
metricpairs.Add(new MetricAgg(timeperiod, new GaugeMetricAggregator(name, dt, tags, false)));
metricpairs.Add(new MetricAgg(timeperiod, new SummaryMetricAggregator(name, dt, tags, false)));
metricpairs.Add(new MetricAgg(timeperiod, new GaugeMetricAggregator(name, dt, tags)));
}
else if (this.instrument.GetType().Name.Contains("Histogram"))
{
metricpairs.Add(new MetricAgg(timeperiod, new HistogramMetricAggregator(name, dt, tags, false)));
}
else
{
metricpairs.Add(new MetricAgg(timeperiod, new GaugeMetricAggregator(name, dt, tags, false)));
metricpairs.Add(new MetricAgg(timeperiod, new SumMetricAggregator(name, dt, tags, false, true)));
metricpairs.Add(new MetricAgg(timeperiod, new SumMetricAggregator(name, dt, tags, true, true)));
metricpairs.Add(new MetricAgg(timeperiod, new SummaryMetricAggregator(name, dt, tags, false)));
metricpairs.Add(new MetricAgg(timeperiod, new HistogramMetricAggregator(name, dt, tags, false)));
}
}

Expand Down Expand Up @@ -205,9 +199,9 @@ internal List<IMetric> Collect(int periodMilliseconds)
internal class MetricAgg
{
internal int TimePeriod;
internal IMetricBuilder Metric;
internal IAggregator Metric;

internal MetricAgg(int timePeriod, IMetricBuilder metric)
internal MetricAgg(int timePeriod, IAggregator metric)
{
this.TimePeriod = timePeriod;
this.Metric = metric;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@

namespace OpenTelemetry.Metrics
{
internal class GaugeMetricAggregator : IGaugeMetric, IMetricBuilder
internal class GaugeMetricAggregator : IGaugeMetric, IAggregator
{
private readonly object lockUpdate = new object();
private Type valueType;
private long longValue;
private double doubleValue;

internal GaugeMetricAggregator(string name, DateTimeOffset startTimeExclusive, KeyValuePair<string, object>[] attributes, bool isDelta)
internal GaugeMetricAggregator(string name, DateTimeOffset startTimeExclusive, KeyValuePair<string, object>[] attributes)
{
this.Name = name;
this.StartTimeExclusive = startTimeExclusive;
this.EndTimeInclusive = startTimeExclusive;
this.Attributes = attributes;
this.IsDeltaTemporality = isDelta;
}

public string Name { get; private set; }
Expand All @@ -43,8 +42,6 @@ internal GaugeMetricAggregator(string name, DateTimeOffset startTimeExclusive, K

public KeyValuePair<string, object>[] Attributes { get; private set; }

public bool IsDeltaTemporality { get; }

public IEnumerable<IExemplar> Exemplars { get; private set; } = new List<IExemplar>();

public IDataPoint LastValue
Expand Down Expand Up @@ -93,7 +90,7 @@ public void Update<T>(DateTimeOffset dt, T value)

public IMetric Collect(DateTimeOffset dt)
{
var cloneItem = new GaugeMetricAggregator(this.Name, this.StartTimeExclusive, this.Attributes, this.IsDeltaTemporality);
var cloneItem = new GaugeMetricAggregator(this.Name, this.StartTimeExclusive, this.Attributes);

lock (this.lockUpdate)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenTelemetry.Metrics
{
internal class HistogramMetricAggregator : IHistogramMetric, IMetricBuilder
internal class HistogramMetricAggregator : IHistogramMetric, IAggregator
{
private readonly object lockUpdate = new object();
private List<HistogramBucket> buckets = new List<HistogramBucket>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="IMetricBuilder.cs" company="OpenTelemetry Authors">
// <copyright file="IAggregator.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +18,7 @@

namespace OpenTelemetry.Metrics
{
internal interface IMetricBuilder
internal interface IAggregator
{
void Update<T>(DateTimeOffset dt, T value)
where T : struct;
Expand Down
2 changes: 0 additions & 2 deletions src/OpenTelemetry/Metrics/MetricAggregators/IGaugeMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace OpenTelemetry.Metrics
{
internal interface IGaugeMetric : IMetric
{
bool IsDeltaTemporality { get; }

IEnumerable<IExemplar> Exemplars { get; }

IDataPoint LastValue { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenTelemetry.Metrics
{
internal class SumMetricAggregator : ISumMetric, IMetricBuilder
internal class SumMetricAggregator : ISumMetric, IAggregator
{
private readonly object lockUpdate = new object();
private Type valueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenTelemetry.Metrics
{
internal class SummaryMetricAggregator : ISummaryMetric, IMetricBuilder
internal class SummaryMetricAggregator : ISummaryMetric, IAggregator
{
private readonly object lockUpdate = new object();

Expand Down

0 comments on commit 786c636

Please sign in to comment.