Skip to content

Commit

Permalink
Cleanup Metric aggregators and unused code (#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Sep 10, 2021
1 parent 16b3188 commit 3e0c451
Show file tree
Hide file tree
Showing 28 changed files with 21 additions and 1,451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ public static void WriteMetricsCollection(this PrometheusExporter exporter, Stre

case MetricType.Histogram:
{
/*
* For Histogram we emit one row for Sum, Count and as
* many rows as number of buckets.
* myHistogram_sum{tag1="value1",tag2="value2"} 258330 1629860660991
* myHistogram_count{tag1="value1",tag2="value2"} 355 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="0"} 0 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="5"} 2 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="10"} 4 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="25"} 6 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="50"} 12 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="75"} 19 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="100"} 26 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="250"} 65 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="500"} 128 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="1000"} 241 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="+Inf"} 355 1629860660991
*/
builder = builder.WithType(PrometheusHistogramType);
foreach (var metricPoint in metric.GetMetricPoints())
{
Expand Down Expand Up @@ -187,68 +204,5 @@ public static string GetMetricsCollection(this PrometheusExporter exporter)

return Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length);
}

private static void WriteHistogram(
StreamWriter writer,
PrometheusMetricBuilder builder,
IEnumerable<KeyValuePair<string, object>> labels,
string metricName,
double sum,
long count,
IEnumerable<HistogramBucket> buckets)
{
/* For Histogram we emit one row for Sum, Count and as
* many rows as number of buckets.
* myHistogram_sum{tag1="value1",tag2="value2"} 258330 1629860660991
* myHistogram_count{tag1="value1",tag2="value2"} 355 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="0"} 0 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="5"} 2 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="10"} 4 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="25"} 6 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="50"} 12 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="75"} 19 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="100"} 26 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="250"} 65 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="500"} 128 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="1000"} 241 1629860660991
* myHistogram_bucket{tag1="value1",tag2="value2",le="+Inf"} 355 1629860660991
*/

builder = builder.WithType(PrometheusHistogramType);
var metricValueBuilderSum = builder.AddValue();
metricValueBuilderSum.WithName(metricName + PrometheusHistogramSumPostFix);
metricValueBuilderSum = metricValueBuilderSum.WithValue(sum);
foreach (var label in labels)
{
metricValueBuilderSum.WithLabel(label.Key, label.Value.ToString());
}

var metricValueBuilderCount = builder.AddValue();
metricValueBuilderCount.WithName(metricName + PrometheusHistogramCountPostFix);
metricValueBuilderCount = metricValueBuilderCount.WithValue(count);
foreach (var label in labels)
{
metricValueBuilderCount.WithLabel(label.Key, label.Value.ToString());
}

long totalCount = 0;
foreach (var bucket in buckets)
{
totalCount += bucket.Count;
var metricValueBuilderBuckets = builder.AddValue();
metricValueBuilderBuckets.WithName(metricName + PrometheusHistogramBucketPostFix);
metricValueBuilderBuckets = metricValueBuilderBuckets.WithValue(totalCount);
foreach (var label in labels)
{
metricValueBuilderBuckets.WithLabel(label.Key, label.Value.ToString());
}

var bucketName = double.IsPositiveInfinity(bucket.HighBoundary) ?
PrometheusHistogramBucketLabelPositiveInfinity : bucket.HighBoundary.ToString(CultureInfo.InvariantCulture);
metricValueBuilderBuckets.WithLabel(PrometheusHistogramBucketLabelLessThan, bucketName);
}

builder.Write(writer);
}
}
}
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Metrics perf improvements, bug fixes.
Replace MetricProcessor with MetricReader.
([#2306](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2306))

* Add `BatchExportActivityProcessorOptions` which supports field value overriding
using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
`OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Text;

namespace OpenTelemetry.Metrics
{
public enum AggregationTemporality
Expand Down

This file was deleted.

25 changes: 0 additions & 25 deletions src/OpenTelemetry/Metrics/MetricAggregators/HistogramBucket.cs

This file was deleted.

70 changes: 0 additions & 70 deletions src/OpenTelemetry/Metrics/MetricAggregators/HistogramMetric.cs

This file was deleted.

Loading

0 comments on commit 3e0c451

Please sign in to comment.