Skip to content

Commit f658365

Browse files
author
Oleksii Kononenko
committed
Merged PR 722185: Revert "Merged PR 718998: Revert "Merged PR 717355: Send ETW events on symbol...
Merge the BSI change back in. Related work items: #2060729
1 parent 92abec7 commit f658365

File tree

2 files changed

+76
-38
lines changed

2 files changed

+76
-38
lines changed

Public/Src/Tools/SymbolDaemon/SymbolDaemon.cs

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
using BuildXL.Ipc.ExternalApi;
1616
using BuildXL.Ipc.Interfaces;
1717
using BuildXL.Storage;
18-
using BuildXL.Utilities.Core;
18+
using BuildXL.Tracing.CloudBuild;
1919
using BuildXL.Utilities.CLI;
20+
using BuildXL.Utilities.Core;
2021
using BuildXL.Utilities.Core.Tasks;
2122
using Microsoft.VisualStudio.Services.Common;
2223
using Microsoft.VisualStudio.Services.Symbol.App.Core.Tracing;
@@ -160,7 +161,7 @@ public sealed class SymbolDaemon : ServicePipDaemon.FinalizedByCreatorServicePip
160161
IsRequired = false,
161162
DefaultValue = true,
162163
});
163-
164+
164165
internal static readonly StrOption PersonalAccessTokenEnv = RegisterSymbolConfigOption(new StrOption("PersonalAccessTokenEnv")
165166
{
166167
ShortName = "patenv",
@@ -730,20 +731,11 @@ internal static void EnsureCommandsInitialized()
730731
/// </summary>
731732
protected override async Task<IIpcResult> DoCreateAsync(string name = null)
732733
{
733-
// TODO(olkonone): add logging
734-
Request createRequestResult;
735-
736-
try
737-
{
738-
createRequestResult = await InternalCreateAsync();
739-
}
740-
catch (Exception e)
741-
{
742-
return new IpcResult(IpcResultStatus.GenericError, e.DemystifyToString());
743-
}
734+
var dropCreationEvent = await HandleResultAndSendSymbolEtwEventAsync(InternalCreateAsync());
744735

745-
// get and return RequestId ?
746-
return IpcResult.Success(I($"Symbol request '{RequestName}' created (assigned request ID: '{createRequestResult.Id}')."));
736+
return dropCreationEvent.Succeeded
737+
? IpcResult.Success(I($"Symbol request '{RequestName}' created (url: '{dropCreationEvent.DropUrl}')."))
738+
: new IpcResult(IpcResultStatus.GenericError, dropCreationEvent.ErrorMessage);
747739
}
748740

749741
/// <summary>
@@ -777,19 +769,11 @@ private async Task<IIpcResult> AddSymbolFileAsync(SymbolFile file)
777769
/// </summary>
778770
protected override async Task<IIpcResult> DoFinalizeAsync()
779771
{
780-
// TODO(olkonone): add logging
781-
Request finalizeRequestResult;
782-
783-
try
784-
{
785-
finalizeRequestResult = await InternalFinalizeAsync();
786-
}
787-
catch (Exception e)
788-
{
789-
return new IpcResult(IpcResultStatus.GenericError, e.DemystifyToString());
790-
}
772+
var dropFinalizationEvent = await HandleResultAndSendSymbolEtwEventAsync(InternalFinalizeAsync());
791773

792-
return IpcResult.Success(I($"Symbol request '{RequestName}' finalized; the request expires on '{finalizeRequestResult.ExpirationDate}'."));
774+
return dropFinalizationEvent.Succeeded
775+
? IpcResult.Success(I($"Symbol request '{RequestName}' finalized."))
776+
: new IpcResult(IpcResultStatus.GenericError, dropFinalizationEvent.ErrorMessage);
793777
}
794778

795779
/// <nodoc />
@@ -805,25 +789,42 @@ public override void Dispose()
805789
base.Dispose();
806790
}
807791

808-
private async Task<Request> InternalCreateAsync()
792+
private async Task<DropCreationEvent> InternalCreateAsync()
809793
{
810794
var symbolClient = await m_symbolServiceClientTask;
811795
var result = await symbolClient.CreateAsync();
812796

813797
Contract.Assert(result.Status == RequestStatus.Created);
814798

815-
return result;
799+
var serializedResult = SymbolRequesToString(result);
800+
m_logger.Info($"CreateAsync completed:{Environment.NewLine}{serializedResult}");
801+
802+
return new DropCreationEvent()
803+
{
804+
Succeeded = true,
805+
DropUrl = result.Url.ToString(),
806+
// For Symbols, expiration is set during finalization, so we are using a value we will be assigning later.
807+
DropExpirationInDays = (int)SymbolConfig.Retention.TotalDays,
808+
AdditionalInformation = serializedResult
809+
};
816810
}
817811

818-
private async Task<Request> InternalFinalizeAsync()
812+
private async Task<DropFinalizationEvent> InternalFinalizeAsync()
819813
{
820814
var symbolClient = await m_symbolServiceClientTask;
821815
var result = await symbolClient.FinalizeAsync();
822816

823817
Contract.Assert(result.Status == RequestStatus.Sealed);
824818
Contract.Assert(result.ExpirationDate.HasValue);
825819

826-
return result;
820+
var serializedResult = SymbolRequesToString(result);
821+
m_logger.Info($"FinalizeAsync completed:{Environment.NewLine}{serializedResult}");
822+
823+
return new DropFinalizationEvent()
824+
{
825+
Succeeded = true,
826+
DropUrl = result.Url.ToString(),
827+
};
827828
}
828829

829830
private async Task ReportStatisticsAsync()
@@ -870,5 +871,46 @@ private async Task ReportStatisticsAsync()
870871
m_logger.Warning("No stats recorded by symbol client of type " + symbolClient.GetType().Name);
871872
}
872873
}
874+
875+
private async Task<T> HandleResultAndSendSymbolEtwEventAsync<T>(Task<T> task) where T : DropOperationBaseEvent
876+
{
877+
var sw = Stopwatch.StartNew();
878+
T dropEvent;
879+
try
880+
{
881+
dropEvent = await task;
882+
}
883+
catch (Exception e)
884+
{
885+
dropEvent = Activator.CreateInstance<T>();
886+
dropEvent.Succeeded = false;
887+
dropEvent.ErrorMessage = e.DemystifyToString();
888+
// For symbols, url is something that is only defined for successful operations
889+
// (it's based on a requestId which is not available until successful execution of 'symbol create').
890+
dropEvent.DropUrl = null;
891+
}
892+
893+
// common properties: execution time, drop type
894+
dropEvent.ElapsedTimeTicks = sw.ElapsedTicks;
895+
dropEvent.DropType = "SymbolIndex";
896+
897+
// send event
898+
m_etwLogger.Log(dropEvent);
899+
900+
return dropEvent;
901+
}
902+
903+
private static string SymbolRequesToString(Request request)
904+
{
905+
try
906+
{
907+
return request.ToJson();
908+
}
909+
catch (Exception e)
910+
{
911+
// The value is only used for debugging, so it's not a big deal if we fail to create the string.
912+
return $"Failed to serialized Request. Exception: {e}";
913+
}
914+
}
873915
}
874916
}

Public/Src/Tools/SymbolDaemon/VsoSymbolClient.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@
1111
using BuildXL.Ipc.Common;
1212
using BuildXL.Ipc.ExternalApi;
1313
using BuildXL.Ipc.Interfaces;
14-
using BuildXL.Utilities.Core;
1514
using BuildXL.Utilities.Authentication;
16-
using BuildXL.Utilities.Collections;
17-
using BuildXL.Utilities.ParallelAlgorithms;
15+
using BuildXL.Utilities.Core;
1816
using BuildXL.Utilities.Core.Tasks;
19-
using BuildXL.Utilities.Tracing;
20-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
17+
using BuildXL.Utilities.ParallelAlgorithms;
2118
using Microsoft.VisualStudio.Services.BlobStore.Common;
2219
using Microsoft.VisualStudio.Services.Common;
2320
using Microsoft.VisualStudio.Services.Content.Common;
24-
using Microsoft.VisualStudio.Services.Content.Common.Authentication;
2521
using Microsoft.VisualStudio.Services.Content.Common.Tracing;
2622
using Microsoft.VisualStudio.Services.Symbol.App.Core;
2723
using Microsoft.VisualStudio.Services.Symbol.App.Core.Telemetry;
@@ -471,7 +467,7 @@ public async Task<Request> FinalizeAsync(CancellationToken token)
471467
var result = await m_symbolClient.FinalizeRequestAsync(
472468
RequestId,
473469
ComputeExpirationDate(m_config.Retention),
474-
// isUpdateOperation == true => request will be marked as 'Sealed',
470+
// isUpdateOperation != true => request will be marked as 'Sealed',
475471
// i.e., no more DebugEntries could be added to it
476472
isUpdateOperation: false,
477473
token);

0 commit comments

Comments
 (0)