Added function to log cmdlet execution info during test (#361)

This commit is contained in:
Vincent Dai 2022-11-01 10:55:42 +08:00 коммит произвёл GitHub
Родитель 1b1efb9e07
Коммит 95df4e871a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 47 добавлений и 7 удалений

Просмотреть файл

@ -27,5 +27,6 @@ namespace Microsoft.Azure.PowerShell.Common.Config
public const string EnableInterceptSurvey = "DisplaySurveyMessage";
public const string DisplayBreakingChangeWarning = "DisplayBreakingChangeWarning";
public const string EnableDataCollection = "EnableDataCollection";
public const string EnableTestCoverage = "EnableTestCoverage";
}
}

Просмотреть файл

@ -673,6 +673,9 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Common
_qosEvent.PSHostName = PSHostName;
_qosEvent.ModuleName = this.ModuleName;
_qosEvent.ModuleVersion = this.ModuleVersion;
_qosEvent.SourceScript = MyInvocation.ScriptName;
_qosEvent.ScriptLineNumber = MyInvocation.ScriptLineNumber;
if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
{
_qosEvent.CommandName = this.MyInvocation.MyCommand.Name;
@ -752,6 +755,7 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Common
return;
}
_qosEvent.ParameterSetName = this.ParameterSetName;
_qosEvent.FinishQosEvent();
if (!IsUsageMetricEnabled && (!IsErrorMetricEnabled || _qosEvent.IsSuccess))
@ -759,11 +763,6 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Common
return;
}
if (!IsDataCollectionAllowed())
{
return;
}
WriteDebug(_qosEvent.ToString());
try

Просмотреть файл

@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
namespace Microsoft.WindowsAzure.Commands.Common
{
/// <summary>
/// All properties and actions defined for test coverage
/// </summary>
public interface ITestCoverage
{
/// <summary>
/// Log the raw data from QoS event object
/// </summary>
/// <param name="qos"></param>
void LogRawData(AzurePSQoSEvent qos);
}
}

Просмотреть файл

@ -18,6 +18,7 @@ using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.Commands.Common;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.PowerShell.Common.Config;
using Microsoft.Azure.PowerShell.Common.Share;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.Common.Utilities;
@ -181,11 +182,20 @@ namespace Microsoft.WindowsAzure.Commands.Common
public void LogQoSEvent(AzurePSQoSEvent qos, bool isUsageMetricEnabled, bool isErrorMetricEnabled)
{
if (qos == null || !IsMetricTermAccepted())
{
if (qos == null)
return;
if (!string.IsNullOrEmpty(qos.SourceScript)
&& AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager)
&& configManager.GetConfigValue<bool>(ConfigKeysForCommon.EnableTestCoverage)
&& AzureSession.Instance.TryGetComponent<ITestCoverage>(nameof(ITestCoverage), out var testCoverage))
{
testCoverage.LogRawData(qos);
}
if (!IsMetricTermAccepted())
return;
if (isUsageMetricEnabled)
{
LogUsageEvent(qos);
@ -573,6 +583,8 @@ public class AzurePSQoSEvent
public string ModuleName { get; set; }
public string ModuleVersion { get; set; }
//Version of PowerShell runspace ($Host.Runspace.Version)
public string SourceScript { get; set; }
public int ScriptLineNumber { get; set; }
public string PSVersion { get; set; }
//Host version of PowerShell ($Host.Version) which can be customized by PowerShell wrapper
public string HostVersion { get; set; }