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 13 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.ReStreamLogsToFiles)]
public bool ReStreamLogsToFiles { 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 GetReStreamLogsToFiles()
{
return TestFlag(Configure?.ReStreamLogsToFiles, Constants.Agent.CommandLine.Flags.ReStreamLogsToFiles);
}

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

agentSettings.NotificationSocketAddress = command.GetNotificationSocketAddress();

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

agentSettings.DisableLogUploads = command.GetDisableLogUploads();

agentSettings.ReStreamLogsToFiles = command.GetReStreamLogsToFiles();

agentSettings.AlwaysExtractTask = command.GetAlwaysExtractTask();

_store.SaveSettings(agentSettings);
Expand Down Expand Up @@ -736,7 +744,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 _reStreamLogsToFiles;
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;
_reStreamLogsToFiles = HostContext.GetService<IConfigurationStore>().GetSettings().ReStreamLogsToFiles;

if (_disableLogUploads)
if (_disableLogUploads || _reStreamLogsToFiles)
{
_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 || _reStreamLogsToFiles)
{
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 || _reStreamLogsToFiles)
{
_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 (_reStreamLogsToFiles) {
//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 ReStreamLogsToFiles { get; set; }

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

Expand Down Expand Up @@ -132,7 +135,7 @@ public string Fingerprint

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

[DataMember(EmitDefaultValue = false)]
public bool DebugMode { 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 ReStreamLogsToFiles = "restreamlogstofiles";
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/de-DE/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
" --acceptTeeEula nur macOS und Linux. Akzeptiert den TEE-Endbenutzerlizenzvertrag.",
" --gitUseSChannel Nur Windows. Weist Git an, den nativen Zertifikatspeicher von Windows zu verwenden.",
" --alwaysExtractTask Führt eine Entzippen für Aufgaben für jeden Pipelineschritt aus.",
" --disableLogUploads Streamen oder senden Sie keine Konsolenprotokollausgaben an den Server. Stattdessen können Sie sie nach Abschluss des Auftrags aus dem Dateisystem des Agent-Hosts abrufen. HINWEIS: Kann nicht mit --reStreamLogsToFiles verwendet werden, da dies zu einem Fehler führt.",
" --reStreamLogsToFiles Streamen oder senden Sie die Konsolenprotokollausgabe an den Server sowie eine Protokolldatei im Dateisystem des Agent-Hosts. HINWEIS: Kann nicht mit --disableLogUploads verwendet werden, da dies zu einem Fehler führt.",
"",
"CLI-WIDTH-OPTIONS-(35-CHARS)-------CLI-WIDTH-DESCRIPTION-(70-CHARS)--------------------------------------",
"Startoptionen (nur Windows):",
Expand Down Expand Up @@ -394,6 +396,7 @@
"ListenForJobs": "{0:u}: Auf Aufträge lauschen",
"LocalClockSkewed": "Die Uhr des lokalen Computers weicht möglicherweise um mehr als fünf Minuten von der Serverzeit ab. Synchronisieren Sie Ihre Uhr mit Ihrer Domäne oder Internetzeit, und versuchen Sie es noch einmal.",
"LocalSystemAccountNotFound": "Das lokale Systemkonto wurde nicht gefunden.",
"LogOutputMessage": "Der Agent hat das Hochladen von Protokollen sowie das Speichern von Protokollen in einer Datei aktiviert. Nachdem der Job abgeschlossen ist, können Sie die Protokolle dieses Schritts unter {0} auf dem Agent abrufen.",
KonstantinTyukalov marked this conversation as resolved.
Show resolved Hide resolved
"Maintenance": "Wartung",
"MaxHierarchyLevelReached": "Die Hierarchieebene übersteigt den unterstützten Grenzwert von {0}. Niedrigere Hierarchie wird abgeschnitten.",
"MaxSubResultLimitReached": "Die Anzahl der Unterergebnisse im Testfall „{0}“ überschreitet den unterstützten Grenzwert von {1}. Die restlichen werden abgeschnitten.",
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 @@ -137,6 +137,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 --reStreamLogsToFiles, it will cause an error.",
" --reStreamLogsToFiles 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 @@ -396,6 +398,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
1 change: 1 addition & 0 deletions src/Misc/layoutbin/es-ES/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: Escuchando trabajos",
"LocalClockSkewed": "Es posible que el reloj de la máquina local no esté sincronizado con la hora del servidor con una diferencia de más de cinco minutos. Sincronice el reloj con la hora de su dominio o internet e inténtelo de nuevo.",
"LocalSystemAccountNotFound": "No se encuentra la cuenta del sistema local",
"LogOutputMessage": "El agente ha permitido cargar registros y guardarlos en un archivo. Una vez que se complete el trabajo, puede recuperar los registros de este paso en {0} en el agente.",
"Maintenance": "Mantenimiento",
"MaxHierarchyLevelReached": "El nivel de jerarquía es mayor que el límite admitido de {0}, se truncará la jerarquía inferior.",
"MaxSubResultLimitReached": "El número de subresultados en el caso de prueba \"{0}\" supera el límite admitido de {1}, truncando los restantes.",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/fr-FR/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u} : à l’écoute des travaux",
"LocalClockSkewed": "L’horloge de l’ordinateur local n’est peut-être pas synchronisée avec l’heure du serveur de plus de cinq minutes. Veuillez synchroniser votre horloge avec votre domaine ou l’heure Internet et réessayer.",
"LocalSystemAccountNotFound": "Compte système local introuvable",
"LogOutputMessage": "L'agent a activé le téléchargement des journaux ainsi que l'enregistrement du journal dans un fichier. Une fois la tâche terminée, vous pouvez récupérer les journaux de cette étape sur {0} sur l'agent.",
"Maintenance": "Maintenance",
"MaxHierarchyLevelReached": "Le niveau de hiérarchie est supérieur à la limite prise en charge {0}, troncation de la hiérarchie inférieure.",
"MaxSubResultLimitReached": "Le nombre de sous-résultats dans le cas de test '{0}' est supérieur à la limite prise en charge de {1}, ce qui tronque les autres.",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/it-IT/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: ascolto dei processi",
"LocalClockSkewed": "L'orologio del computer locale potrebbe non essere sincronizzato con l'ora del server di più di cinque minuti. Sincronizzare l'orologio con il dominio o l'ora Internet e riprovare.",
"LocalSystemAccountNotFound": "Impossibile trovare l'account di sistema locale",
"LogOutputMessage": "L'agente ha abilitato il caricamento dei registri e il salvataggio dei registri su file. Una volta completato il lavoro, puoi recuperare i registri di questo passaggio su {0} sull'agente.",
"Maintenance": "Manutenzione",
"MaxHierarchyLevelReached": "Il livello gerarchia è maggiore del limite supportato {0}. La gerarchia inferiore verrà troncata.",
"MaxSubResultLimitReached": "Il numero di risultati secondari in test case '{0}' è superiore al limite supportato di {1}, troncando quelli rimanenti.",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/ja-JP/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: ジョブをリッスンしています",
"LocalClockSkewed": "ローカル コンピューターの時計が、サーバー時刻と 5 分以上非同期である可能性があります。時計をドメインまたはインターネットの時刻と同期して、もう一度お試しください。",
"LocalSystemAccountNotFound": "ローカル システム アカウントが見つかりません",
"LogOutputMessage": "エージェントは、ログのアップロードとファイルへのログの保存を有効にしました。ジョブが完了すると、エージェントの {0} でこのステップのログを取得できます。",
"Maintenance": "メンテナンス",
"MaxHierarchyLevelReached": "階層レベルがサポートされている制限 {0} を超えているため、下位階層が切り捨てられます。",
"MaxSubResultLimitReached": "テスト ケース '{0}' のサブ結果の数が、サポートされている {1} の制限を超えています。残りの値は切り捨てられます。",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/ko-KR/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: 작업 수신 대기",
"LocalClockSkewed": "로컬 컴퓨터의 시계는 서버 시간과 5분 이상 동기화되지 않을 수 있습니다. 시계를 도메인 또는 인터넷 시간과 동기화하고 다시 시도하세요.",
"LocalSystemAccountNotFound": "로컬 시스템 계정을 찾을 수 없습니다",
"LogOutputMessage": "에이전트는 로그 업로드와 로그 파일 저장을 활성화했습니다. 작업이 완료된 후 에이전트의 {0}에서 이 단계의 로그를 검색할 수 있습니다.",
"Maintenance": "유지 관리",
"MaxHierarchyLevelReached": "계층 구조 수준이 지원되는 제한 {0}보다 많습니다. 낮은 계층 구조를 자릅니다.",
"MaxSubResultLimitReached": "테스트 케이스 '{0}'의 하위 결과 수가 지원되는 제한인 {1}개를 초과하여 나머지 결과를 자릅니다.",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/ru-RU/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: прослушивание заданий",
"LocalClockSkewed": "Часы локального компьютера могут быть не синхронизированы с серверным временем более чем на пять минут. Синхронизируйте часы с доменом или интернет-службой времени и повторите попытку.",
"LocalSystemAccountNotFound": "Не удалось найти учетную запись локальной системы",
"LogOutputMessage": "Агент включил загрузку журналов, а также сохранение журнала в файл. После завершения задания вы можете получить журналы этого шага в {0} на агенте.",
"Maintenance": "Обслуживание",
"MaxHierarchyLevelReached": "Уровень иерархии превышает поддерживаемый предел ({0}). Нижестоящая иерархия будет усечена.",
"MaxSubResultLimitReached": "Число вложенных результатов в тестовом случае ''{0}'' превышает поддерживаемый предел {1}, остальные удаляются.",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/zh-CN/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: 正在侦听作业",
"LocalClockSkewed": "本地计算机的时钟可能与服务器时间不同步,不同步的时间超过五分钟。请将时钟与域或 Internet 时间同步,然后重试。",
"LocalSystemAccountNotFound": "找不到本地系统帐户",
"LogOutputMessage": "代理已启用上传日志以及将日志保存到文件。作业完成后,您可以在代理上的 {0} 处检索此步骤的日志。",
"Maintenance": "维护",
"MaxHierarchyLevelReached": "层次结构级别已超过支持的限制 {0},导致较低的层次结构被截断。",
"MaxSubResultLimitReached": "测试用例 \"{0}\" 中的子结果数超过了支持上限 {1},正在截断剩余的子结果。",
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/zh-TW/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"ListenForJobs": "{0:u}: 正在聆聽工作",
"LocalClockSkewed": "本機電腦的時鐘可能與伺服器時間不同步 (可能超過五分鐘)。請將您的時鐘與網域或網際網路時間同步,然後再試一次。",
"LocalSystemAccountNotFound": "找不到本機系統帳戶",
"LogOutputMessage": "代理程式已啟用上傳日誌以及將日誌儲存到檔案。作業完成後,您可以在代理程式上的 {0} 處擷取此步驟的日誌。",
"Maintenance": "維修",
"MaxHierarchyLevelReached": "階層層級大於支援的限制 {0},因此會截斷較低的階層。",
"MaxSubResultLimitReached": "測試案例中的子結果數目 '{0}' 超過支援的限制 {1},正在截斷其餘的子結果。",
Expand Down