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

Adding trace level in diag argument #1681

Merged
merged 16 commits into from
Aug 1, 2018
Merged

Conversation

abhishkk
Copy link
Contributor

@abhishkk abhishkk commented Jul 9, 2018

Description

Currently \diag: arg always stores logs of verbose level. This PR adds customization in diag argument to allow users to pass trace level for logs.

Limitations

dotnet test command has --diag option. TraceLevel will not be supported in this --diag option.

if (string.IsNullOrWhiteSpace(argument))
{
throw new CommandLineException(CommandLineResources.EnableDiagUsage);
HandleInvalidDiagArgument();
Copy link
Contributor

Choose a reason for hiding this comment

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

throw Exception here itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

/// <returns>Diag argument list.</returns>
private string[] GetDiagArgumentList(string argument)
{
var argumentSeperator = new char[] { ';' };
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor / Reuse from Collect/Logger processors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -228,7 +230,8 @@ private static void InitializeEqtTrace(IDictionary<string, string> argsDictionar
// Setup logging if enabled
if (argsDictionary.TryGetValue(LogFileArgument, out string logFile))
{
EqtTrace.InitializeVerboseTrace(logFile);
var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument);
Copy link
Contributor

@mayankbansal018 mayankbansal018 Jul 9, 2018

Choose a reason for hiding this comment

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

verify for invalid tracelevel values,
Also verify vstest.console with older testhost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check for invalid tracelevel values
Verified with older testhost as well.

/// <summary>
/// Trace level for logs.
/// </summary>
public PlatformTraceLevel TraceLevel { get; set; } = PlatformTraceLevel.Verbose;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I use System.Diagnostics.TraceLevel here OR Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformTraceLevel.

Internally we use PlatformTraceLevel wherever TraceLevel is not present. Example: NETSTANDARD1_4

Copy link
Contributor

Choose a reason for hiding this comment

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

PlatformTraceLevel is in PlatformAbstraction, this will mandate translationlayer users to have a reference to PlatformAbstraction as well.

If possible we should remove all the usage for System.Diagnostics.TraceLevel, rather have another TraceLevel enum in OM for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed dependency on platform abstractions.
Cant remove System.Diagnostics.TraceLevel as used by exe config trace level.

var diagArgumentList = GetDiagArgumentList(argument);

// Get diag file path.
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon].
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the behavior in that case, do we throw an error to the user ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we throw error to the user outputing diag arg usage.

/// <summary>
/// Trace level for logs.
/// </summary>
public PlatformTraceLevel TraceLevel { get; set; } = PlatformTraceLevel.Verbose;
Copy link
Contributor

Choose a reason for hiding this comment

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

PlatformTraceLevel is in PlatformAbstraction, this will mandate translationlayer users to have a reference to PlatformAbstraction as well.

If possible we should remove all the usage for System.Diagnostics.TraceLevel, rather have another TraceLevel enum in OM for this.

var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument);

// In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose.
var traceLevel = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt) ?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unexpected, I know it is a bit tricky, can we log a warning for this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

var diagArgumentList = ArgumemtProcessorUtilities.GetArgumentList(argument, ArgumemtProcessorUtilities.SemiColonArgumentSeperator, CommandLineResources.EnableDiagUsage);

// Get diag file path.
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon].
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning for case file path contains ";" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cant know if the semi colon is present in file path. we simply split the argument based on semi colon and the first argument is our file path

Copy link
Contributor

Choose a reason for hiding this comment

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

This means we will get some warning right ? I am expecting we wont be able to understand the string post ";" and should throw. Can you check ?


internal class ArgumemtProcessorUtilities
{
public static readonly char[] SemiColonArgumentSeperator = { ';' };
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Separator*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

using System;
using System.Collections.Generic;

internal class ArgumemtProcessorUtilities
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Argument*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// Licensed under the MIT license. See LICENSE file in the project root for full license information.


namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also handle validation of arguments based on a list? instead of just returning any value from the raw string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are handling the validation of argument here.

@abhishkk
Copy link
Contributor Author

Include kaadhina PR and makes changes there as well.

/// Initializes the tracing with custom log file and trace level.
/// Overrides if any trace is set before.
/// </summary>
/// <param name="customLogFile">Customr log file for trace messages.</param>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:custom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

(PlatformTraceLevel)traceLevelInt :
PlatformTraceLevel.Verbose;

EqtTrace.Warning("DataCollectorMain.Run: Invalid trace level: {0}, defaulting to vebose tracelevel.", traceLevelInt);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will log always. Have a proper if for the previous block.
Nit:verbose*

Copy link
Contributor

Choose a reason for hiding this comment

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

And without Initialize, will it work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected. thanks

/// </summary>
/// <param name="collectDumpKey">Collect dump key.</param>
/// <returns>Flag for collect dump key valid or not.</returns>
private bool ValidateCollectDumpKey(string collectDumpKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused. How is this part of this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have made the parsing logic generic with my PR as per Mayank's PR comment. Thus blame, diag and logger have been changed to use the new generic logic.

These are just refactoring and not the code changes.

var diagArgumentList = ArgumemtProcessorUtilities.GetArgumentList(argument, ArgumemtProcessorUtilities.SemiColonArgumentSeperator, CommandLineResources.EnableDiagUsage);

// Get diag file path.
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon].
Copy link
Contributor

Choose a reason for hiding this comment

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

This means we will get some warning right ? I am expecting we wont be able to understand the string post ";" and should throw. Can you check ?

}

/// <summary>
/// Initialize diag loggin.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@mayankbansal018 mayankbansal018 left a comment

Choose a reason for hiding this comment

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

:shipit:

@abhishkk abhishkk merged commit 7fbfc61 into microsoft:master Aug 1, 2018
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.

4 participants