Skip to content

Commit

Permalink
[repo/InfluxDB] Prepare to .NET9 (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Oct 29, 2024
1 parent c6d6501 commit f6326f5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private static IMetricsWriter CreateMetricsWriter(MetricsSchema metricsSchema)
return metricsSchema switch
{
MetricsSchema.TelegrafPrometheusV2 => new TelegrafPrometheusWriterV2(),
MetricsSchema.TelegrafPrometheusV1 => new TelegrafPrometheusWriterV1(),
MetricsSchema.None => new TelegrafPrometheusWriterV1(),
_ => new TelegrafPrometheusWriterV1(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public InfluxDBMetricsExporter(IMetricsWriter writer, InfluxDBClient influxDbCli
case WriteErrorEvent writeErrorEvent:
InfluxDBEventSource.Log.FailedToExport(writeErrorEvent.Exception.Message);
break;
default:
break;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi)
.Tags(resource?.Attributes)
.Timestamp(dataPoint.EndTime.UtcDateTime, WritePrecision.Ns);

if (dataPoint.TryGetHistogramMinMaxValues(out double min, out double max))
if (dataPoint.TryGetHistogramMinMaxValues(out var min, out var max))
{
pointData = pointData.Field("min", min)
.Field("max", max);
Expand All @@ -142,6 +142,10 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi)
writeApi.WritePoint(pointData);
}

break;
case MetricType.ExponentialHistogram:
break;
default:
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi)
.Field($"{metricName}_count", metricPoint.GetHistogramCount())
.Field($"{metricName}_sum", metricPoint.GetHistogramSum());

if (metricPoint.TryGetHistogramMinMaxValues(out double min, out double max))
if (metricPoint.TryGetHistogramMinMaxValues(out var min, out var max))
{
headPoint = headPoint
.Field($"{metricName}_min", min)
Expand All @@ -149,6 +149,10 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi)
}
}

break;
case MetricType.ExponentialHistogram:
break;
default:
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ namespace OpenTelemetry.Exporter.InfluxDB.Tests;
public class InfluxDBMetricsExporterTests
{
private static readonly string OpenTelemetrySdkVersion;
private static readonly double[] TestBoundaries = new[] { 10D, 20D, 100D, 200D };
private static readonly double[] TestBoundaries = [10D, 20D, 100D, 200D];

#pragma warning disable CA1810 // Initialize reference type static fields inline
static InfluxDBMetricsExporterTests()
#pragma warning restore CA1810 // Initialize reference type static fields inline
{
var sdkVersion = typeof(Sdk).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
if (sdkVersion != null)
{
OpenTelemetrySdkVersion = Version.Parse(sdkVersion).ToString(3);
}
else
{
OpenTelemetrySdkVersion = "0.0.0";
}
OpenTelemetrySdkVersion = sdkVersion != null ? Version.Parse(sdkVersion).ToString(3) : "0.0.0";
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public static class AssertUtils
internal static class AssertUtils
{
public static void HasField<TKey, TValue>(TKey expectedKey, TValue expectedValue, IReadOnlyDictionary<TKey, object> collection)
where TKey : notnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public class InfluxDBFakeServer : IDisposable
internal class InfluxDBFakeServer : IDisposable
{
private static readonly char[] SplitChars = Environment.NewLine.ToCharArray();
private readonly IDisposable httpServer;
private readonly BlockingCollection<string> lines;

public InfluxDBFakeServer()
{
this.lines = new BlockingCollection<string>();
this.lines = [];
this.httpServer = TestHttpServer.RunServer(
context =>
{
byte[] buffer = new byte[context.Request.ContentLength64];
var buffer = new byte[context.Request.ContentLength64];
_ = context.Request.InputStream.Read(buffer, 0, buffer.Length);
string text = Encoding.UTF8.GetString(buffer);
var text = Encoding.UTF8.GetString(buffer);
foreach (var line in text.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries))
{
this.lines.Add(line);
Expand All @@ -45,11 +45,9 @@ public void Dispose()

public PointData ReadPoint()
{
if (this.lines.TryTake(out var line, TimeSpan.FromSeconds(5)))
{
return LineProtocolParser.ParseLine(line);
}

throw new InvalidOperationException("Failed to read a data point from the InfluxDB server within the 5-second timeout.");
return this.lines.TryTake(out var line, TimeSpan.FromSeconds(5))
? LineProtocolParser.ParseLine(line)
: throw new InvalidOperationException(
"Failed to read a data point from the InfluxDB server within the 5-second timeout.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public static class InfluxDBMetricsExporterOptionsTestExtensions
internal static class InfluxDBMetricsExporterOptionsTestExtensions
{
public static void WithDefaultTestConfiguration(this InfluxDBMetricsExporterOptions options)
{
options.Bucket = "MyBucket";
options.Org = "MyOrg";
options.Token = "MyToken";

// For tests we want to flush the metrics ASAP
// For tests, we want to flush the metrics ASAP
options.FlushInterval = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public class LineProtocolParser
internal class LineProtocolParser
{
private static readonly DateTime UnixEpoch = DateTime.SpecifyKind(new DateTime(1970, 1, 1), DateTimeKind.Utc);

Expand Down Expand Up @@ -57,35 +57,32 @@ private static List<KeyValuePair<string, string>> ParseTags(IEnumerable<string>

private static object ParseFieldValue(string fieldValue)
{
if (bool.TryParse(fieldValue, out bool boolValue))
if (bool.TryParse(fieldValue, out var boolValue))
{
return boolValue;
}

#pragma warning disable CA1865 // Use char overload
if (fieldValue.EndsWith("i", StringComparison.Ordinal)
&& long.TryParse(fieldValue.AsSpan(0, fieldValue.Length - 1).ToString(), out long intValue))
&& long.TryParse(fieldValue.AsSpan(0, fieldValue.Length - 1).ToString(), out var intValue))
{
return intValue;
}
#pragma warning restore CA1865 // Use char overload

if (double.TryParse(fieldValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double doubleValue))
{
return doubleValue;
}

return fieldValue;
return double.TryParse(fieldValue, NumberStyles.Float, CultureInfo.InvariantCulture, out var doubleValue)
? doubleValue
: fieldValue;
}

private static DateTime ParseTimestamp(string? timestampSection)
{
if (string.IsNullOrEmpty(timestampSection) || !long.TryParse(timestampSection, out long unixTimeNanoseconds))
if (string.IsNullOrEmpty(timestampSection) || !long.TryParse(timestampSection, out var unixTimeNanoseconds))
{
throw new ArgumentException("Invalid formatted timestamp.");
}

long ticks = unixTimeNanoseconds / 100;
var ticks = unixTimeNanoseconds / 100;
return UnixEpoch.AddTicks(ticks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public static class MeterProviderBuilderTestExtensions
internal static class MeterProviderBuilderTestExtensions
{
public static MeterProviderBuilder ConfigureDefaultTestResource(this MeterProviderBuilder meterProviderBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils;

public class PointData
internal class PointData
{
public string Measurement { get; init; } = null!;

Expand Down

0 comments on commit f6326f5

Please sign in to comment.