Skip to content

Enable auth migration based on config refresh. #3786

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

Merged
merged 3 commits into from
Apr 3, 2025

Conversation

TingluoHuang
Copy link
Member

After refresh .credentials with the service, we can enable or disable auth migration based on whether authorizationurlv2 exists or not.

@TingluoHuang TingluoHuang requested a review from a team as a code owner April 3, 2025 00:50
@@ -37,6 +37,7 @@ public sealed class BrokerServer : RunnerService, IBrokerServer

public async Task ConnectAsync(Uri serverUri, VssCredentials credentials)
{
Trace.Entering();
Copy link
Member Author

Choose a reason for hiding this comment

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

add verbose trace.

@@ -306,6 +305,10 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
Trace.Error("Catch exception during get next message.");
Trace.Error(ex);

// clear out potential message for broker migration,
// in case the exception is thrown from get message from broker-listener.
message = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

in case we got migration message from pipelines, but fail to get message broker-listener.
we currently return the migration message to the caller which the caller don't know how to handle the migration message.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good find

@@ -50,7 +51,8 @@ public override void Initialize(IHostContext hostContext)
{
base.Initialize(hostContext);
_term = HostContext.GetService<ITerminal>();
_acquireJobThrottler = HostContext.CreateService<IErrorThrottler>();
Copy link
Member Author

Choose a reason for hiding this comment

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

we should always use GetService instead of CreateService for singleton service.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This was originally intended not to be a singleton. Why switch to singleton?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The error throttler helps us back off when encountering successive, non-retriable errors from /acquirejob.

Copy link
Member Author

@TingluoHuang TingluoHuang Apr 3, 2025

Choose a reason for hiding this comment

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

i didn't find any place we use IErrorThrottler outside of the Runner.cs, so i thought we only need one.
I guess, if the original idea is to create IErrorThrottler as needed, then CreateService make more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

i changed it back for now.

@@ -252,7 +254,7 @@ public async Task<int> ExecuteCommand(CommandSettings command)
}
}

RunnerSettings settings = configManager.LoadSettings();
_runnerSettings = configManager.LoadSettings();
Copy link
Member Author

Choose a reason for hiding this comment

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

make this a global variable, so we can reuse it later (next PR) without reloading it from disk.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: instance not global

Copy link
Collaborator

@ericsciple ericsciple Apr 3, 2025

Choose a reason for hiding this comment

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

Multiple methods throughout this class receive RunnerSettings as a parameter. Will those all switch to use the instance variable instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

nvm, i am going to switch back, the instance var might cause more changes...

}
else
{
HostContext.DeferAuthMigration(TimeSpan.FromDays(365), "Credential file does not contain authorizationUrlV2");
Copy link
Member Author

Choose a reason for hiding this comment

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

this is acting as disable the migration via FF from the service.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fuzzy on this detail. This PR seems fine for now. I will catch up on this detail on the next PR.

@@ -18,24 +18,21 @@ public sealed class BrokerMessageListenerL0
private readonly Mock<IBrokerServer> _brokerServer;
private readonly Mock<IRunnerServer> _runnerServer;
private readonly Mock<ICredentialManager> _credMgr;
private Mock<IConfigurationStore> _store;
Copy link
Member Author

Choose a reason for hiding this comment

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

we don't use this any more.

@@ -103,8 +103,8 @@ public async Task Delay(TimeSpan delay, CancellationToken token)
handler(this, new DelayEventArgs(delay, token));
}

// Delay zero
await Task.Delay(TimeSpan.Zero);
Copy link
Member Author

Choose a reason for hiding this comment

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

zero will make the test case stuck in case we use the HostContext.Delay in some background task.

ericsciple
ericsciple previously approved these changes Apr 3, 2025
@TingluoHuang TingluoHuang merged commit c1095ae into main Apr 3, 2025
9 checks passed
@TingluoHuang TingluoHuang deleted the users/tihuang/cleanup4 branch April 3, 2025 03:24
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.

2 participants