Skip to content

Commit

Permalink
Merge branch 'main' into vibankwa/otlp-retry-implementation-part2
Browse files Browse the repository at this point in the history
  • Loading branch information
vishweshbankwar authored Feb 21, 2024
2 parents 52e13a1 + 4ae0aaf commit d49c60a
Show file tree
Hide file tree
Showing 27 changed files with 368 additions and 580 deletions.
28 changes: 5 additions & 23 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ name: "CodeQL"
on:
schedule:
- cron: '0 0 * * *' # once in a day at 00:00
workflow_dispatch:

jobs:
analyze:
Expand All @@ -17,11 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['csharp']
# Learn more...
# https://docs.github.com/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: configure Pagefile
Expand All @@ -34,31 +31,16 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v4

# Command-line programs to run using the OS shell.
# https://git.io/JvXDl

# If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
- name: dotnet pack OpenTelemetry.proj
run: dotnet pack OpenTelemetry.proj --configuration Release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
1 change: 0 additions & 1 deletion OpenTelemetry.proj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TestProjects Include="test\**\*.csproj" />

<!-- Not pack SemanticConventions project for now -->
<SolutionProjects Remove="src\OpenTelemetry.SemanticConventions\OpenTelemetry.SemanticConventions.csproj" />
<PackProjects Remove="src\OpenTelemetry.SemanticConventions\OpenTelemetry.SemanticConventions.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions
Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTotalNameSuffixForCounters.get -> bool
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTotalNameSuffixForCounters.set -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.PrometheusAspNetCoreOptions() -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.set -> void
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added option to disable _total suffix addition to counter metrics
([#5305](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5305))

* Export OpenMetrics format from Prometheus exporters ([#5107](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5107))
* For requests with OpenMetrics format, scope info is automatically added
([#5086](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5086)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public class PrometheusAspNetCoreOptions
/// </summary>
public string ScrapeEndpointPath { get; set; } = DefaultScrapeEndpointPath;

/// <summary>
/// Gets or sets a value indicating whether addition of _total suffix for counter metric names is disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTotalNameSuffixForCounters
{
get => this.ExporterOptions.DisableTotalNameSuffixForCounters;
set => this.ExporterOptions.DisableTotalNameSuffixForCounters = value;
}

/// <summary>
/// Gets or sets the cache duration in milliseconds for scrape responses. Default value: 300.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
OpenTelemetry.Exporter.PrometheusHttpListenerOptions
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTotalNameSuffixForCounters.get -> bool
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTotalNameSuffixForCounters.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.get -> System.Collections.Generic.IReadOnlyCollection<string>
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added option to disable _total suffix addition to counter metrics
([#5305](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5305))

* Export OpenMetrics format from Prometheus exporters
([#5107](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5107))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private PrometheusMetric GetPrometheusMetric(Metric metric)
// Optimize writing metrics with bounded cache that has pre-calculated Prometheus names.
if (!this.metricsCache.TryGetValue(metric, out var prometheusMetric))
{
prometheusMetric = PrometheusMetric.Create(metric);
prometheusMetric = PrometheusMetric.Create(metric, this.exporter.DisableTotalNameSuffixForCounters);

// Add to the cache if there is space.
if (this.metricsCacheCount < MaxCachedMetrics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public PrometheusExporter(PrometheusExporterOptions options)
Guard.ThrowIfNull(options);

this.ScrapeResponseCacheDurationMilliseconds = options.ScrapeResponseCacheDurationMilliseconds;
this.DisableTotalNameSuffixForCounters = options.DisableTotalNameSuffixForCounters;

this.CollectionManager = new PrometheusCollectionManager(this);
}
Expand All @@ -50,6 +51,8 @@ internal Func<Batch<Metric>, ExportResult> OnExport

internal int ScrapeResponseCacheDurationMilliseconds { get; }

internal bool DisableTotalNameSuffixForCounters { get; }

internal bool OpenMetricsRequested { get; set; }

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public int ScrapeResponseCacheDurationMilliseconds
this.scrapeResponseCacheDurationMilliseconds = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether addition of _total suffix for counter metric names is disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTotalNameSuffixForCounters { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ UpDownCounter becomes gauge
PrometheusType.Untyped, PrometheusType.Counter, PrometheusType.Gauge, PrometheusType.Summary, PrometheusType.Histogram, PrometheusType.Histogram, PrometheusType.Histogram, PrometheusType.Histogram, PrometheusType.Gauge,
};

public PrometheusMetric(string name, string unit, PrometheusType type)
public PrometheusMetric(string name, string unit, PrometheusType type, bool disableTotalNameSuffixForCounters)
{
// The metric name is
// required to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Invalid characters
Expand Down Expand Up @@ -48,7 +48,7 @@ public PrometheusMetric(string name, string unit, PrometheusType type)
// If the metric name for monotonic Sum metric points does not end in a suffix of `_total` a suffix of `_total` MUST be added by default, otherwise the name MUST remain unchanged.
// Exporters SHOULD provide a configuration option to disable the addition of `_total` suffixes.
// https://github.com/open-telemetry/opentelemetry-specification/blob/b2f923fb1650dde1f061507908b834035506a796/specification/compatibility/prometheus_and_openmetrics.md#L286
if (type == PrometheusType.Counter && !sanitizedName.EndsWith("_total"))
if (type == PrometheusType.Counter && !sanitizedName.EndsWith("_total") && !disableTotalNameSuffixForCounters)
{
sanitizedName += "_total";
}
Expand All @@ -71,9 +71,9 @@ public PrometheusMetric(string name, string unit, PrometheusType type)

public PrometheusType Type { get; }

public static PrometheusMetric Create(Metric metric)
public static PrometheusMetric Create(Metric metric, bool disableTotalNameSuffixForCounters)
{
return new PrometheusMetric(metric.Name, metric.Unit, GetPrometheusType(metric));
return new PrometheusMetric(metric.Name, metric.Unit, GetPrometheusType(metric), disableTotalNameSuffixForCounters);
}

internal static string SanitizeMetricName(string metricName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public static MeterProviderBuilder AddPrometheusHttpListener(
private static MetricReader BuildPrometheusHttpListenerMetricReader(
PrometheusHttpListenerOptions options)
{
var exporter = new PrometheusExporter(new PrometheusExporterOptions { ScrapeResponseCacheDurationMilliseconds = 0 });
var exporter = new PrometheusExporter(new PrometheusExporterOptions
{
ScrapeResponseCacheDurationMilliseconds = 0,
DisableTotalNameSuffixForCounters = options.DisableTotalNameSuffixForCounters,
});

var reader = new BaseExportingMetricReader(exporter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class PrometheusHttpListenerOptions
/// </summary>
public string ScrapeEndpointPath { get; set; } = "/metrics";

/// <summary>
/// Gets or sets a value indicating whether addition of _total suffix for counter metric names is disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTotalNameSuffixForCounters { get; set; }

/// <summary>
/// Gets or sets the URI (Uniform Resource Identifier) prefixes to use for the http listener.
/// Default value: <c>["http://localhost:9464/"]</c>.
Expand Down
2 changes: 0 additions & 2 deletions src/OpenTelemetry/Metrics/Base2ExponentialBucketHistogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ internal sealed partial class Base2ExponentialBucketHistogram
internal double RunningMax = double.NegativeInfinity;
internal double SnapshotMax;

internal int IsCriticalSectionOccupied = 0;

internal ExponentialHistogramData SnapshotExponentialHistogramData = new();

private int scale;
Expand Down
115 changes: 13 additions & 102 deletions src/OpenTelemetry/Metrics/CompositeMetricReaderExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,126 +11,37 @@ namespace OpenTelemetry.Metrics;
/// </summary>
internal sealed partial class CompositeMetricReader
{
internal List<Metric?> AddMetricsWithNoViews(Instrument instrument)
internal override List<Metric> AddMetricWithNoViews(Instrument instrument)
{
var metrics = new List<Metric?>(this.count);
var metrics = new List<Metric>(this.count);

for (var cur = this.Head; cur != null; cur = cur.Next)
{
metrics.Add(cur.Value.AddMetricWithNoViews(instrument));
}

return metrics;
}

internal void RecordSingleStreamLongMeasurements(List<Metric?> metrics, long value, ReadOnlySpan<KeyValuePair<string, object?>> tags)
{
Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
var metric = metrics[index];
if (metric != null)
var innerMetrics = cur.Value.AddMetricWithNoViews(instrument);
if (innerMetrics.Count > 0)
{
cur.Value.RecordSingleStreamLongMeasurement(metric, value, tags);
}

index++;
}
}

internal void RecordSingleStreamDoubleMeasurements(List<Metric?> metrics, double value, ReadOnlySpan<KeyValuePair<string, object?>> tags)
{
Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");
Debug.Assert(innerMetrics.Count == 1, "Multiple metrics returned without view configuration");

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
var metric = metrics[index];
if (metric != null)
{
cur.Value.RecordSingleStreamDoubleMeasurement(metric, value, tags);
metrics.AddRange(innerMetrics);
}

index++;
}
}

internal List<List<Metric>> AddMetricsSuperListWithViews(Instrument instrument, List<MetricStreamConfiguration?> metricStreamConfigs)
{
var metricsSuperList = new List<List<Metric>>(this.count);
for (var cur = this.Head; cur != null; cur = cur.Next)
{
var metrics = cur.Value.AddMetricsListWithViews(instrument, metricStreamConfigs);
metricsSuperList.Add(metrics);
}

return metricsSuperList;
}

internal void RecordLongMeasurements(List<List<Metric>> metricsSuperList, long value, ReadOnlySpan<KeyValuePair<string, object?>> tags)
{
Debug.Assert(metricsSuperList.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
if (metricsSuperList[index].Count > 0)
{
cur.Value.RecordLongMeasurement(metricsSuperList[index], value, tags);
}

index++;
}
return metrics;
}

internal void RecordDoubleMeasurements(List<List<Metric>> metricsSuperList, double value, ReadOnlySpan<KeyValuePair<string, object?>> tags)
internal override List<Metric> AddMetricWithViews(Instrument instrument, List<MetricStreamConfiguration?> metricStreamConfigs)
{
Debug.Assert(metricsSuperList.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
if (metricsSuperList[index].Count > 0)
{
cur.Value.RecordDoubleMeasurement(metricsSuperList[index], value, tags);
}

index++;
}
}
Debug.Assert(metricStreamConfigs != null, "metricStreamConfigs was null");

internal void CompleteSingleStreamMeasurements(List<Metric?> metrics)
{
Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");
var metrics = new List<Metric>(this.count * metricStreamConfigs!.Count);

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
var metric = metrics[index];
if (metric != null)
{
cur.Value.CompleteSingleStreamMeasurement(metric);
}
var innerMetrics = cur.Value.AddMetricWithViews(instrument, metricStreamConfigs);

index++;
metrics.AddRange(innerMetrics);
}
}

internal void CompleteMeasurements(List<List<Metric>> metricsSuperList)
{
Debug.Assert(metricsSuperList.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers.");

int index = 0;
for (var cur = this.Head; cur != null; cur = cur.Next)
{
if (metricsSuperList[index].Count > 0)
{
cur.Value.CompleteMeasurement(metricsSuperList[index]);
}

index++;
}
return metrics;
}
}
2 changes: 0 additions & 2 deletions src/OpenTelemetry/Metrics/HistogramBuckets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class HistogramBuckets
internal double RunningMax = double.NegativeInfinity;
internal double SnapshotMax;

internal int IsCriticalSectionOccupied = 0;

private readonly BucketLookupNode? bucketLookupTreeRoot;

private readonly Func<double, int> findHistogramBucketIndex;
Expand Down
Loading

0 comments on commit d49c60a

Please sign in to comment.