Exemple #1
0
        public void Accepts100PerSecond()
        {
            var e = new EventRateLimiter(100);

            var t = DateTime.Parse("2012-09-21 14:00");
            var p = 0;

            for (int i = 0; i < 10000; i++)
            {
                if (e.Request(t + TimeSpan.FromTicks(i)))
                {
                    p++;
                }
            }

            Assert.AreEqual(100, p);

            t = DateTime.Parse("2012-09-21 14:00:01");
            p = 0;
            for (int i = 0; i < 10000; i++)
            {
                if (e.Request(t + TimeSpan.FromTicks(i)))
                {
                    p++;
                }
            }

            Assert.AreEqual(100, p);
        }
Exemple #2
0
 private static void AddSomeRequests(DateTime t, EventRateLimiter e)
 {
     for (int i = 0; i < 10; i++)
     {
         e.Request(t.AddMilliseconds(i * 10));
     }
 }
Exemple #3
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");

            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var sqsDatum = _eventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent)).Single();

            var sendMessageBatchRequestEntry = new SendMessageBatchRequestEntry
            {
                MessageBody = sqsDatum.Message,
                Id          = sqsDatum.ID,
            };

            if (sqsDatum.DelaySeconds.HasValue)
            {
                sendMessageBatchRequestEntry.DelaySeconds = sqsDatum.DelaySeconds.Value;
            }

            _client.AddSendMessageRequest(new SendMessageBatchRequestWrapper
            {
                QueueName = sqsDatum.QueueName,
                Entries   = new[]
                {
                    sendMessageBatchRequestEntry
                }.ToList()
            }
                                          );
        }
        public void DefaultAlwaysAccepts()
        {
            var e = new EventRateLimiter();

            var t = DateTime.Parse("2012-09-21 14:00");
            AddSomeRequests(t, e);

            Assert.IsTrue(e.Request(t.AddMilliseconds(900)));
        }
Exemple #5
0
        public void DefaultAlwaysAccepts()
        {
            var e = new EventRateLimiter();

            var t = DateTime.Parse("2012-09-21 14:00");

            AddSomeRequests(t, e);

            Assert.IsTrue(e.Request(t.AddMilliseconds(900)));
        }
 protected override void Append(LoggingEvent loggingEvent)
 {
     if (!_eventRateLimiter.Request(loggingEvent.TimeStamp))
     {
         LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
     }
     else
     {
         base.Append(loggingEvent);
     }
 }
        public void Accepts100PerSecond()
        {
            var e = new EventRateLimiter(100);

            var t = DateTime.Parse("2012-09-21 14:00");
            var p = 0;
            for (int i = 0; i < 10000; i++)
                if (e.Request(t + TimeSpan.FromTicks(i)))
                    p++;

            Assert.AreEqual(100, p);

            t = DateTime.Parse("2012-09-21 14:00:01");
            p = 0;
            for (int i = 0; i < 10000; i++)
                if (e.Request(t + TimeSpan.FromTicks(i)))
                    p++;

            Assert.AreEqual(100, p);
        }
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");

            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var metricDataRequests = MetricDatumEventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent));

            foreach (var putMetricDataRequest in metricDataRequests)
            {
                _client.QueuePutMetricData(putMetricDataRequest);
            }
        }
Exemple #9
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");

            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var logDatum = _eventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent)).Single();

            _client.AddLogRequest(new PutLogEventsRequest(logDatum.GroupName, logDatum.StreamName, new[] { new InputLogEvent
                                                                                                           {
                                                                                                               Timestamp = logDatum.Timestamp.Value.ToUniversalTime(),
                                                                                                               Message   = logDatum.Message
                                                                                                           } }.ToList()));
        }
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");


            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var sqsDatum = _eventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent)).Single();

            if (System.Text.UTF8Encoding.UTF8.GetByteCount(sqsDatum.Message) > 256 * 1024)
            {
                throw new MessageTooLargeException(sqsDatum.Message);
            }

            if (sqsDatum.QueueName != null && !_queueNameRegex.IsMatch(sqsDatum.QueueName))
            {
                throw new MessageTooLargeException(sqsDatum.Message);
            }

            var sendMessageBatchRequestEntry = new SendMessageBatchRequestEntry
            {
                MessageBody = sqsDatum.Message,
                Id          = sqsDatum.ID,
            };

            if (sqsDatum.DelaySeconds.HasValue)
            {
                sendMessageBatchRequestEntry.DelaySeconds = sqsDatum.DelaySeconds.Value;
            }

            _client.AddSendMessageRequest(new SendMessageBatchRequestWrapper
            {
                QueueName = sqsDatum.QueueName ?? _fallbackQueueName,
                Entries   = new[]
                {
                    sendMessageBatchRequestEntry
                }.ToList()
            }
                                          );
        }
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");


            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var snsDatum = _eventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent)).Single();


            _client.AddPublishRequest(new PublishRequestWrapper
            {
                Message = snsDatum.Message,
                Topic   = snsDatum.Topic ?? _fallbackTopic
            });
        }
 private static void AddSomeRequests(DateTime t, EventRateLimiter e)
 {
     for (int i = 0; i < 10; i++)
         e.Request(t.AddMilliseconds(i * 10));
 }