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

[DO NOT REVIEW] MSI V2 #5001

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[DO NOT REVIEW] MSI V2 #5001

wants to merge 1 commit into from

Conversation

gladjohn
Copy link
Contributor

[DO NOT REVIEW] MSI V2

/// <summary>
/// Resets the cached managed identity source. Used only for testing purposes.
/// </summary>
internal static void ResetManagedIdentitySourceCache()
Copy link
Member

Choose a reason for hiding this comment

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

I think this will need to be made public for Azure SDK to test. And it'd be better to have a "ResetStaticCaches" general API, like our tests currently do, which reset everything.

Copy link
Member

Choose a reason for hiding this comment

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

i.e. see the logic in TestCommon.ResetInternalStaticCaches();

@@ -30,6 +30,9 @@ public class ServiceFabricTests
public void TestInitialize()
{
TestCommon.ResetInternalStaticCaches();
Copy link
Member

Choose a reason for hiding this comment

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

The TestBase class already calls TestCommon.ResetInternalStaticCaches();

@@ -37,6 +37,13 @@ public class ManagedIdentityTests : TestBase
internal const string ExpectedErrorCode = "ErrorCode";
internal const string ExpectedCorrelationId = "Some GUID";

[TestInitialize]
Copy link
Member

Choose a reason for hiding this comment

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

See TestCommon.ResetInternalStaticCaches() - just include it it there.


namespace Microsoft.Identity.Client.ManagedIdentity
{
internal interface IProbe
Copy link
Member

Choose a reason for hiding this comment

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

The only reason to introduce an interface is if you're going to mock it, but it doesn't seem to be the case here. You don't need to mock this object, as you can rely on HTTP mocking.

}
}

internal class ProbeResult
Copy link
Member

Choose a reason for hiding this comment

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

Seems to be more like a general purpose class "SuccessAndErrorMessage". I would also not use a class here, but a struct, to avoid heap allocations.

}

_logger.Verbose(() => "[Probe] Credential endpoint not supported.");
return ProbeResult.Failure("Credential endpoint not supported.");
Copy link
Member

Choose a reason for hiding this comment

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

If you're just using static messages, I don't see the point of "ProbeResult" at all.

return ProbeResult.Success();
}

_logger.Verbose(() => "[Probe] Credential endpoint not supported.");
Copy link
Member

Choose a reason for hiding this comment

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

You will need a lot more logging here, to find out why the probe failed.

private const string ProbeBody = ".";
private const string ImdsHeader = "IMDS/";
private static readonly SemaphoreSlim s_lock = new(1);
private static ProbeResult s_cachedResult;
Copy link
Member

@bgavrilMS bgavrilMS Nov 20, 2024

Choose a reason for hiding this comment

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

We had a lot of problems with static region auto-discovery, which uses a similar concept.

  1. Should the HTTP call fail after some time? (it does in region ... 2 seconds)
  2. Are you sure that probe failure really means endpoint not available? Could the probe fail for other reasons?
  3. should the probe (HTTP call) be retried? How often / for how long?
  4. should we "default" to credential endpoint? it seems more widespread?

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