public void ParseEvents(string input, int expectedEvents, string[] expectedMessage, string expectedType) { var events = _parser.ParseEvents(input, 2, "exceptionless/2.0.0.0"); Assert.Equal(expectedEvents, events.Count); for (int index = 0; index < events.Count; index++) { var ev = events[index]; Assert.Equal(expectedMessage[index], ev.Message); Assert.Equal(expectedType, ev.Type); Assert.NotEqual(DateTimeOffset.MinValue, ev.Date); } }
private List <PersistentEvent> ParseEventPost(EventPost ep) { byte[] data = ep.Data; if (!String.IsNullOrEmpty(ep.ContentEncoding)) { data = data.Decompress(ep.ContentEncoding); } var encoding = Encoding.UTF8; if (!String.IsNullOrEmpty(ep.CharSet)) { encoding = Encoding.GetEncoding(ep.CharSet); } string input = encoding.GetString(data); List <PersistentEvent> events = _eventParserPluginManager.ParseEvents(input, ep.ApiVersion, ep.UserAgent); events.ForEach(e => { // set the project id on all events e.ProjectId = ep.ProjectId; }); return(events); }
private List <PersistentEvent> ParseEventPost(EventPostInfo ep) { byte[] data = ep.Data; if (!String.IsNullOrEmpty(ep.ContentEncoding)) { data = data.Decompress(ep.ContentEncoding); } var encoding = Encoding.UTF8; if (!String.IsNullOrEmpty(ep.CharSet)) { encoding = Encoding.GetEncoding(ep.CharSet); } string input = encoding.GetString(data); List <PersistentEvent> events = _eventParserPluginManager.ParseEvents(input, ep.ApiVersion, ep.UserAgent); events.ForEach(e => { // set the project id on all events e.ProjectId = ep.ProjectId; // set the reference id to the event id if one was defined. if (!String.IsNullOrEmpty(e.Id) && String.IsNullOrEmpty(e.ReferenceId)) { e.ReferenceId = e.Id; } // the event id, stack id and organization id should never be set for posted events e.Id = e.StackId = e.OrganizationId = null; }); return(events); }
public static async Task CreateSearchDataAsync(ExceptionlessElasticConfiguration configuration, IEventRepository eventRepository, EventParserPluginManager parserPluginManager, bool updateDates = false) { string path = Path.Combine("..", "..", "..", "Search", "Data"); foreach (string file in Directory.GetFiles(path, "event*.json", SearchOption.AllDirectories)) { if (file.EndsWith("summary.json")) { continue; } var events = parserPluginManager.ParseEvents(await File.ReadAllTextAsync(file), 2, "exceptionless/2.0.0.0"); Assert.NotNull(events); Assert.True(events.Count > 0); foreach (var ev in events) { if (updateDates) { ev.Date = SystemClock.OffsetNow; ev.CreatedUtc = SystemClock.UtcNow; } ev.CopyDataToIndex(Array.Empty <string>()); } await eventRepository.AddAsync(events, o => o.ImmediateConsistency()); } configuration.Events.QueryParser.Configuration.MappingResolver.RefreshMapping(); }
private List <PersistentEvent> ParseEventPost(EventPostInfo ep, DateTime createdUtc, byte[] uncompressedData, string queueEntryId, bool isInternalProject) { using (_logger.BeginScope(new ExceptionlessState().Tag("parsing"))) { if (!isInternalProject && _logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Parsing EventPost: {QueueEntryId}", queueEntryId); } List <PersistentEvent> events = null; try { var encoding = Encoding.UTF8; if (!String.IsNullOrEmpty(ep.CharSet)) { encoding = Encoding.GetEncoding(ep.CharSet); } _metrics.Time(() => { string input = encoding.GetString(uncompressedData); events = _eventParserPluginManager.ParseEvents(input, ep.ApiVersion, ep.UserAgent) ?? new List <PersistentEvent>(0); foreach (var ev in events) { ev.CreatedUtc = createdUtc; ev.OrganizationId = ep.OrganizationId; ev.ProjectId = ep.ProjectId; // set the reference id to the event id if one was defined. if (!String.IsNullOrEmpty(ev.Id) && String.IsNullOrEmpty(ev.ReferenceId)) { ev.ReferenceId = ev.Id; } // the event id and stack id should never be set for posted events ev.Id = ev.StackId = null; } }, MetricNames.PostsParsingTime); _metrics.Counter(MetricNames.PostsParsed); _metrics.Gauge(MetricNames.PostsEventCount, events.Count); } catch (Exception ex) { _metrics.Counter(MetricNames.PostsParseErrors); if (!isInternalProject) { _logger.LogError(ex, "An error occurred while processing the EventPost {QueueEntryId}: {Message}", queueEntryId, ex.Message); } } if (!isInternalProject && _logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Parsed {ParsedCount} events from EventPost: {QueueEntryId}", events?.Count ?? 0, queueEntryId); } return(events); } }
public void ParseErrors(string errorFilePath) { var json = File.ReadAllText(errorFilePath); var ctx = new EventUpgraderContext(json); _upgrader.Upgrade(ctx); ApprovalsUtility.VerifyFile(Path.ChangeExtension(errorFilePath, ".expected.json"), ctx.Documents.First.ToString()); var events = _parser.ParseEvents(ctx.Documents.ToString(), 2, "exceptionless/2.0.0.0"); Assert.Equal(1, events.Count); }
public void ParseEvents(string input, int expectedEvents, string expectedType) { var events = _eventParserPluginManager.ParseEvents(input, 1, "exceptionless/1.0.0.0"); Assert.Equal(expectedEvents, events.Count); foreach (var ev in events) { Assert.Equal(expectedType, ev.Type); Assert.False(String.IsNullOrWhiteSpace(ev.Message)); Assert.NotEqual(ev.Date, DateTimeOffset.MinValue); } }
public void ParseEvents(string errorFilePath) { var json = File.ReadAllText(errorFilePath); var ctx = new EventUpgraderContext(json); // TODO: Figure out what is wrong with 800000002e519522d83837a1 _eventUpgraderPluginManager.Upgrade(ctx); ApprovalsUtility.VerifyFile(Path.ChangeExtension(errorFilePath, ".expected.json"), ctx.Documents.First.ToString()); var events = _eventParserPluginManager.ParseEvents(ctx.Documents.ToString(), 2, "exceptionless/2.0.0.0"); Assert.Equal(1, events.Count); }
public void ParseErrors(string errorFilePath) { string json = File.ReadAllText(errorFilePath); var ctx = new EventUpgraderContext(json); _upgrader.Upgrade(ctx); string expectedContent = File.ReadAllText(Path.ChangeExtension(errorFilePath, ".expected.json")); Assert.Equal(expectedContent, ctx.Documents.First.ToString()); var events = _parser.ParseEvents(ctx.Documents.ToString(), 2, "exceptionless/2.0.0.0"); Assert.Single(events); }
private async Task <List <PersistentEvent> > ParseEventPostAsync(EventPostInfo ep, DateTime createdUtc, string queueEntryId, bool isInternalProject) { List <PersistentEvent> events = null; try { await _metricsClient.TimeAsync(async() => { byte[] data = ep.Data; if (!String.IsNullOrEmpty(ep.ContentEncoding)) { data = data.Decompress(ep.ContentEncoding); } var encoding = Encoding.UTF8; if (!String.IsNullOrEmpty(ep.CharSet)) { encoding = Encoding.GetEncoding(ep.CharSet); } string input = encoding.GetString(data); events = _eventParserPluginManager.ParseEvents(input, ep.ApiVersion, ep.UserAgent) ?? new List <PersistentEvent>(0); foreach (var ev in events) { ev.CreatedUtc = createdUtc; // set the project id on all events ev.ProjectId = ep.ProjectId; // set the reference id to the event id if one was defined. if (!String.IsNullOrEmpty(ev.Id) && String.IsNullOrEmpty(ev.ReferenceId)) { ev.ReferenceId = ev.Id; } // the event id, stack id and organization id should never be set for posted events ev.Id = ev.StackId = ev.OrganizationId = null; } }, MetricNames.PostsParsingTime).AnyContext(); await _metricsClient.CounterAsync(MetricNames.PostsParsed).AnyContext(); await _metricsClient.GaugeAsync(MetricNames.PostsEventCount, events.Count).AnyContext(); } catch (Exception ex) { await _metricsClient.CounterAsync(MetricNames.PostsParseErrors).AnyContext(); _logger.Error().Exception(ex).Message("An error occurred while processing the EventPost '{0}': {1}", queueEntryId, ex.Message).WriteIf(!isInternalProject); } return(events); }