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

Add Interface to Send Auth Info to Telemetry #421

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

msJinLei
Copy link
Contributor

@msJinLei msJinLei commented Jun 12, 2024

  • The info added

    • auth-info-head-tokencredentialname
    • auth-info-head-authenticationsuccess
    • auth-info-head-tokencacheenabled
  • Example To update later

image

@msJinLei msJinLei force-pushed the jinlei/telemetry branch 2 times, most recently from eeb4c86 to ff84672 Compare June 17, 2024 02:35
Copy link
Member

@isra-fel isra-fel left a comment

Choose a reason for hiding this comment

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

  1. 1* Cmdlet telemetry : N * auth telemetry. Conclusion: data structure => array, but only 1 element. Todo: test if array is OK to be stored in kusto?
  2. telemetry key naming convention. Conclusion: use dash. General conclusion: ?
  3. Scope. Can we leverage MSAL telemetry? Todo: remove AuthorityUri. Consider adding correlation ID later. Consider enable telemetry of -Environment parameter.
  4. leverage Beisi & Lei's design. Conclusion: not much.
  5. Codegen => Todo: next sprint. Create task.
  6. TokenCacheEnabled => nice to have. Consider risk & effort of testing.

src/Authentication.Abstractions/AuthenticationInfo.cs Outdated Show resolved Hide resolved
/// <summary>
/// Authentication process succeed or not.
/// </summary>
public bool AuthenticationSuccess { get; set; } = false;
Copy link
Member

Choose a reason for hiding this comment

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

Why presuming it false? Or does it even matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prefer to set it as negative result biased.

TokenCredentialName = null;
}

public AuthenticationInfo(IAuthenticationInfo other, bool? isSuccess = null)
Copy link
Member

Choose a reason for hiding this comment

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

Why is isSuccess bool? ? In what case will it be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is isSuccess bool? ? In what case will it be null?

If it is null, use the value in other. The case doesn't exist in current code.

/// <summary>
/// Get the information to be recorded in Telemetry
/// </summary>
IList<IAuthenticationInfo> GetDataForTelemetry();
Copy link
Member

Choose a reason for hiding this comment

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

Updating a core interface can be risky. We must

  1. Update all implementation of this interface. I believe there's one in Accounts and another in Accounts' tests.
  2. Test collaboration of new Accounts and older version of service modules, especially if they use this interface.

src/Common/AzurePSCmdlet.cs Outdated Show resolved Hide resolved
src/Common/MetricHelper.cs Outdated Show resolved Hide resolved
src/Common/MetricHelper.cs Outdated Show resolved Hide resolved
@msJinLei msJinLei force-pushed the jinlei/telemetry branch 3 times, most recently from ce45e53 to 39e6304 Compare July 26, 2024 08:14
@msJinLei msJinLei force-pushed the jinlei/telemetry branch 4 times, most recently from 9f1fa26 to eabb4e3 Compare August 7, 2024 05:51
@msJinLei msJinLei force-pushed the jinlei/telemetry branch 5 times, most recently from 9174668 to e4b4dc9 Compare August 18, 2024 22:38
@msJinLei msJinLei force-pushed the jinlei/telemetry branch 2 times, most recently from a693ddf to 4574c39 Compare August 20, 2024 13:24
@msJinLei msJinLei force-pushed the jinlei/telemetry branch 4 times, most recently from 9415a08 to 662702c Compare August 21, 2024 02:19
@msJinLei
Copy link
Contributor Author

No change since last review

  • MetricHelper
  • AuthTelemetryRecord

@msJinLei msJinLei marked this pull request as ready for review August 21, 2024 03:05
@msJinLei
Copy link
Contributor Author

1* Cmdlet telemetry : N * auth telemetry. Conclusion: data structure => array, but only 1 element. Todo: test if array is OK to be stored in kusto?

Cannot use array directly, the current solution is to expand the first (most important) authentication telemetry record and serialize the other parts into a json string

telemetry key naming convention. Conclusion: use dash. General conclusion: ?

Scope. Can we leverage MSAL telemetry? Todo: remove AuthorityUri. Consider adding correlation ID later. Consider enable telemetry of -Environment parameter.
CorrelationId is added but not way to get id from MSAL, need MSAL team to support

leverage Beisi & Lei's design. Conclusion: not much.

Codegen => Todo: next sprint. Create task.
Done, need more test

TokenCacheEnabled => nice to have. Consider risk & effort of testing.
removed

@msJinLei msJinLei requested a review from isra-fel August 21, 2024 03:09
/// </summary>
public class AzureCmdletContext : ICmdletContext
{
private string cmdletId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private string cmdletId;
private string _cmdletId;

suggest using '_' as the prefix of private field.

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 both private data members that start with lower case and "_". Let get a unified decision for it.

@@ -292,6 +292,20 @@ public void SetPSHost(PSHost host)
{
}

private static void PopulateAuthenticationPropertiesFromQos(AuthenticationTelemetryData telemetry, IDictionary<string, string> eventProperties)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static void PopulateAuthenticationPropertiesFromQos(AuthenticationTelemetryData telemetry, IDictionary<string, string> eventProperties)
private static void PopulateAuthenticationPropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)

because the naming of this function is ...FromQos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will also discuss with yeming about the naming

/// <param name="cmdletContext">The cmdlet context called from</param>
/// <returns>A client properly authenticated in the given context, properly configured for use with Azure PowerShell,
/// targeting the given named endpoint in the targeted environment</returns>
TClient CreateArmClient<TClient>(IAzureContext context, string endpoint, ICmdletContext cmdletContext) where TClient : ServiceClient<TClient>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why creating an ArmClient needs cmdletContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of partners use Arm Client to handle the authentication. If we want to collect authentication telemetry from their cmdlets, a good way is to add cmdlet context here.
Also the CmdletContext can be treated as the same status as AzureContext. We can pass them both in the same interface.

var record = telemetry?.Head;
if (record != null)
{
eventProperties[$"{AuthTelemetryRecord.AuthTelemetryPropertyHeadPrefix}-{nameof(record.TokenCredentialName).ToLower()}"] = record.TokenCredentialName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move out of metric helper

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.

3 participants