diff --git a/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBExporterExtensions.cs b/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBExporterExtensions.cs index 6628e761bf..88e917cf90 100644 --- a/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBExporterExtensions.cs @@ -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(), }; } diff --git a/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBMetricsExporter.cs b/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBMetricsExporter.cs index 651d360162..4c5d7a45be 100644 --- a/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBMetricsExporter.cs +++ b/src/OpenTelemetry.Exporter.InfluxDB/InfluxDBMetricsExporter.cs @@ -26,6 +26,8 @@ public InfluxDBMetricsExporter(IMetricsWriter writer, InfluxDBClient influxDbCli case WriteErrorEvent writeErrorEvent: InfluxDBEventSource.Log.FailedToExport(writeErrorEvent.Exception.Message); break; + default: + break; } }; } diff --git a/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV1.cs b/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV1.cs index 078e64916e..555e6e8873 100644 --- a/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV1.cs +++ b/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV1.cs @@ -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); @@ -142,6 +142,10 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi) writeApi.WritePoint(pointData); } + break; + case MetricType.ExponentialHistogram: + break; + default: break; } } diff --git a/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV2.cs b/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV2.cs index df2a25e0fa..d0eda952d4 100644 --- a/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV2.cs +++ b/src/OpenTelemetry.Exporter.InfluxDB/TelegrafPrometheusWriterV2.cs @@ -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) @@ -149,6 +149,10 @@ public void Write(Metric metric, Resource? resource, WriteApi writeApi) } } + break; + case MetricType.ExponentialHistogram: + break; + default: break; } } diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs index 5528c0bb32..f9105672cf 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs @@ -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()?.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] diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/AssertUtils.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/AssertUtils.cs index 3c8d12c4ca..9d7c81b2b3 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/AssertUtils.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/AssertUtils.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils; -public static class AssertUtils +internal static class AssertUtils { public static void HasField(TKey expectedKey, TValue expectedValue, IReadOnlyDictionary collection) where TKey : notnull diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBFakeServer.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBFakeServer.cs index 595b733949..e332000c42 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBFakeServer.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBFakeServer.cs @@ -8,7 +8,7 @@ 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; @@ -16,13 +16,13 @@ public class InfluxDBFakeServer : IDisposable public InfluxDBFakeServer() { - this.lines = new BlockingCollection(); + 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); @@ -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."); } } diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBMetricsExporterOptionsTestExtensions.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBMetricsExporterOptionsTestExtensions.cs index c3d84543eb..93b682d07b 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBMetricsExporterOptionsTestExtensions.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/InfluxDBMetricsExporterOptionsTestExtensions.cs @@ -3,7 +3,7 @@ namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils; -public static class InfluxDBMetricsExporterOptionsTestExtensions +internal static class InfluxDBMetricsExporterOptionsTestExtensions { public static void WithDefaultTestConfiguration(this InfluxDBMetricsExporterOptions options) { @@ -11,7 +11,7 @@ public static void WithDefaultTestConfiguration(this InfluxDBMetricsExporterOpti 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; } } diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs index 4116cd9d6d..8ee5b7aa2d 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs @@ -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); @@ -57,35 +57,32 @@ private static List> ParseTags(IEnumerable 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); } } diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/MeterProviderBuilderTestExtensions.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/MeterProviderBuilderTestExtensions.cs index 1df7fa1bc8..ddfa310485 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/MeterProviderBuilderTestExtensions.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/MeterProviderBuilderTestExtensions.cs @@ -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) { diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/PointData.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/PointData.cs index 9c159e0c9e..4d2c66ceea 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/PointData.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/PointData.cs @@ -3,7 +3,7 @@ namespace OpenTelemetry.Exporter.InfluxDB.Tests.Utils; -public class PointData +internal class PointData { public string Measurement { get; init; } = null!;