-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from tableau/Dec2022
4.2.3 Release. Prep plugin and fixes for backgrounder plugin
- Loading branch information
Showing
40 changed files
with
4,837 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ TestLogs/ | |
|
||
# code coverage | ||
coverage.json | ||
coverage.cobertura.xml | ||
coverage.cobertura.xml | ||
|
||
#Other | ||
*.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using LogShark.Shared.LogReading.Containers; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace LogShark.Shared.LogReading.Readers | ||
{ | ||
internal class PrepLogReader : ILogReader | ||
{ | ||
private readonly String _filePath; | ||
private readonly IProcessingNotificationsCollector _processingNotificationsCollector; | ||
|
||
private static readonly char PathDelimiter = '\\'; | ||
|
||
private MultilineJavaLogReader _javaLogReader; | ||
|
||
private NativeJsonLogsReader _jsonLogReader; | ||
|
||
public static readonly Dictionary<String, PrepLogTypes> PrepLogTypeMap = new Dictionary<String, PrepLogTypes>() | ||
{ | ||
{@"/floweditor_node.*", PrepLogTypes.MultilineJava}, | ||
{@"^floweditor_node.*", PrepLogTypes.MultilineJava}, | ||
{@"/flowprocessor_node.*", PrepLogTypes.MultilineJava}, | ||
{@"^flowprocessor_node.*", PrepLogTypes.MultilineJava}, | ||
{@"/nativeapi_flowprocessor.*.txt", PrepLogTypes.NativeJson}, | ||
{@"^nativeapi_flowprocessor.*.txt", PrepLogTypes.NativeJson}, | ||
{@"Logs/app.log", PrepLogTypes.NativeJson}, | ||
{@"^app.log", PrepLogTypes.NativeJson}, | ||
{@"Logs/preprestapi.*.log*", PrepLogTypes.NativeJson}, | ||
{@"^preprestapi.*.log*", PrepLogTypes.NativeJson}, | ||
{@"Logs/log_.*.txt*", PrepLogTypes.NativeJson}, | ||
{@"^log_.*.txt*", PrepLogTypes.NativeJson}, | ||
}; | ||
|
||
public PrepLogReader(Stream stream, string filePath, IProcessingNotificationsCollector processingNotificationsCollector) | ||
{ | ||
_filePath = filePath; | ||
_processingNotificationsCollector = processingNotificationsCollector; | ||
|
||
_jsonLogReader = new NativeJsonLogsReader(stream, filePath, processingNotificationsCollector); | ||
_javaLogReader = new MultilineJavaLogReader(stream); | ||
} | ||
|
||
public IEnumerable<ReadLogLineResult> ReadLines() | ||
{ | ||
String filename = _filePath.Split(PathDelimiter).Last(); // Get the file name | ||
|
||
foreach(string pattern in PrepLogTypeMap.Keys) | ||
{ | ||
Regex r = new Regex(pattern); | ||
if(r.Match(filename).Success) | ||
{ | ||
switch(PrepLogTypeMap[pattern]) | ||
{ | ||
case PrepLogTypes.MultilineJava: | ||
return _javaLogReader.ReadLines(); | ||
case PrepLogTypes.NativeJson: | ||
return _jsonLogReader.ReadLines(); | ||
} | ||
} | ||
} | ||
|
||
_processingNotificationsCollector.ReportError($"Can't map file to a type of log, filename: {0}. " + | ||
$"Falling back to multiline java log", _filePath); | ||
|
||
return _jsonLogReader.ReadLines(); | ||
} | ||
} | ||
|
||
internal enum PrepLogTypes | ||
{ | ||
NativeJson, | ||
MultilineJava, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using FluentAssertions; | ||
using LogShark.Plugins.Prep; | ||
using LogShark.Shared; | ||
using LogShark.Shared.LogReading.Containers; | ||
using LogShark.Tests.Plugins.Helpers; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using System; | ||
using Xunit; | ||
|
||
namespace LogShark.Tests.Plugins | ||
{ | ||
public class PrepPluginTests : InvariantCultureTestsBase | ||
{ | ||
private static readonly LogFileInfo TestLogFileInfo = new("foo.log", @"prep/foo.log", "worker0", DateTime.MinValue); | ||
|
||
|
||
[Fact] | ||
public void BadInput() | ||
{ | ||
var processingNotificationsCollector = new ProcessingNotificationsCollector(10); | ||
var testWriterFactory = new TestWriterFactory(); | ||
using (var plugin = new PrepPlugin()) | ||
{ | ||
plugin.Configure(testWriterFactory, null, processingNotificationsCollector, new NullLoggerFactory()); | ||
|
||
var wrongContentFormat = new LogLine(new ReadLogLineResult(123, "An invalid Prep log line"), TestLogFileInfo); | ||
var nullContent = new LogLine(new ReadLogLineResult(123, null), TestLogFileInfo); | ||
|
||
plugin.ProcessLogLine(nullContent, LogType.Prep); | ||
plugin.ProcessLogLine(wrongContentFormat, LogType.Prep); | ||
} | ||
|
||
testWriterFactory.AssertAllWritersAreDisposedAndEmpty(1); | ||
processingNotificationsCollector.TotalErrorsReported.Should().Be(2); | ||
} | ||
|
||
|
||
[Fact] | ||
public void GoodInput() | ||
{ | ||
var processingNotificationsCollector = new ProcessingNotificationsCollector(10); | ||
var testWriterFactory = new TestWriterFactory(); | ||
using (var plugin = new PrepPlugin()) | ||
{ | ||
plugin.Configure(testWriterFactory, null, processingNotificationsCollector, new NullLoggerFactory()); | ||
|
||
var goodLog = new LogLine(new ReadLogLineResult(123, "2022-06-22 19:37:30.244 -0500 (,,,,) Curator-PathChildrenCache-19 : ERROR org.apache.curator.framework.recipes.cache.PathChildrenCache - "), TestLogFileInfo); | ||
|
||
plugin.ProcessLogLine(goodLog, LogType.Prep); | ||
} | ||
|
||
testWriterFactory.GetOneWriterAndVerifyOthersAreEmptyAndDisposed<PrepEvent>("PrepEvents", 1); | ||
processingNotificationsCollector.TotalErrorsReported.Should().Be(0); | ||
} | ||
} | ||
} |
Empty file.
Empty file.
Binary file added
BIN
+64 KB
...rk.Tests/TestData/EndToEndTests/Expected/logs_clean_tabadmin_hyper/hyper/PrepEvents.hyper
Binary file not shown.
Binary file added
BIN
+28.3 KB
...ests/Expected/logs_clean_tabadmin_hyper/workbooks/Prep_logs_clean_tabadmin [No Data].twbx
Binary file not shown.
Oops, something went wrong.