From 76e0b8abe62e39979fe37e4ec5982928cd7e16b8 Mon Sep 17 00:00:00 2001 From: Vadim Chekan Date: Wed, 15 Jul 2015 15:06:47 -0700 Subject: [PATCH 1/3] Make metrics low-case by default --- Src/Metrics/Graphite/GraphiteExtensions.cs | 20 ++++++++++---------- Src/Metrics/Graphite/PickleGraphiteSender.cs | 6 +++++- Src/Metrics/Graphite/TcpGraphiteSender.cs | 7 ++++++- Src/Metrics/Graphite/UdpGraphiteSender.cs | 7 ++++++- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Src/Metrics/Graphite/GraphiteExtensions.cs b/Src/Metrics/Graphite/GraphiteExtensions.cs index f52d4689..74790bae 100644 --- a/Src/Metrics/Graphite/GraphiteExtensions.cs +++ b/Src/Metrics/Graphite/GraphiteExtensions.cs @@ -6,39 +6,39 @@ namespace Metrics { public static class GraphiteExtensions { - public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval) + public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval, bool keysToLowercase = true) { if (graphiteUri.Scheme.ToLowerInvariant() == "net.tcp") { - return reports.WithTCPGraphite(graphiteUri.Host, graphiteUri.Port, interval); + return reports.WithTCPGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase); } if (graphiteUri.Scheme.ToLowerInvariant() == "net.udp") { - return reports.WithUDPGraphite(graphiteUri.Host, graphiteUri.Port, interval); + return reports.WithUDPGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase); } if (graphiteUri.Scheme.ToLowerInvariant() == "net.pickled") { - return reports.WithPickledGraphite(graphiteUri.Host, graphiteUri.Port, interval); + return reports.WithPickledGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase: keysToLowercase); } throw new ArgumentException("Graphite uri scheme must be either net.tcp or net.udp or net.pickled (ex: net.udp://graphite.myhost.com:2003 )", "graphiteUri"); } - public static MetricsReports WithPickledGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, int batchSize = PickleGraphiteSender.DefaultPickleJarSize) + public static MetricsReports WithPickledGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, int batchSize = PickleGraphiteSender.DefaultPickleJarSize, bool keysToLowercase = false) { - return reports.WithGraphite(new PickleGraphiteSender(host, port, batchSize), interval); + return reports.WithGraphite(new PickleGraphiteSender(host, port, batchSize, keysToLowercase), interval); } - public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval) + public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = true) { - return reports.WithGraphite(new TcpGraphiteSender(host, port), interval); + return reports.WithGraphite(new TcpGraphiteSender(host, port, keysToLowercase), interval); } - public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval) + public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = true) { - return reports.WithGraphite(new UdpGraphiteSender(host, port), interval); + return reports.WithGraphite(new UdpGraphiteSender(host, port, keysToLowercase), interval); } public static MetricsReports WithGraphite(this MetricsReports reports, GraphiteSender graphiteLink, TimeSpan interval) diff --git a/Src/Metrics/Graphite/PickleGraphiteSender.cs b/Src/Metrics/Graphite/PickleGraphiteSender.cs index b101208b..55e9f488 100644 --- a/Src/Metrics/Graphite/PickleGraphiteSender.cs +++ b/Src/Metrics/Graphite/PickleGraphiteSender.cs @@ -16,20 +16,24 @@ public sealed class PickleGraphiteSender : GraphiteSender private readonly int port; private readonly int pickleJarSize; + private readonly bool _keysToLowercase; private TcpClient client; private PickleJar jar = new PickleJar(); - public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize) + public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize, bool keysToLowercase = true) { this.host = host; this.port = port; this.pickleJarSize = batchSize; + _keysToLowercase = keysToLowercase; } public override void Send(string name, string value, string timestamp) { + if (_keysToLowercase) + name = name.ToLower(); this.jar.Append(name, value, timestamp); if (jar.Size >= this.pickleJarSize) diff --git a/Src/Metrics/Graphite/TcpGraphiteSender.cs b/Src/Metrics/Graphite/TcpGraphiteSender.cs index 47f91b0b..4956c3a2 100644 --- a/Src/Metrics/Graphite/TcpGraphiteSender.cs +++ b/Src/Metrics/Graphite/TcpGraphiteSender.cs @@ -13,13 +13,15 @@ public sealed class TcpGraphiteSender : GraphiteSender private readonly string host; private readonly int port; + private readonly bool _keysToLowercase; private TcpClient client; - public TcpGraphiteSender(string host, int port) + public TcpGraphiteSender(string host, int port, bool keysToLowercase) { this.host = host; this.port = port; + _keysToLowercase = keysToLowercase; } protected override void SendData(string data) @@ -31,6 +33,9 @@ protected override void SendData(string data) this.client = InitClient(this.host, this.port); } + if (_keysToLowercase) + data = data.ToLower(); + var bytes = Encoding.UTF8.GetBytes(data); this.client.GetStream().Write(bytes, 0, bytes.Length); diff --git a/Src/Metrics/Graphite/UdpGraphiteSender.cs b/Src/Metrics/Graphite/UdpGraphiteSender.cs index 22cf8998..81340f67 100644 --- a/Src/Metrics/Graphite/UdpGraphiteSender.cs +++ b/Src/Metrics/Graphite/UdpGraphiteSender.cs @@ -13,13 +13,15 @@ public sealed class UdpGraphiteSender : GraphiteSender private readonly string host; private readonly int port; + private readonly bool _keysToLowercase; private UdpClient client; - public UdpGraphiteSender(string host, int port) + public UdpGraphiteSender(string host, int port, bool keysToLowercase) { this.host = host; this.port = port; + _keysToLowercase = keysToLowercase; } protected override void SendData(string data) @@ -31,6 +33,9 @@ protected override void SendData(string data) this.client = InitClient(this.host, this.port); } + if (_keysToLowercase) + data = data.ToLower(); + var bytes = Encoding.UTF8.GetBytes(data); this.client.Send(bytes, bytes.Length); } From 2597f1accf27d613a7d47c3b06fff629bade4966 Mon Sep 17 00:00:00 2001 From: Vadim Chekan Date: Thu, 17 Sep 2015 11:30:31 -0700 Subject: [PATCH 2/3] Make default metrics case backward-compatible (do not force lower case). --- Src/Metrics/Graphite/GraphiteExtensions.cs | 6 +++--- Src/Metrics/Graphite/PickleGraphiteSender.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Metrics/Graphite/GraphiteExtensions.cs b/Src/Metrics/Graphite/GraphiteExtensions.cs index 74790bae..da630b4d 100644 --- a/Src/Metrics/Graphite/GraphiteExtensions.cs +++ b/Src/Metrics/Graphite/GraphiteExtensions.cs @@ -6,7 +6,7 @@ namespace Metrics { public static class GraphiteExtensions { - public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval, bool keysToLowercase = true) + public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval, bool keysToLowercase = false) { if (graphiteUri.Scheme.ToLowerInvariant() == "net.tcp") { @@ -31,12 +31,12 @@ public static MetricsReports WithPickledGraphite(this MetricsReports reports, st return reports.WithGraphite(new PickleGraphiteSender(host, port, batchSize, keysToLowercase), interval); } - public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = true) + public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = false) { return reports.WithGraphite(new TcpGraphiteSender(host, port, keysToLowercase), interval); } - public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = true) + public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = false) { return reports.WithGraphite(new UdpGraphiteSender(host, port, keysToLowercase), interval); } diff --git a/Src/Metrics/Graphite/PickleGraphiteSender.cs b/Src/Metrics/Graphite/PickleGraphiteSender.cs index 55e9f488..d8a6b42b 100644 --- a/Src/Metrics/Graphite/PickleGraphiteSender.cs +++ b/Src/Metrics/Graphite/PickleGraphiteSender.cs @@ -22,7 +22,7 @@ public sealed class PickleGraphiteSender : GraphiteSender private PickleJar jar = new PickleJar(); - public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize, bool keysToLowercase = true) + public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize, bool keysToLowercase = false) { this.host = host; this.port = port; From dae9ce5d026f7f0058f7c5cbadaf0135217f1465 Mon Sep 17 00:00:00 2001 From: Vadim Chekan Date: Mon, 28 Sep 2015 14:33:47 -0700 Subject: [PATCH 3/3] Ntent-specific package names. Removed pre-release marker, because it makes any project using it pre-release too. --- Publishing/Metrics.NET.nuspec | 4 ++-- Publishing/Nancy.Metrics.nuspec | 6 +++--- Publishing/Owin.Metrics.nuspec | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Publishing/Metrics.NET.nuspec b/Publishing/Metrics.NET.nuspec index 6dac4aad..1a0e9a55 100644 --- a/Publishing/Metrics.NET.nuspec +++ b/Publishing/Metrics.NET.nuspec @@ -1,8 +1,8 @@  - Metrics.NET - 0.3.3-pre + 0.3.3 + Metrics.NET_ntent Metrics.NET iulian.margarintescu Iulian Margarintescu diff --git a/Publishing/Nancy.Metrics.nuspec b/Publishing/Nancy.Metrics.nuspec index 1a093092..a13af3fd 100644 --- a/Publishing/Nancy.Metrics.nuspec +++ b/Publishing/Nancy.Metrics.nuspec @@ -1,8 +1,8 @@  - Nancy.Metrics - 0.3.3-pre + 0.3.3 + Nancy.Metrics_ntent Nancy.Metrics iulian.margarintescu Iulian Margarintescu @@ -15,7 +15,7 @@ http://www.erata.net/Metrics.NET/metrics_32.png nancy, nancyfx, metrics, measurements, charts, timer, histogram, duration, graphite, health checks - + diff --git a/Publishing/Owin.Metrics.nuspec b/Publishing/Owin.Metrics.nuspec index d29f86cb..4dc296c6 100644 --- a/Publishing/Owin.Metrics.nuspec +++ b/Publishing/Owin.Metrics.nuspec @@ -1,8 +1,8 @@ - Owin.Metrics - 0.3.3-pre + 0.3.3 + Owin.Metrics_ntent Owin.Metrics Allan Hardy Iulian Margarintescu @@ -15,7 +15,7 @@ http://www.erata.net/Metrics.NET/metrics_32.png webapi, owin, metrics, measurements, charts, timer, histogram, duration, graphite, health checks - +