Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GraphiteDB tags formatter #818

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/JustEat.StatsD/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static JustEat.StatsD.TagsFormatter.GraphiteDb.get -> JustEat.StatsD.TagsFormatters.IStatsDTagsFormatter!
5 changes: 5 additions & 0 deletions src/JustEat.StatsD/TagsFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static class TagsFormatter
/// </summary>
public static IStatsDTagsFormatter DataDog => new TrailingTagsFormatter();

/// <summary>
/// Gets a GraphiteDB tags formatter.
/// </summary>
public static IStatsDTagsFormatter GraphiteDb => new GraphiteDbTagsFormatter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This highlights that we should have probably made these singletons via { get; } = ... rather than creating a new instance on every access.

I'll fix that in a separate PR after this is merged.


/// <summary>
/// Gets an InfluxDB tags formatter.
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions src/JustEat.StatsD/TagsFormatters/GraphiteDbTagsFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace JustEat.StatsD.TagsFormatters;

/// <summary>
/// Formats StatsD tags for GraphiteDB.
/// Tags placed right after the bucket name with format: <code>";" + tag1=value1;tag2;tag3=value</code>.
/// </summary>
internal sealed class GraphiteDbTagsFormatter : StatsDTagsFormatter
{
private const string Prefix = ";";
private const bool AreTrailingTags = false;
private const string TagsSeparator = ";";
private const string KeyValueSeparator = "=";

/// <summary>
/// Initializes a new instance of the <see cref="GraphiteDbTagsFormatter"/> class.
/// </summary>
public GraphiteDbTagsFormatter()
: base(new StatsDTagsFormatterConfiguration
{
Prefix = Prefix,
Suffix = string.Empty,
AreTrailing = AreTrailingTags,
TagsSeparator = TagsSeparator,
KeyValueSeparator = KeyValueSeparator,
})
{
}
}
18 changes: 18 additions & 0 deletions tests/JustEat.StatsD.Tests/Utf8TagsFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public static class Utf8TagsFormatterTests
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|c|@0.5")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|c|@0.5|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|c|@0.5")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|c|@0.5")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|c|@0.5")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|c|@0.5")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|c|@0.5\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|c|@0.5|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|c|@0.5\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|c|@0.5\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|c|@0.5\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|c|@0.5\n")]
public static void CounterSampled(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -35,11 +37,13 @@ public static void CounterSampled(bool formatterEndWithLineFeedSymbol, TagsForma
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|c|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|c")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|c")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|c")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|c")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|c|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|c\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|c\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|c\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|c\n")]
public static void CounterRegular(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -52,11 +56,13 @@ public static void CounterRegular(bool formatterEndWithLineFeedSymbol, TagsForma
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:-128|c")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:-128|c|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:-128|c")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:-128|c")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:-128|c")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:-128|c")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:-128|c\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:-128|c|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:-128|c\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:-128|c\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:-128|c\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:-128|c\n")]
public static void CounterNegative(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -69,11 +75,13 @@ public static void CounterNegative(bool formatterEndWithLineFeedSymbol, TagsForm
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket:128|c")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket:128|c")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket:128|c\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket:128|c\n")]
public static void CounterWithoutTags(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -86,11 +94,13 @@ public static void CounterWithoutTags(bool formatterEndWithLineFeedSymbol, TagsF
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|ms")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|ms|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|ms")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|ms")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|ms")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|ms")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|ms\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|ms|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|ms\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|ms\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|ms\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|ms\n")]
public static void Timing(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -103,11 +113,13 @@ public static void Timing(bool formatterEndWithLineFeedSymbol, TagsFormatter tag
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|ms|@0.5")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|ms|@0.5|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|ms|@0.5")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|ms|@0.5")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|ms|@0.5")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|ms|@0.5")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|ms|@0.5\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|ms|@0.5|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|ms|@0.5\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|ms|@0.5\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|ms|@0.5\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|ms|@0.5\n")]
public static void TimingSampled(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -120,11 +132,13 @@ public static void TimingSampled(bool formatterEndWithLineFeedSymbol, TagsFormat
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128|g")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128|g|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|g")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|g")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|g")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|g")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128|g\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128|g|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128|g\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128|g\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128|g\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128|g\n")]
public static void GaugeIntegral(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand All @@ -137,11 +151,13 @@ public static void GaugeIntegral(bool formatterEndWithLineFeedSymbol, TagsFormat
[InlineData(false, TagsFormatter.NoOp, "prefix.bucket:128.5|g")]
[InlineData(false, TagsFormatter.Trailing, "prefix.bucket:128.5|g|#foo:bar,empty,lorem:ipsum")]
[InlineData(false, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128.5|g")]
[InlineData(false, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128.5|g")]
[InlineData(false, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128.5|g")]
[InlineData(false, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128.5|g")]
[InlineData(true, TagsFormatter.NoOp, "prefix.bucket:128.5|g\n")]
[InlineData(true, TagsFormatter.Trailing, "prefix.bucket:128.5|g|#foo:bar,empty,lorem:ipsum\n")]
[InlineData(true, TagsFormatter.InfluxDb, "prefix.bucket,foo=bar,empty,lorem=ipsum:128.5|g\n")]
[InlineData(true, TagsFormatter.GraphiteDb, "prefix.bucket;foo=bar;empty;lorem=ipsum:128.5|g\n")]
[InlineData(true, TagsFormatter.Librato, "prefix.bucket#foo=bar,empty,lorem=ipsum:128.5|g\n")]
[InlineData(true, TagsFormatter.SignalFx, "prefix.bucket[foo=bar,empty,lorem=ipsum]:128.5|g\n")]
public static void GaugeFloat(bool formatterEndWithLineFeedSymbol, TagsFormatter tagsFormatter, string expected)
Expand Down Expand Up @@ -303,6 +319,7 @@ private static StatsDUtf8Formatter GetStatsDUtf8Formatter(bool formatterEndWithL
TagsFormatter.NoOp => new NoOpTagsFormatter(),
TagsFormatter.Trailing => JustEat.StatsD.TagsFormatter.CloudWatch,
TagsFormatter.InfluxDb => JustEat.StatsD.TagsFormatter.InfluxDb,
TagsFormatter.GraphiteDb => JustEat.StatsD.TagsFormatter.GraphiteDb,
TagsFormatter.Librato => JustEat.StatsD.TagsFormatter.Librato,
TagsFormatter.SignalFx => JustEat.StatsD.TagsFormatter.SignalFx,
_ => throw new ArgumentOutOfRangeException(nameof(tagsFormatter))
Expand All @@ -321,6 +338,7 @@ public enum TagsFormatter
NoOp,
Trailing,
InfluxDb,
GraphiteDb,
Librato,
SignalFx,
}
Expand Down
2 changes: 1 addition & 1 deletion version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.1.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' ">
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_HEAD_REF)' == '' ">beta.$(GITHUB_RUN_NUMBER)</VersionSuffix>
Expand Down
Loading