Beispiel #1
0
        private static void Check(StatsDMessage message, double sampleRate, string expected)
        {
            Formatter.TryFormat(message, sampleRate, Buffer, out int written).ShouldBe(true);
            var result = Encoding.UTF8.GetString(Buffer.AsSpan(0, written));

            result.ShouldBe(expected);
        }
Beispiel #2
0
        public static void MessagesLargerThenAvailableBufferShouldNotBeFormatted()
        {
            var buffer     = new byte[128];
            var hugeBucket = new string('x', 256);
            var message    = StatsDMessage.Gauge(128.5, hugeBucket);

            Formatter.TryFormat(message, 1.0, buffer, out int written).ShouldBe(false);
            written.ShouldBe(0);
        }
Beispiel #3
0
        public static void CounterRegularWithTags()
        {
            var tags = new Dictionary <string, string>
            {
                ["foo"]     = "bar",
                ["another"] = "tag"
            };
            var message = StatsDMessage.Counter(128, "bucket", tags);

            Check(message, "prefix.bucket;foo=bar;another=tag:128|c");
        }
Beispiel #4
0
        public static void GaugeIncrementWithTags()
        {
            var tags = new Dictionary <string, string>
            {
                ["foo"]     = "bar",
                ["another"] = "tag"
            };

            var message = StatsDMessage.Gauge(128, "bucket", tags, Operation.Increment);

            Check(message, "prefix.bucket;foo=bar;another=tag:+128|g");
        }
Beispiel #5
0
        public static void GetMaxBufferSizeCalculatesValidBufferSizes(int bucketSize, char ch)
        {
            var hugeBucket = new string(ch, bucketSize);
            var message    = StatsDMessage.Gauge(128.5, hugeBucket);
            var expected   = $"prefix.{hugeBucket}:128.5|g";

            var buffer = new byte[Formatter.GetMaxBufferSize(message)];

            Formatter.TryFormat(message, 1.0, buffer, out int written).ShouldBe(true);
            var actual = Encoding.UTF8.GetString(buffer.AsSpan(0, written));

            actual.ShouldBe(expected);
        }
Beispiel #6
0
        public void BufferBased()
        {
            Dictionary <string, string> tags = new Dictionary <string, string>();

            tags.Add("key", " value");
            tags.Add("key2", " value2");

            FormatterBuffer.TryFormat(StatsDMessage.Gauge(255, "some.neat.bucket", null), 1, Buffer, out _);
            FormatterBuffer.TryFormat(StatsDMessage.Timing(255, "some.neat.bucket", null), 1, Buffer, out _);
            FormatterBuffer.TryFormat(StatsDMessage.Counter(255, "some.neat.bucket", null), 1, Buffer, out _);
            FormatterBuffer.TryFormat(StatsDMessage.Gauge(255, "some.neat.bucket", tags), 1, Buffer, out _);
            FormatterBuffer.TryFormat(StatsDMessage.Timing(255, "some.neat.bucket", tags), 1, Buffer, out _);
            FormatterBuffer.TryFormat(StatsDMessage.Counter(255, "some.neat.bucket", tags), 1, Buffer, out _);
        }
Beispiel #7
0
 public void BufferBased()
 {
     FormatterBuffer.TryFormat(StatsDMessage.Gauge(255, "some.neat.bucket"), 1, Buffer, out _);
     FormatterBuffer.TryFormat(StatsDMessage.Timing(255, "some.neat.bucket"), 1, Buffer, out _);
     FormatterBuffer.TryFormat(StatsDMessage.Counter(255, "some.neat.bucket"), 1, Buffer, out _);
 }
Beispiel #8
0
        public static void GaugeFloat()
        {
            var message = StatsDMessage.Gauge(128.5, "bucket");

            Check(message, "prefix.bucket:128.5|g");
        }
Beispiel #9
0
        public static void GaugeIntegral()
        {
            var message = StatsDMessage.Gauge(128, "bucket");

            Check(message, "prefix.bucket:128|g");
        }
Beispiel #10
0
        public static void TimingSampled()
        {
            var message = StatsDMessage.Timing(128, "bucket");

            Check(message, 0.5, "prefix.bucket:128|ms|@0.5");
        }
Beispiel #11
0
        public static void Timing()
        {
            var message = StatsDMessage.Timing(128, "bucket");

            Check(message, "prefix.bucket:128|ms");
        }
Beispiel #12
0
        public static void CounterNegative()
        {
            var message = StatsDMessage.Counter(-128, "bucket");

            Check(message, "prefix.bucket:-128|c");
        }
Beispiel #13
0
        public static void CounterRegular()
        {
            var message = StatsDMessage.Counter(128, "bucket");

            Check(message, "prefix.bucket:128|c");
        }
Beispiel #14
0
        public static void CounterSampled()
        {
            var message = StatsDMessage.Counter(128, "bucket");

            Check(message, 0.5, "prefix.bucket:128|c|@0.5");
        }
Beispiel #15
0
 private static void Check(StatsDMessage message, string expected)
 {
     Check(message, 1, expected);
 }
Beispiel #16
0
        public static void GaugeIncrement()
        {
            var message = StatsDMessage.Gauge(128, "bucket", null, Operation.Increment);

            Check(message, "prefix.bucket:+128|g");
        }