private void InvokeTest(string type)
        {
            var context = new DefaultHttpContext();

            context.Request.Method = "POST";
            context.Request.Path   = "/_" + type;
            context.Request.Body   = File.OpenRead($"messages\\{type}.txt");
            httpHandler.Invoke(context).Wait();
            RoutingKey.Parse(routingKey, out project, out _, out var service, out _);
            Assert.AreEqual("frontier-" + type, service);
            Assert.AreEqual(LogLevel.Error, logEventData.Level);
        }
        public IAirlockEventProcessor GetProcessor(string routingKey)
        {
            RoutingKey.Parse(routingKey, out var project, out var environment, out _, out _);
            var projEnv = $"{project}_{environment}";

            if (!processorsByProjectAndEnv.TryGetValue(projEnv, out var processor))
            {
                var ravenClient            = CreateRavenClient(project, environment);
                var sentryProjectId        = ravenClient.CurrentDsn.ProjectID;
                var sentryPacketSender     = new SentryPacketSender(ravenClient, log);
                var sentryAirlockProcessor = new SentryAirlockProcessor(sentryProjectId, processorSettings, log, sentryPacketSender);
                processor = new DefaultAirlockEventProcessor <LogEventData>(airlockDeserializer, sentryAirlockProcessor);
                processorsByProjectAndEnv.Add(projEnv, processor);
            }
            return(processor);
        }
Beispiel #3
0
        public sealed override void Process(List <AirlockEvent <LogEventData> > events, ProcessorMetrics processorMetrics)
        {
            var bulks = events
                        .Select(
                @event =>
            {
                RoutingKey.Parse(@event.RoutingKey, out var project, out var environment, out var service,
                                 out var _);
                var indexName       = $"{project}-{environment}";
                var indexRecordMeta = BuildIndexRecordMeta(indexName);
                var indexRecord     = BuildIndexRecord(@event, service);
                return(new { indexName, indexRecordMeta, indexRecord });
            })
                        .GroupBy(x => x.indexName)
                        .SelectMany(g => g.Batch(10000).Select(records =>
            {
                var postDataItems = new List <object>();
                foreach (var record in records)
                {
                    postDataItems.Add(record.indexRecordMeta);
                    postDataItems.Add(record.indexRecord);
                }

                var postData = new PostData <object>(postDataItems);
                return(new { postData, recordsCount = postDataItems.Count / 2 });
            }))
                        .ToList();

            Parallel.ForEach(
                bulks,
                bulk =>
            {
                try
                {
                    BulkIndex(bulk.postData, processorMetrics.SendingErrorCounter);
                    processorMetrics.EventProcessedCounter.Add(bulk.recordsCount);
                }
                catch (Exception)
                {
                    processorMetrics.EventFailedCounter.Add(bulk.recordsCount);
                    throw;
                }
            });
        }
 public void Parse_fails_if_invalid_key(string routingKey)
 {
     Assert.False(RoutingKey.TryParse(routingKey, out var _, out var _, out var _, out var _));
     Assert.Throws <InvalidOperationException>(() => RoutingKey.Parse(routingKey, out var _, out var _, out var _, out var _));
 }