public void send_timer_with_lambda_and_sampleRate_passes() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); _randomGenerator = MockRepository.GenerateMock <IRandomGenerator>(); _randomGenerator.Stub(x => x.ShouldSend(Arg <double> .Is.Anything)).Return(true); var s = new Statsd(_udp, _randomGenerator, _stopwatch); s.Send(() => TestMethod(), statName); _udp.AssertWasCalled(x => x.Send("name:500|ms")); }
public void set_return_value_with_send_timer_with_lambda() { const string statName = "name"; IStopwatch stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); Statsd s = new Statsd(udp, _randomGenerator, _stopwatch); int returnValue = 0; s.Send(() => returnValue = testMethod(), statName); udp.AssertWasCalled(x => x.Send("name:500|ms")); Assert.That(returnValue, Is.EqualTo(5)); }
/// <summary> /// Emit a batch of log events to datadog. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks>Override either <see cref="PeriodicBatchingSink.EmitBatch"/> or <see cref="PeriodicBatchingSink.EmitBatchAsync"/>, /// not both.</remarks> protected override void EmitBatch(IEnumerable <LogEvent> events) { if (events == null) { throw new ArgumentNullException("events"); } foreach (var logEvent in events) { var payload = new StringWriter(); var title = "Log Event - " + logEvent.Level; var alertType = GetAlertTypeFromEvent(logEvent); _textFormatter.Format(logEvent, payload); _statsd.Add(title, payload.ToString(), alertType, hostname: _datadogConfiguration.Hostname, tags: _datadogConfiguration.Tags); } _statsd.Send(); }
public void send_timer_with_lambda_and_tags_fails() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); _randomGenerator = MockRepository.GenerateMock <IRandomGenerator>(); _randomGenerator.Stub(x => x.ShouldSend(Arg <double> .Is.Anything)).Return(false); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); s.Send(() => TestMethod(), statName, 0.1, new { tag1 = 1, tag2 = "2" }); _sender.AssertWasNotCalled(x => x.Send(Arg <Metric> .Is.Anything)); }
public void send_timer_with_lambda() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); s.Send(() => TestMethod(), statName); IList <object[]> argsPerCall = _sender.GetArgumentsForCallsMadeOn(x => x.Send(Arg <Metric> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((Metric)argsPerCall[0][0]).Command, Is.EqualTo("name:500|ms")); }
public void send_timer_with_lamba_still_records_on_error_and_still_bubbles_up_exception() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); Assert.Throws <InvalidOperationException>(() => s.Send(() => { throw new InvalidOperationException(); }, statName)); IList <object[]> argsPerCall = _sender.GetArgumentsForCallsMadeOn(x => x.Send(Arg <Metric> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((Metric)argsPerCall[0][0]).Command, Is.EqualTo("name:500|ms")); }
public void send_service_check_with_pipe_in_name() { Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch); Assert.Throws <ArgumentException>(() => s.Send("name|", 0)); }
public void send_counters() { Parallel.For(0, ThreadCount, x => _stats.Send <Statsd.Counting>(Guid.NewGuid().ToString(), 5)); Assert.That(DistinctMetricsSent(), Is.EqualTo(ThreadCount)); }