Skip to content

Commit a03fea2

Browse files
committed
add IConfigManagerWithEvents
1 parent c4f1529 commit a03fea2

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

src/Authentication.Abstractions/Authentication.Abstractions.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454

5555
<ItemGroup>
5656
<None Include="..\..\LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="" />
57-
<Folder Include="Models\" />
5857
</ItemGroup>
5958

6059
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
2+
using Microsoft.Azure.PowerShell.Common.Config;
3+
4+
using System;
5+
6+
namespace Microsoft.Azure.Commands.Common.Authentication.Config
7+
{
8+
public interface IConfigManagerWithEvents: IConfigManager
9+
{
10+
event EventHandler<ConfigEventArgs> ConfigRead;
11+
event EventHandler<ConfigEventArgs> ConfigUpdated;
12+
event EventHandler<ConfigEventArgs> ConfigCleared;
13+
}
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
6+
{
7+
public class ConfigEventArgs : EventArgs, IExtensibleModel
8+
{
9+
public string ConfigKey { get; }
10+
11+
public string ConfigValue { get; }
12+
13+
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>();
14+
15+
public ConfigEventArgs(string configKey, string configValue)
16+
{
17+
ConfigKey = configKey;
18+
ConfigValue = configValue;
19+
}
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
6+
{
7+
public class ConfigReadEventArgs : ConfigEventArgs
8+
{
9+
public string ConfigTelemetryKey { get; }
10+
11+
public ConfigReadEventArgs(string configKey, string configValue) : this(configKey, configKey, configValue)
12+
{
13+
}
14+
15+
public ConfigReadEventArgs(string configKey, string configTelemetryKey, string configValue) : base(configKey, configValue)
16+
{
17+
ConfigTelemetryKey = configTelemetryKey;
18+
}
19+
}
20+
}

src/Common/AzurePSCmdlet.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
18+
using Microsoft.Azure.Commands.Common.Authentication.Config;
1719
using Microsoft.Azure.PowerShell.Common.Config;
1820
using Microsoft.Azure.PowerShell.Common.Share.Survey;
1921
using Microsoft.Azure.PowerShell.Common.UpgradeNotification;
@@ -522,6 +524,25 @@ protected void WriteSurvey()
522524
}
523525
}
524526

527+
528+
private void AddTelemetryForConfig()
529+
{
530+
// attach config read event handler to add config telemetry
531+
AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager);
532+
if (configManager is IConfigManagerWithEvents cm)
533+
{
534+
cm.ConfigRead += OnConfigReaded;
535+
}
536+
}
537+
538+
private void OnConfigReaded(object sender, ConfigEventArgs args)
539+
{
540+
if (!_qosEvent.ConfigMetrics.ContainsKey(args.ConfigKey) && args is ConfigReadEventArgs readEventArgs)
541+
{
542+
_qosEvent.ConfigMetrics[readEventArgs.ConfigKey] = new ConfigMetrics(readEventArgs.ConfigTelemetryKey, readEventArgs.ConfigValue.ToString());
543+
}
544+
}
545+
525546
protected new void ThrowTerminatingError(ErrorRecord errorRecord)
526547
{
527548
FlushDebugMessages();
@@ -546,7 +567,8 @@ protected void WriteSurvey()
546567
base.WriteObject(sendToPipeline, enumerateCollection);
547568
}
548569

549-
private void SanitizeOutput(object sendToPipeline)
570+
571+
private void SanitizeOutput(object sendToPipeline)
550572
{
551573
if (OutputSanitizer?.RequireSecretsDetection == true)
552574
{
@@ -772,6 +794,8 @@ protected virtual void InitializeQosEvent()
772794
}
773795

774796
_qosEvent.SanitizerInfo = new SanitizerTelemetry(OutputSanitizer?.RequireSecretsDetection == true);
797+
798+
AddTelemetryForConfig();
775799
}
776800

777801
private void RecordDebugMessages()

0 commit comments

Comments
 (0)