Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDMP-16 Add Max Message Length Check to Logging Notifications #1595

Merged
merged 17 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,51 @@ public virtual void StartLogging()
_logManager.CreateDataLoadInfo(_loggingTask, _hostingApplication.ToString(), _runDescription, "", false);
}

private const string RDMPLoggingStringLengthLimit = "RDMP_LOGGING_STRING_LENGTH_LIMIT";
private static readonly int StrStringLengthLimit;

static ToLoggingDatabaseDataLoadEventListener()
{
StrStringLengthLimit = int.TryParse(Environment.GetEnvironmentVariable(RDMPLoggingStringLengthLimit),out var limit) ? limit : int.MaxValue;
}

private static string EnsureMessageAValidLength(string message)
{
return StrStringLengthLimit < 4 ? "" :
message.Length > StrStringLengthLimit ? message[..(StrStringLengthLimit - 3)] + "..." : message;
}
public virtual void OnNotify(object sender, NotifyEventArgs e)
{
if (DataLoadInfo == null)
StartLogging();
if (StrStringLengthLimit < 4) // Logging suppressed
return;

switch (e.ProgressEventType)
{
case ProgressEventType.Trace:
case ProgressEventType.Debug:
break;
case ProgressEventType.Information:
DataLoadInfo.LogProgress(Logging.DataLoadInfo.ProgressEventType.OnInformation, sender.ToString(),
e.Message);
DataLoadInfo?.LogProgress(Logging.DataLoadInfo.ProgressEventType.OnInformation, sender.ToString(),
EnsureMessageAValidLength(e.Message));
break;
case ProgressEventType.Warning:
var msg = e.Message + (e.Exception == null
? ""
: Environment.NewLine + ExceptionHelper.ExceptionToListOfInnerMessages(e.Exception, true));
DataLoadInfo.LogProgress(Logging.DataLoadInfo.ProgressEventType.OnWarning, sender.ToString(), msg);
msg = EnsureMessageAValidLength(msg);
DataLoadInfo?.LogProgress(Logging.DataLoadInfo.ProgressEventType.OnWarning, sender.ToString(), msg);
break;
case ProgressEventType.Error:
var err = e.Message + (e.Exception == null
? ""
: Environment.NewLine + ExceptionHelper.ExceptionToListOfInnerMessages(e.Exception, true));
DataLoadInfo.LogFatalError(sender.ToString(), err);
err = EnsureMessageAValidLength(err);
DataLoadInfo?.LogFatalError(sender.ToString(), err);
break;
default:
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(e));
}
}

Expand All @@ -97,18 +114,16 @@ public virtual void OnProgress(object sender, ProgressEventArgs e)

Debug.Assert(DataLoadInfo != null, "DataLoadInfo != null");

if (e.Progress.UnitOfMeasurement == ProgressType.Records)
if (e.Progress.UnitOfMeasurement != ProgressType.Records) return;

if (!TableLoads.TryGetValue(e.TaskDescription,out var t))
{
//if(!tableLoads.Any(tbl=>tbl.))
if (!TableLoads.ContainsKey(e.TaskDescription))
{
var t = DataLoadInfo.CreateTableLoadInfo("", e.TaskDescription,
new[] { new DataSource(sender.ToString()) }, e.Progress.KnownTargetValue);
TableLoads.Add(e.TaskDescription, t);
}

TableLoads[e.TaskDescription].Inserts = e.Progress.Value;
t = DataLoadInfo.CreateTableLoadInfo("", e.TaskDescription,
new[] { new DataSource(sender.ToString()) }, e.Progress.KnownTargetValue);
TableLoads.Add(e.TaskDescription, t);
}

t.Inserts = e.Progress.Value;
}

public virtual void FinalizeTableLoadInfos()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static void FindProblems(List<string> csFilesFound)
"Settings.Designer.cs",
"PlatformDatabaseCreationOptions.cs",
"PackOptions.cs",
"PasswordEncryptionKeyLocation.cs"
"PasswordEncryptionKeyLocation.cs",
"ToLoggingDatabaseDataLoadEventListener.cs"
}); //allowed because it's default arguments for CLI

prohibitedStrings.Add("TEST_");
Expand Down