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

when formatting timing use miliseconds instead of ticks #112

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
65 changes: 65 additions & 0 deletions src/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Text;
using JustEat.StatsD.Buffered;
using Shouldly;
using Xunit;

namespace JustEat.StatsD
{
public class BufferBasedStatsDPublisherTests
{
private readonly FakeTransport _transport = new FakeTransport();
private readonly StatsDConfiguration _configuration = new StatsDConfiguration { Prefix = "test" };
private readonly BufferBasedStatsDPublisher _sut;

public BufferBasedStatsDPublisherTests()
{
_sut = new BufferBasedStatsDPublisher(_configuration, _transport);
}

[Fact]
public void TestTiming_TimeSpan()
{
_sut.Timing(TimeSpan.FromSeconds(1.234), "timing");
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms");
}

[Fact]
public void TestTimingSampled_TimeSpan()
{
for (int i = 0; _transport.Messages.Count == 0 && i < 10000; i++)
{
_sut.Timing(TimeSpan.FromSeconds(1.234), 0.99, "timing");
}
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms|@0.99");
}

[Fact]
public void TestTiming_Long()
{
_sut.Timing(1234, "timing");
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms");
}

[Fact]
public void TestTimingSampled_Long()
{
for (int i = 0; _transport.Messages.Count == 0 && i < 10000; i++)
{
_sut.Timing(1234, 0.99, "timing");
}
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms|@0.99");
}

private class FakeTransport : IStatsDBufferedTransport
{
public List<string> Messages { get; } = new List<string>();

public void Send(in ArraySegment<byte> metric)
{
Messages.Add(Encoding.UTF8.GetString(metric.Array, metric.Offset, metric.Count));
}
}
}
}
4 changes: 2 additions & 2 deletions src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ public void Gauge(long value, string bucket, DateTime timestamp)

public void Timing(TimeSpan duration, string bucket)
{
Timing(duration.Ticks, bucket);
Timing((long)duration.TotalMilliseconds, bucket);
}

public void Timing(TimeSpan duration, double sampleRate, string bucket)
{
Timing(duration.Ticks, sampleRate, bucket);
Timing((long)duration.TotalMilliseconds, sampleRate, bucket);
}

public void Timing(long duration, string bucket)
Expand Down