Ejemplo n.º 1
0
        public void it_contains_the_stat_name()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);

            metrics.Gauge("mystat", 1);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains("|mystat|"),
                        $@"Expected the given stat name: ""|mystat|"" but couldn't find it in <{logs.First()}>");
        }
Ejemplo n.º 2
0
        public void adding_a_tag_appends_it_with_a_hash()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);
            var colour  = new StatTag("colour", "blue");

            metrics.Gauge("mystat", 1, 1D, colour);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains("|#colour:blue"),
                        $@"Expected the tag string: ""|#colour:blue"" but couldn't find it in <{logs.First()}>");
        }
Ejemplo n.º 3
0
        public void sample_rate_of_0_never_sends_it()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            Repeat(100, () =>
            {
                var metrics = new DogMetrics(contextMock.Object);
                metrics.Gauge("mystat", 1, 0D);
            });

            Assert.True(logs.Count == 0,
                        $"Expected no lines to come through but had {logs.Count}");
        }
Ejemplo n.º 4
0
        public void sample_rate_of_1_always_sends_it()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            Repeat(100, () =>
            {
                var metrics = new DogMetrics(contextMock.Object);
                metrics.Gauge("mystat", 1, 1D); //don't usually need to specify 1D
            });

            Assert.True(logs.Count == 100,
                        $"Expected all lines to come through but only had {logs.Count}");
        }
Ejemplo n.º 5
0
        public void a_tag_need_not_have_value()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics  = new DogMetrics(contextMock.Object);
            var isBlue   = new StatTag("isBlue");
            var isCircle = new StatTag("isCircle");

            metrics.Gauge("mystat", 1, 1D, isBlue, isCircle);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains("|#isBlue,isCircle"),
                        $@"Expected the tag string: ""|#isBlue,isCircle"" but couldn't find it in <{logs.First()}>");
        }
Ejemplo n.º 6
0
        public void multiple_tags_are_separated_by_comma()
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);
            var colour  = new StatTag("colour", "blue");
            var shape   = new StatTag("shape", "circle");

            metrics.Gauge("mystat", 1, 1D, colour, shape);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains("|#colour:blue,shape:circle"),
                        $@"Expected the tag string: ""|#colour:blue,shape:circle"" but couldn't find it in <{logs.First()}>");
        }
Ejemplo n.º 7
0
        public void with_no_tags_it_still_includes_the_hash()
        {
            // I need to check if this is 'ok' by the integration
            // but for now just documenting the behaviour

            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);

            metrics.Gauge("mystat", 1);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains("|#"),
                        $@"Expected the tag string: ""|#"" but couldn't find it in <{logs.First()}>");
        }
Ejemplo n.º 8
0
        public void a_sample_rate_of_0_point_5_sends_it_roughly_half_the_time()
        {
            // You probably shouldn't use this for .Counter or .Check though
            // since there is no way to tell datadog it is sampled...

            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            Repeat(100, () =>
            {
                var metrics = new DogMetrics(contextMock.Object);
                metrics.Gauge("mystat", 1, 0.5D);
            });

            Assert.InRange(logs.Count, 40, 60);
        }
Ejemplo n.º 9
0
        public void it_contains_the_current_unix_timestamp()
        {
            // Could this test fail when run on exactly the border of a second?

            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);

            metrics.Gauge("mystat", 1);

            var currentUnixTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains($"|{currentUnixTime}|"),
                        $@"Expected the current unix timestamp: ""|{currentUnixTime}|"" but couldn't find it in <{logs.First()}>");
        }