Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7cac55d
[Prometheus.HttpListener] Improve performance
martincostello Apr 25, 2026
bdb4112
[Prometheus.HttpListener] Fix tests
martincostello Apr 25, 2026
358e2f3
[Prometheus.HttpListener] Fix test
martincostello Apr 25, 2026
4aecfea
[Prometheus.HttpListener] Address feedback
martincostello Apr 25, 2026
53d6284
[Exporter.Prometheus] Further perf improvements
martincostello Apr 26, 2026
8609727
[Exporter.Prometheus] Extend coverage
martincostello Apr 26, 2026
27a1d2e
[Exporter.Prometheus] Fix lint warnings
martincostello Apr 26, 2026
65d6b25
[Exporter.Prometheus] Extend coverage
martincostello Apr 26, 2026
fb2545d
[Exporter.Prometheus] Extend coverage
martincostello Apr 26, 2026
93d6a8a
Merge branch 'main' into PrometheusSerializer-perf
martincostello Apr 27, 2026
d6db630
[Exporter.Prometheus] Remove parameters
martincostello Apr 27, 2026
4e86902
Merge branch 'main' into PrometheusSerializer-perf
martincostello Apr 27, 2026
b0c53f1
[Exporter.Prometheus] Reduce duplication
martincostello Apr 27, 2026
21b3a09
[Exporter.Prometheus] Fix-up merge
martincostello Apr 27, 2026
140da7a
[Exporter.Prometheus] Fix tests
martincostello Apr 27, 2026
2445d2a
[Exporter.Prometheus] Reduce duplication
martincostello Apr 27, 2026
fbbbc06
[Exporter.Prometheus] Refactoring
martincostello Apr 27, 2026
c1124f4
Merge branch 'main' into PrometheusSerializer-perf
martincostello Apr 28, 2026
5fe7480
[Exporter.Prometheus] Polyfill char methods
martincostello Apr 28, 2026
29784ae
[Exporter.Prometheus] Address feedback
martincostello Apr 28, 2026
b46cb19
[Exporter.Prometheus] Update comments
martincostello Apr 28, 2026
74e5259
Merge branch 'main' into PrometheusSerializer-perf
martincostello May 1, 2026
c24c7ed
[Exporter.Prometheus] Simplify test
martincostello May 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@
</ItemGroup>

</Project>

Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ private ExportResult OnCollect(in Batch<Metric> metrics)

break;
}
catch (IndexOutOfRangeException)
catch (Exception ex) when (ex is IndexOutOfRangeException or ArgumentException)
{
Comment thread
martincostello marked this conversation as resolved.
if (!IncreaseBufferSize(ref buffer))
{
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want
// to put some upper limit and allow the user to configure it.
// 2. we got an IndexOutOfRangeException which was triggered by some other
// 2. we got an ArgumentException/IndexOutOfRangeException which was triggered by some other
// code instead of the buffer[cursor++] - in this case we should give up
// at certain point rather than allocating like crazy.
throw;
Expand Down Expand Up @@ -280,7 +280,7 @@ private ExportResult OnCollect(in Batch<Metric> metrics)

break;
}
catch (IndexOutOfRangeException)
catch (Exception ex) when (ex is IndexOutOfRangeException or ArgumentException)
{
if (!IncreaseBufferSize(ref buffer))
{
Expand All @@ -297,7 +297,7 @@ private ExportResult OnCollect(in Batch<Metric> metrics)
cursor = PrometheusSerializer.WriteEof(buffer, cursor);
break;
}
catch (IndexOutOfRangeException)
catch (Exception ex) when (ex is IndexOutOfRangeException or ArgumentException)
{
if (!IncreaseBufferSize(ref buffer))
{
Expand Down Expand Up @@ -346,7 +346,7 @@ private int WriteTargetInfo(ref byte[] buffer)

break;
}
catch (IndexOutOfRangeException)
catch (Exception ex) when (ex is IndexOutOfRangeException or ArgumentException)
{
if (!IncreaseBufferSize(ref buffer))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public PrometheusMetric(string name, string unit, PrometheusType type, bool disa
this.OpenMetricsMetadataName = openMetricsMetadataName;
this.Unit = sanitizedUnit;
this.Type = type;
this.NameBytes = ConvertToAsciiBytes(sanitizedName);
this.OpenMetricsNameBytes = ConvertToAsciiBytes(openMetricsName);
this.OpenMetricsMetadataNameBytes = ConvertToAsciiBytes(openMetricsMetadataName);
this.UnitBytes = sanitizedUnit == null ? null : ConvertToAsciiBytes(sanitizedUnit);

static byte[] ConvertToAsciiBytes(string value)
{
var bytes = new byte[value.Length];

for (var i = 0; i < value.Length; i++)
{
bytes[i] = unchecked((byte)value[i]);
}

return bytes;
}
}

public string Name { get; }
Expand All @@ -74,8 +90,21 @@ public PrometheusMetric(string name, string unit, PrometheusType type, bool disa

public PrometheusType Type { get; }

public static PrometheusMetric Create(Metric metric, bool disableTotalNameSuffixForCounters)
=> new(metric.Name, metric.Unit, GetPrometheusType(metric.MetricType), disableTotalNameSuffixForCounters);
internal byte[] NameBytes { get; }

internal byte[] OpenMetricsNameBytes { get; }

internal byte[] OpenMetricsMetadataNameBytes { get; }

internal byte[]? UnitBytes { get; }

internal byte[]? SerializedStaticTags { get; private set; }

public static PrometheusMetric Create(Metric metric, bool disableTotalNameSuffixForCounters) =>
new(metric.Name, metric.Unit, GetPrometheusType(metric.MetricType), disableTotalNameSuffixForCounters)
{
SerializedStaticTags = PrometheusSerializer.SerializeStaticTags(metric),
};

internal static string SanitizeMetricUnit(string metricUnit)
{
Expand Down
Loading
Loading