Skip to content

Commit 26239e0

Browse files
authored
Merge pull request #5573 from Azure/adls-data-plane-task-addDebugFunctionality
Adls data plane task add debug functionality
2 parents 9da0af4 + 97935bd commit 26239e0

File tree

8 files changed

+70
-26
lines changed

8 files changed

+70
-26
lines changed

src/ResourceManager/DataLakeStore/ChangeLog.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21-
22-
* Update the version of the ADLS dataplane SDK to 1.1.2
23-
24-
## Version 5.1.1
25-
* Corrected usage of 'Login-AzureRmAccount' to use 'Connect-AzureRmAccount'
26-
* Corrected the error message of 'Test-AzureRmDataLakeStoreAccount' when running this cmdlet without having logged in with 'Login-AzureRmAccount'
21+
* Add debug functionality
22+
* Update the version of the ADLS dataplane SDK to 1.1.2
2723

2824
## Version 5.2.0-preview
29-
3025
* Export-AzureRmDataLakeStoreItem (https://github.com/Azure/azure-powershell/blob/adls-data-plane/src/ResourceManager/DataLakeStore/documentation/upcoming-breaking-changes.md) - Deprecated parameters PerFileThreadCount, ConcurrentFileCount and introduced parameter Concurrency
3126
* Import-AzureRMDataLakeStoreItem (https://github.com/Azure/azure-powershell/blob/adls-data-plane/src/ResourceManager/DataLakeStore/documentation/upcoming-breaking-changes.md) -Deprecated parametersPerFileThreadCount, ConcurrentFileCount and introduced parameter Concurrency
3227
* Get-AzureRMDataLakeStoreItemContent - Fixed the tail behavior for contents greater than 4MB

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands.DataLakeStore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<ItemGroup>
3939
<Reference Include="Microsoft.Azure.DataLake.Store, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4040
<SpecificVersion>False</SpecificVersion>
41-
<HintPath>..\..\..\packages\Microsoft.Azure.DataLake.Store.1.1.2\lib\net452\Microsoft.Azure.DataLake.Store.dll</HintPath>
41+
<HintPath>..\..\..\packages\Microsoft.Azure.DataLake.Store.1.1.4\lib\net452\Microsoft.Azure.DataLake.Store.dll</HintPath>
4242
<Private>True</Private>
4343
</Reference>
4444
<Reference Include="Microsoft.Azure.Management.DataLake.Store, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -89,6 +89,7 @@
8989
<Compile Include="Commands\TestAzureRmDataLakeStoreAccount.cs" />
9090
<Compile Include="DataPlaneCommands\TestAzureRmDataLakeStoreItem.cs" />
9191
<Compile Include="DataPlaneModels\AdlsClientFactory.cs" />
92+
<Compile Include="DataPlaneModels\AdlsLoggerTarget.cs" />
9293
<Compile Include="Models\DataLakeStoreClient.cs" />
9394
<Compile Include="Models\DataLakeStoreCmdletBase.cs" />
9495
<Compile Include="DataPlaneModels\DataLakeStoreEnums.cs" />

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneCommands/ExportAzureRmDataLakeStoreItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public override void ExecuteCmdlet()
149149
{
150150
var diagnosticPath =
151151
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
152-
DataLakeStoreFileSystemClient.SetupLogging(DiagnosticLogLevel, diagnosticPath);
152+
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
153153
}
154154

155155
int threadCount;

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneCommands/ImportAzureRmDataLakeStoreItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public override void ExecuteCmdlet()
157157
{
158158
var diagnosticPath =
159159
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
160-
DataLakeStoreFileSystemClient.SetupLogging(DiagnosticLogLevel, diagnosticPath);
160+
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
161161
}
162162

163163
int threadCount;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Concurrent;
2+
using NLog;
3+
using NLog.Targets;
4+
5+
namespace Microsoft.Azure.Commands.DataLakeStore.Models
6+
{
7+
/// <summary>
8+
/// NLog is used by the ADLS dataplane sdk to log debug messages. We can create a custom target
9+
/// which basically queues the debug data to the ConcurrentQueue for debug messages.
10+
/// https://github.com/NLog/NLog/wiki/How-to-write-a-custom-target
11+
/// </summary>
12+
[Target("AdlsLogger")]
13+
internal sealed class AdlsLoggerTarget : TargetWithLayout
14+
{
15+
internal ConcurrentQueue<string> DebugMessageQueue;
16+
protected override void Write(LogEventInfo logEvent)
17+
{
18+
string logMessage = Layout.Render(logEvent);
19+
DebugMessageQueue?.Enqueue(logMessage);
20+
}
21+
}
22+
}

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneModels/DataLakeStoreFileSystemClient.cs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ public class DataLakeStoreFileSystemClient
4545
private const int MaxConnectionLimit = 1000;
4646
private const long NeverExpireValue = 253402300800000;
4747
internal const int ImportExportMaxThreads = 256;
48+
private readonly LoggingConfiguration _adlsLoggerConfig;
49+
4850
#region Constructors
4951

52+
static DataLakeStoreFileSystemClient()
53+
{
54+
// Registering the custom target class
55+
Target.Register<AdlsLoggerTarget>("AdlsLogger"); //generic
56+
LogManager.ReconfigExistingLoggers();
57+
}
58+
5059
public DataLakeStoreFileSystemClient(IAzureContext context)
5160
{
5261
if (context != null)
@@ -68,6 +77,29 @@ public DataLakeStoreFileSystemClient(IAzureContext context)
6877
ServicePointManager.UseNagleAlgorithm = false;
6978
}
7079

80+
public DataLakeStoreFileSystemClient(IAzureContext context, DataLakeStoreFileSystemCmdletBase cmdlet) : this(context)
81+
{
82+
_adlsLoggerConfig = new LoggingConfiguration();
83+
84+
// Custom target that logs the debug messages from the SDK to the powershell framework's debug message queue
85+
var adlsTarget = new AdlsLoggerTarget{
86+
DebugMessageQueue = cmdlet.DebugMessages
87+
};
88+
89+
// Add the target to the configuration
90+
_adlsLoggerConfig.AddTarget("logger", adlsTarget);
91+
92+
//Logs all patterns of debug messages
93+
var rule = new LoggingRule("adls.dotnet.*", NLog.LogLevel.Debug, adlsTarget);
94+
_adlsLoggerConfig.LoggingRules.Add(rule);
95+
96+
var powershellLoggingRule= new LoggingRule("adls.powershell.WebTransport", NLog.LogLevel.Debug, adlsTarget);
97+
_adlsLoggerConfig.LoggingRules.Add(powershellLoggingRule);
98+
99+
// Enable the NLog configuration to use this
100+
LogManager.Configuration = _adlsLoggerConfig;
101+
}
102+
71103
#endregion
72104

73105
#region File and Folder Permissions Operations
@@ -495,28 +527,22 @@ public void AppendToFile(string filePath, string accountName, byte[] contents)
495527
}
496528
}
497529
/// <summary>
498-
/// Setsup Nlog logging
530+
/// Setsup Nlog logging to a file
499531
/// </summary>
500532
/// <param name="level">Logging level- debug or error</param>
501533
/// <param name="fileName">Path of file where logging will be done</param>
502-
public void SetupLogging(LogLevel level, string fileName)
534+
public void SetupFileLogging(LogLevel level, string fileName)
503535
{
504-
// Step 1. Create configuration object
505-
var config = new LoggingConfiguration();
506-
507-
// Step 2. Create targets and add them to the configuration
508536
var fileTarget = new FileTarget();
509-
config.AddTarget("file", fileTarget);
537+
_adlsLoggerConfig.AddTarget("file", fileTarget);
510538

511-
// Step 3. Set target properties
512539
fileTarget.FileName = fileName;
513-
fileTarget.Layout = "${message}";
540+
541+
var rule = new LoggingRule("adls.dotnet.*", NLog.LogLevel.Debug, fileTarget);
542+
_adlsLoggerConfig.LoggingRules.Add(rule);
514543

515-
// Step 4. Define rules
516-
var rule2 = new LoggingRule("asdl.dotnet.*", NLog.LogLevel.Debug, fileTarget);
517-
config.LoggingRules.Add(rule2);
518-
// Step 5. Activate the configuration
519-
LogManager.Configuration = config;
544+
//Re-enable the configuration
545+
LogManager.Configuration = _adlsLoggerConfig;
520546
}
521547
/// <summary>
522548
/// Performs the bulk copy and tracks the progress

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneModels/DataLakeStoreFileSystemCmdletBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public DataLakeStoreFileSystemClient DataLakeStoreFileSystemClient
3434
{
3535
get {
3636
return _dataLakeFileSystemClient ??
37-
(_dataLakeFileSystemClient = new DataLakeStoreFileSystemClient(DefaultProfile.DefaultContext));
37+
(_dataLakeFileSystemClient = new DataLakeStoreFileSystemClient(DefaultProfile.DefaultContext, this));
3838
}
3939

4040

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DataLake.Store" version="1.1.2" targetFramework="net452" />
3+
<package id="Microsoft.Azure.DataLake.Store" version="1.1.4" targetFramework="net452" />
44
<package id="Microsoft.Azure.Management.DataLake.Store" version="2.3.0-preview" targetFramework="net452" />
55
<package id="NLog" version="4.4.12" targetFramework="net452" />
66
</packages>

0 commit comments

Comments
 (0)