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

Initial implementation for workflow log tracing #1176

Merged
merged 8 commits into from
Nov 14, 2023

Conversation

RyanLettieri
Copy link
Contributor

Description

Added in basic logging for workflow to log the registered activities and registered workflows.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[1170]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
@RyanLettieri RyanLettieri requested review from a team as code owners October 25, 2023 20:18
@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2332388) 66.42% compared to head (0bff075) 66.42%.

❗ Current head 0bff075 differs from pull request most recent head 71064cf. Consider uploading reports for the commit 71064cf to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1176   +/-   ##
=======================================
  Coverage   66.42%   66.42%           
=======================================
  Files         171      171           
  Lines        5758     5758           
  Branches      626      626           
=======================================
  Hits         3825     3825           
  Misses       1784     1784           
  Partials      149      149           
Flag Coverage Δ
net6 66.42% <ø> (ø)
net7 66.42% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
}
}
}
}, cts.Token);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this CancellationToken is only used if the Task has not yet already started, which it most likely has, so it's possible that the task never ends (in the case of not all expected logs being found).

You could use the async method Stream.ReadLineAsync(CancellationToken) to provide a means of abandoning the search when time expires. That would also allow you to avoid calling Task.WaitAll(), which is a synchronously-blocking method.

}
}, cts.Token);

if (!Task.WaitAll(new Task[] {searchTask}, timeout))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe hold off testing the result until after the log file has been deleted (rather than two deletion paths).

Copy link
Contributor

@halspang halspang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give some examples of what logs are output when we run a workflow?

Comment on lines 42 to 52
this.logger.Log(LogLevel.Information, "List of registered workflows");
foreach (string item in registeredWorkflows)
{
this.logger.Log(LogLevel.Information, item);
}

this.logger.Log(LogLevel.Information, "List of registered activities:");
foreach (string item in registeredActivities)
{
this.logger.Log(LogLevel.Information, item);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Indentation is weird here.

/// <summary>
/// Defines runtime options for workflows.
/// </summary>
internal sealed class WorkflowLoggingService : IHostedService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if hosted service is the right way to go here. I was thinking more that this would be injected into the various workflow runtime mechanics, like the context.

using (StreamReader reader = new StreamReader(logFilePath))
{
string line;
while ((line = await reader.ReadLineAsync()) != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to pass the cancellation token to ReadLineAsync() so it will stop reading after the timeout.

finally
{
File.Delete(logFilePath);
if (!allLogsFound)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allLogsFound test should probably be outside/after the finally block; it doesn't need to be executed in the case of an exception (e.g. timeout) as the exception will bubble up and fail the test.

@halspang halspang merged commit 39a38f6 into dapr:master Nov 14, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase Logging Metrics for Workflow
3 participants