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

Users/srkidd/enable stream and file output #4829

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
aa7918b
Adding cmd option to enable both stream and log file output
srkidd Jun 3, 2024
3965ee6
Add timestamp to log line for local logs
srkidd Jun 4, 2024
9bde329
Fixing date format for log lines
srkidd Jun 4, 2024
2e6caa8
fixing the date formate to universal time for log lines
srkidd Jun 4, 2024
668764e
Merge branch 'master' into users/srkidd/enable-stream-and-file-output
srkidd Jun 4, 2024
712bb41
Merge pull request #1 from srkidd/users/srkidd/enable-stream-and-file…
srkidd Jun 4, 2024
c1d5b8d
Merge branch 'microsoft:master' into master
srkidd Jun 18, 2024
9136d6a
Merge branch 'microsoft:master' into users/srkidd/enable-stream-and-f…
srkidd Jun 18, 2024
2ac4f2e
Merge branch 'microsoft:master' into users/srkidd/enable-stream-and-f…
srkidd Jun 21, 2024
39e4068
Renaming enableLogOutput to reStreamLogsToFiles and fixing error hand…
srkidd Jun 21, 2024
440fb0d
Merge branch 'users/srkidd/enable-stream-and-file-output' of https://…
srkidd Jun 21, 2024
f1ea63d
Merge branch 'master' into users/srkidd/enable-stream-and-file-output
KonstantinTyukalov Jun 24, 2024
dd248a6
Adding strings for different locals.
srkidd Jun 24, 2024
69a5db9
Removing string
srkidd Jun 25, 2024
78e63f9
Adding loc key for error message
srkidd Jun 27, 2024
b6c638e
Merge branch 'master' into users/srkidd/enable-stream-and-file-output
KonstantinTyukalov Jun 28, 2024
10a0323
Merge branch 'master' into users/srkidd/enable-stream-and-file-output
srkidd Jul 23, 2024
5d20349
Merge branch 'master' into users/srkidd/enable-stream-and-file-output
srkidd Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Agent.Listener/CommandLine/ConfigureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class ConfigureAgent : ConfigureOrRemoveBase
[Option(Constants.Agent.CommandLine.Flags.DisableLogUploads)]
public bool DisableLogUploads { get; set; }

[Option(Constants.Agent.CommandLine.Flags.EnableLogOutput)]
public bool EnableLogOutput { get; set; }

[Option(Constants.Agent.CommandLine.Flags.MachineGroup)]
public bool MachineGroup { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions src/Agent.Listener/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ public bool GetDisableLogUploads()
return TestFlag(Configure?.DisableLogUploads, Constants.Agent.CommandLine.Flags.DisableLogUploads);
}

public bool GetEnableLogOutput()
{
return TestFlag(Configure?.EnableLogOutput, Constants.Agent.CommandLine.Flags.EnableLogOutput);
}

public bool Unattended()
{
if (TestFlag(GetConfigureOrRemoveBase()?.Unattended, Constants.Agent.CommandLine.Flags.Unattended))
Expand Down
11 changes: 10 additions & 1 deletion src/Agent.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,17 @@ public async Task ConfigureAsync(CommandSettings command)

agentSettings.NotificationSocketAddress = command.GetNotificationSocketAddress();

// Test to see if disableLogUpload and enabledLogOutput are both selected
if (command.GetDisableLogUploads() && command.GetEnableLogOutput())
{
Trace.Warning("You cannot use --disableloguploads and --enablelogoutput at the same time!");
throw new NotSupportedException();
}
KonstantinTyukalov marked this conversation as resolved.
Show resolved Hide resolved

agentSettings.DisableLogUploads = command.GetDisableLogUploads();

agentSettings.EnableLogOutput = command.GetEnableLogOutput();

agentSettings.AlwaysExtractTask = command.GetAlwaysExtractTask();

_store.SaveSettings(agentSettings);
Expand Down Expand Up @@ -736,7 +745,7 @@ private void CheckAgentRootDirectorySecure()
// Get info about root folder
DirectoryInfo dirInfo = new DirectoryInfo(rootDirPath);

// Get directory access control list
// Get directory access control list
DirectorySecurity directorySecurityInfo = dirInfo.GetAccessControl();
AuthorizationRuleCollection dirAccessRules = directorySecurityInfo.GetAccessRules(true, true, typeof(NTAccount));

Expand Down
28 changes: 23 additions & 5 deletions src/Agent.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public sealed class ExecutionContext : AgentService, IExecutionContext, IDisposa
private ExecutionTargetInfo _defaultStepTarget;
private ExecutionTargetInfo _currentStepTarget;
private bool _disableLogUploads;
private bool _enableLogOutput;
private string _buildLogsFolderPath;
private string _buildLogsFile;
private FileStream _buildLogsData;
Expand Down Expand Up @@ -180,8 +181,9 @@ public override void Initialize(IHostContext hostContext)
base.Initialize(hostContext);

_disableLogUploads = HostContext.GetService<IConfigurationStore>().GetSettings().DisableLogUploads;
_enableLogOutput = HostContext.GetService<IConfigurationStore>().GetSettings().EnableLogOutput;

if (_disableLogUploads)
if (_disableLogUploads || _enableLogOutput)
{
_buildLogsFolderPath = Path.Combine(hostContext.GetDiagDirectory(), _buildLogsFolderName);
Directory.CreateDirectory(_buildLogsFolderPath);
Expand Down Expand Up @@ -264,7 +266,7 @@ public void Start(string currentOperation = null)

_jobServerQueue.QueueTimelineRecordUpdate(_mainTimelineId, _record);

if (_disableLogUploads)
if (_disableLogUploads || _enableLogOutput)
{
var buildLogsJobFolder = Path.Combine(_buildLogsFolderPath, _mainTimelineId.ToString());
Directory.CreateDirectory(buildLogsJobFolder);
Expand All @@ -276,7 +278,15 @@ public void Start(string currentOperation = null)
_buildLogsData = new FileStream(_buildLogsFile, FileMode.CreateNew);
_buildLogsWriter = new StreamWriter(_buildLogsData, System.Text.Encoding.UTF8);

_logger.Write(StringUtil.Loc("BuildLogsMessage", _buildLogsFile));
if (_disableLogUploads)
{
_logger.Write(StringUtil.Loc("BuildLogsMessage", _buildLogsFile));
}
else
{
_logger.Write(StringUtil.Loc("LogOutputMessage", _buildLogsFile));
}

}
}

Expand All @@ -287,7 +297,7 @@ public TaskResult Complete(TaskResult? result = null, string currentOperation =
Result = result;
}

if (_disableLogUploads)
if (_disableLogUploads || _enableLogOutput)
{
_buildLogsWriter.Flush();
_buildLogsData.Flush();
Expand Down Expand Up @@ -717,9 +727,17 @@ public long Write(string tag, string inputMessage, bool canMaskSecrets = true)
{
totalLines = _logger.TotalLines + 1;

DateTime rightNow = DateTime.UtcNow;

if (_disableLogUploads)
{
_buildLogsWriter.WriteLine(message);
//Add date time stamp to log line
_buildLogsWriter.WriteLine("{0:O} {1}", rightNow, message);
}
else if (_enableLogOutput) {
//Add date time stamp to log line
_buildLogsWriter.WriteLine("{0:O} {1}", rightNow, message);
_logger.Write(message);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public string Fingerprint
[DataMember(EmitDefaultValue = false)]
public bool DisableLogUploads { get; set; }

[DataMember(EmitDefaultValue = false)]
public bool EnableLogOutput { get; set; }

[DataMember(EmitDefaultValue = false)]
public int PoolId { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.VisualStudio.Services.Agent/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public static class Flags
public const string GitUseSChannel = "gituseschannel";
public const string Help = "help";
public const string DisableLogUploads = "disableloguploads";
public const string EnableLogOutput = "enablelogoutput";
public const string MachineGroup = "machinegroup";
public const string Replace = "replace";
public const string NoRestart = "norestart";
Expand Down
3 changes: 3 additions & 0 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
" --acceptTeeEula macOS and Linux only. Accept the TEE end user license agreement.",
" --gitUseSChannel Windows only. Tell Git to use Windows' native cert store.",
" --alwaysExtractTask Perform an unzip for tasks for each pipeline step.",
" --disableLogUploads Don't stream or send console log output to the server. Instead, you may retrieve them from the agent host's filesystem after the job completes. NOTE: Cannot be used with --enableLogOutput, it will cause an error.",
" --enableLogOutput Stream or send console log output to the server as well as a log file on the agent host's filesystem. NOTE: Cannot be used with --disableLogUploads, it will cause an error.",
"",
"CLI-WIDTH-OPTIONS-(35-CHARS)-------CLI-WIDTH-DESCRIPTION-(70-CHARS)--------------------------------------",
"Startup options (Windows only):",
Expand Down Expand Up @@ -395,6 +397,7 @@
"ListenForJobs": "{0:u}: Listening for Jobs",
"LocalClockSkewed": "The local machine's clock may be out of sync with the server time by more than five minutes. Please sync your clock with your domain or internet time and try again.",
"LocalSystemAccountNotFound": "Cannot find local system account",
"LogOutputMessage": "The agent has enabled uploading logs as well as saving log to file. After the job completes, you can retrieve this step's logs at {0} on the agent.",
"Maintenance": "Maintenance",
"MaxHierarchyLevelReached": "Hierarchy level is more than supported limit {0}, truncating lower hierarchy.",
"MaxSubResultLimitReached": "Number of subresults in test case '{0}' is more than the supported limit of {1}, truncating remaining ones.",
Expand Down