Do not export metrics description if it is empty (#2583)
This commit is contained in:
parent
9ad2cfbec9
commit
f0311751d5
|
|
@ -29,7 +29,7 @@ namespace Examples.Console
|
|||
{
|
||||
private static readonly Meter MyMeter = new Meter("TestMeter");
|
||||
private static readonly Counter<double> Counter = MyMeter.CreateCounter<double>("myCounter", description: "A counter for demonstration purpose.");
|
||||
private static readonly Histogram<long> MyHistogram = MyMeter.CreateHistogram<long>("myHistogram", description: "A histogram for demonstration purpose.");
|
||||
private static readonly Histogram<long> MyHistogram = MyMeter.CreateHistogram<long>("myHistogram");
|
||||
private static readonly ThreadLocal<Random> ThreadLocalRandom = new ThreadLocal<Random>(() => new Random());
|
||||
|
||||
internal static object Run(int port, int totalDurationInMins)
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
try
|
||||
{
|
||||
ctx.Response.StatusCode = 200;
|
||||
ctx.Response.ContentType = PrometheusMetricsFormatHelper.ContentType;
|
||||
ctx.Response.Headers.Add("Server", string.Empty);
|
||||
ctx.Response.ContentType = "text/plain; charset=utf-8; version=0.0.4";
|
||||
|
||||
this.exporter.OnExport = (metrics) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
internal static async Task WriteMetricsToResponse(byte[] buffer, int count, HttpResponse response)
|
||||
{
|
||||
response.StatusCode = 200;
|
||||
response.ContentType = PrometheusMetricsFormatHelper.ContentType;
|
||||
response.ContentType = "text/plain; charset=utf-8; version=0.0.4";
|
||||
|
||||
await response.Body.WriteAsync(buffer, 0, count).ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
{
|
||||
internal static class PrometheusMetricsFormatHelper
|
||||
{
|
||||
public const string ContentType = "text/plain; version = 0.0.4";
|
||||
|
||||
#if NETCOREAPP3_1_OR_GREATER
|
||||
private static readonly SpanAction<char, (string, Func<char, bool, bool>)> CreateName
|
||||
= (Span<char> data, (string name, Func<char, bool, bool> isCharacterAllowedFunc) state) =>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
|
||||
public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
|
||||
{
|
||||
if (metric.Description != null)
|
||||
if (!string.IsNullOrWhiteSpace(metric.Description))
|
||||
{
|
||||
cursor = WriteHelpText(buffer, cursor, metric.Name, metric.Unit, metric.Description);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,17 +107,13 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
|
||||
string[] lines = content.Split('\n');
|
||||
|
||||
Assert.Equal(
|
||||
$"# HELP counter_double",
|
||||
lines[0]);
|
||||
|
||||
Assert.Equal(
|
||||
$"# TYPE counter_double counter",
|
||||
lines[1]);
|
||||
lines[0]);
|
||||
|
||||
Assert.Contains(
|
||||
$"counter_double{{key1=\"value1\",key2=\"value2\"}} 101.17",
|
||||
lines[2]);
|
||||
lines[1]);
|
||||
|
||||
var index = content.LastIndexOf(' ');
|
||||
|
||||
|
|
|
|||
|
|
@ -68,17 +68,13 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
|
||||
string[] lines = content.Split('\n');
|
||||
|
||||
Assert.Equal(
|
||||
$"# HELP counter_double",
|
||||
lines[0]);
|
||||
|
||||
Assert.Equal(
|
||||
$"# TYPE counter_double counter",
|
||||
lines[1]);
|
||||
lines[0]);
|
||||
|
||||
Assert.Contains(
|
||||
$"counter_double{{key1=\"value1\",key2=\"value2\"}} 101.17",
|
||||
lines[2]);
|
||||
lines[1]);
|
||||
|
||||
var index = content.LastIndexOf(' ');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue