Skip to content

Commit aa75952

Browse files
committed
Merge remote-tracking branch 'origin/master' into Localization
2 parents 8b6eb71 + 3f88445 commit aa75952

File tree

11 files changed

+434
-206
lines changed

11 files changed

+434
-206
lines changed

src/Agent.Listener/Agent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ public async Task<int> ExecuteCommand(CommandSettings command)
216216
Trace.Info($"Set agent startup type - {startType}");
217217
HostContext.StartupType = startType;
218218

219+
bool debugModeEnabled = command.GetDebugMode();
220+
settings.DebugMode = debugModeEnabled;
221+
store.SaveSettings(settings);
222+
if (debugModeEnabled)
223+
{
224+
Trace.Warning("Agent is running in debug mode, don't use it in production");
225+
}
219226
if (PlatformUtil.RunningOnWindows)
220227
{
221228
if (store.IsAutoLogonConfigured())

src/Agent.Listener/CommandLine/RunAgent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ public class RunAgent : BaseCommand
1818

1919
[Option(Constants.Agent.CommandLine.Args.StartupType)]
2020
public string StartupType { get; set; }
21+
22+
[Option(Constants.Agent.CommandLine.Flags.DebugMode)]
23+
public bool DebugMode { get; set; }
2124
}
2225
}

src/Agent.Listener/CommandSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ public bool GetRunOnce()
544544
TestFlag(Run?.RunOnce, Constants.Agent.CommandLine.Flags.Once);
545545
}
546546

547+
public bool GetDebugMode()
548+
{
549+
return TestFlag(Run?.DebugMode, Constants.Agent.CommandLine.Flags.DebugMode);
550+
}
551+
547552
public bool GetDeploymentPool()
548553
{
549554
return TestFlag(Configure?.DeploymentPool, Constants.Agent.CommandLine.Flags.DeploymentPool);

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ public class AgentKnobs
199199
new EnvironmentKnobSource("VSTSAGENT_TRACE"),
200200
new BuiltInDefaultKnobSource(string.Empty));
201201

202+
public static readonly Knob DebugTask = new Knob(
203+
nameof(DebugTask),
204+
"If the agent executes a task which ID or name matches the value provided, it will run the task so that it will wait for debugger to attach",
205+
new EnvironmentKnobSource("VSTSAGENT_DEBUG_TASK"),
206+
new BuiltInDefaultKnobSource(string.Empty));
207+
202208
public static readonly Knob DumpJobEventLogs = new Knob(
203209
nameof(DumpJobEventLogs),
204210
"If true, dump event viewer logs",

src/Agent.Worker/Handlers/NodeHandler.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,21 @@ public async Task RunAsync()
224224
var sigtermTimeout = TimeSpan.FromMilliseconds(AgentKnobs.ProccessSigtermTimeout.GetValue(ExecutionContext).AsInt());
225225
var useGracefulShutdown = AgentKnobs.UseGracefulProcessShutdown.GetValue(ExecutionContext).AsBoolean();
226226

227+
var configStore = HostContext.GetService<IConfigurationStore>();
228+
var agentSettings = configStore.GetSettings();
229+
if (agentSettings.DebugMode)
230+
{
231+
var debugTask = AgentKnobs.DebugTask.GetValue(ExecutionContext).AsString();
232+
if (!string.IsNullOrEmpty(debugTask))
233+
{
234+
if (string.Equals(Task?.Id.ToString("D"), debugTask, StringComparison.OrdinalIgnoreCase) || string.Equals(Task?.Name, debugTask, StringComparison.OrdinalIgnoreCase))
235+
{
236+
arguments = $"--inspect-brk {arguments}";
237+
}
238+
}
239+
}
240+
241+
227242
try
228243
{
229244
// Execute the process. Exit code 0 should always be returned.

src/Agent.Worker/JobRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
113113

114114
//Start Resource Diagnostics if enabled in the job message
115115
jobContext.Variables.TryGetValue("system.debug", out var systemDebug);
116+
116117
resourceDiagnosticManager = HostContext.GetService<IResourceMetricsManager>();
118+
resourceDiagnosticManager.SetContext(jobContext);
117119

118120
if (string.Equals(systemDebug, "true", StringComparison.OrdinalIgnoreCase))
119121
{
120-
resourceDiagnosticManager.Setup(jobContext);
121-
_ = resourceDiagnosticManager.RunDebugResourceMonitor();
122+
_ = resourceDiagnosticManager.RunDebugResourceMonitorAsync();
122123
}
123124

124125
agentShutdownRegistration = HostContext.AgentShutdownToken.Register(() =>
@@ -422,7 +423,6 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
422423
legacyTaskConnection?.Dispose();
423424
taskConnection?.Dispose();
424425
jobConnection?.Dispose();
425-
resourceDiagnosticManager?.Dispose();
426426

427427
await ShutdownQueue(throwOnFailure: false);
428428
}

0 commit comments

Comments
 (0)