public async Task MetricsWithRealAgent()
        {
            var logger        = new TestLogger();
            var payloadSender = new MockPayloadSender();
            var configReader  = new TestAgentConfigurationReader(logger, metricsInterval: "1s");

            using (var agent = new ApmAgent(new AgentComponents(payloadSender: payloadSender, logger: logger, configurationReader: configReader)))
            {
                await Task.Delay(2200);                 //make sure we wait enough to collect 1 set of metrics

                agent.ConfigurationReader.MetricsIntervalInMillisecond.Should().Be(1000);
            }

            payloadSender.Metrics.Should().NotBeEmpty();
            payloadSender.Metrics.First().Samples.Should().NotBeEmpty();
        }
Exemplo n.º 2
0
        public void DistributionShouldBeUniform(double rate)
        {
            const int    total = 1_000_000;
            var          startCheckingAfter = Convert.ToInt32(total * 0.1);    // i.e., after 10%
            const double allowedDiffInRate  = 0.01;

            var sampledCount = 0;
            var noopLogger   = new NoopLogger();
            var currentExecutionSegmentsContainer = new NoopCurrentExecutionSegmentsContainer();
            var noopPayloadSender   = new NoopPayloadSender();
            var configurationReader = new TestAgentConfigurationReader(noopLogger);
            var sampler             = new Sampler(rate);

            total.Repeat(i =>
            {
                var transaction = new Transaction(noopLogger, "test transaction name", "test transaction type", sampler,
                                                  /* distributedTracingData: */ null, noopPayloadSender, configurationReader, currentExecutionSegmentsContainer);
                if (transaction.IsSampled)
                {
                    ++sampledCount;
                }

                if (i + 1 >= startCheckingAfter)
                {
                    var actualRate = (double)sampledCount / (i + 1);
                    var diffInRate = actualRate - rate;
                    Assert.True(Math.Abs(diffInRate) <= allowedDiffInRate,
                                "Abs(diffInRate) should be <= allowedDiffInRate. " +
                                $"diffInRate: {diffInRate}, allowedDiffInRate: {allowedDiffInRate}, " +
                                $"i: {i}, " +
                                $"actual rate: {actualRate}, expected rate: {rate}, " +
                                $"actual sampled count: {sampledCount}, expected sampled count: {Convert.ToInt32((i + 1) * rate)}"
                                );
                }
            });
        }