Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 476c99a

Browse files
stishkinstas
andauthored
use InterpolatedStringHandler to move values to CustomDimensions Tags instead of keeping them in the error message (#2450)
* use InterpolatedStringHandler to move values to CustomDimensions Tags instead of keeping them in the error message * log blob save raw response failure * add StringBuilder to CSharpExtensions Co-authored-by: stas <[email protected]>
1 parent b3748e4 commit 476c99a

File tree

80 files changed

+574
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+574
-539
lines changed

src/ApiService/ApiService/Functions/AgentCanSchedule.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
3030
var canScheduleRequest = request.OkV;
3131

3232
var node = await _context.NodeOperations.GetByMachineId(canScheduleRequest.MachineId);
33+
3334
if (node == null) {
34-
_log.Warning($"Unable to find node {canScheduleRequest.MachineId}");
35+
_log.Warning($"Unable to find {canScheduleRequest.MachineId:Tag:MachineId}");
3536
return await _context.RequestHandling.NotOk(
3637
req,
3738
new Error(
@@ -52,14 +53,14 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
5253
var workStopped = task == null || task.State.ShuttingDown();
5354

5455
if (workStopped) {
55-
_log.Info($"Work stopped {canScheduleRequest.MachineId}");
56+
_log.Info($"Work stopped for: {canScheduleRequest.MachineId:Tag:MachineId} and {canScheduleRequest.TaskId:Tag:TaskId}");
5657
allowed = false;
5758
}
5859

5960
if (allowed) {
6061
var scp = await _context.NodeOperations.AcquireScaleInProtection(node);
6162
if (!scp.IsOk) {
62-
_log.Warning($"Failed to acquire scale in protection due to {scp.ErrorV}");
63+
_log.Warning($"Failed to acquire scale in protection for: {node.MachineId:Tag:MachineId} in: {node.PoolName:Tag:PoolName} due to {scp.ErrorV:Tag:Error}");
6364
}
6465
allowed = scp.IsOk;
6566
}

src/ApiService/ApiService/Functions/AgentCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
3838
var envelope = new NodeCommandEnvelope(command, messageId);
3939
return await RequestHandling.Ok(req, new PendingNodeCommand(envelope));
4040
} else {
41-
_log.WithTag("Command", "GET").Verbose($"failed to find machine id {nodeCommand.MachineId}");
41+
_log.WithTag("HttpRequest", "GET").Verbose($"failed to find {nodeCommand.MachineId:Tag:MachineId}");
4242
return await RequestHandling.Ok(req, new PendingNodeCommand(null));
4343
}
4444
}
@@ -54,7 +54,7 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
5454
if (message != null) {
5555
await _context.NodeMessageOperations.Delete(message).IgnoreResult();
5656
} else {
57-
_log.WithTag("Command", "DELETE").Verbose($"failed to find machine id {nodeCommand.MachineId} for message {nodeCommand.MessageId}");
57+
_log.WithTag("HttpRequest", "DELETE").Verbose($"failed to find {nodeCommand.MachineId:Tag:MachineId} for {nodeCommand.MessageId:Tag:MessageId}");
5858
}
5959

6060
return await RequestHandling.Ok(req, new BoolResult(true));

src/ApiService/ApiService/Functions/AgentEvents.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
2929
}
3030

3131
var envelope = request.OkV;
32-
_log.Info($"node event: machine_id: {envelope.MachineId} event: {EntityConverter.ToJsonString(envelope)}");
32+
_log.WithTag("HttpRequest", "POST").Info($"node event: {envelope.MachineId:Tag:MachineId} {EntityConverter.ToJsonString(envelope):Tag:Event}");
3333

3434
var error = envelope.Event switch {
3535
NodeStateUpdate updateEvent => await OnStateUpdate(envelope.MachineId, updateEvent),
@@ -66,20 +66,20 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
6666
private async Async.Task<Error?> OnStateUpdate(Guid machineId, NodeStateUpdate ev) {
6767
var node = await _context.NodeOperations.GetByMachineId(machineId);
6868
if (node is null) {
69-
_log.Warning($"unable to process state update event. machine_id:{machineId} state event:{ev}");
69+
_log.Warning($"unable to process state update event. {machineId:Tag:MachineId} {ev:Tag:Event}");
7070
return null;
7171
}
7272

7373
if (ev.State == NodeState.Free) {
7474
if (node.ReimageRequested || node.DeleteRequested) {
75-
_log.Info($"stopping free node with reset flags: {machineId}");
75+
_log.Info($"stopping free node with reset flags: {machineId:Tag:MachineId}");
7676
// discard result: node not used after this point
7777
_ = await _context.NodeOperations.Stop(node);
7878
return null;
7979
}
8080

8181
if (await _context.NodeOperations.CouldShrinkScaleset(node)) {
82-
_log.Info($"stopping free node to resize scaleset: {machineId}");
82+
_log.Info($"stopping free node to resize scaleset: {machineId:Tag:MachineId}");
8383
// discard result: node not used after this point
8484
_ = await _context.NodeOperations.SetHalt(node);
8585
return null;
@@ -88,7 +88,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
8888

8989
if (ev.State == NodeState.Init) {
9090
if (node.DeleteRequested) {
91-
_log.Info($"stopping node (init and delete_requested): {machineId}");
91+
_log.Info($"stopping node (init and delete_requested): {machineId:Tag:MachineId}");
9292
// discard result: node not used after this point
9393
_ = await _context.NodeOperations.Stop(node);
9494
return null;
@@ -103,11 +103,11 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
103103
return null;
104104
}
105105

106-
_log.Info($"node state update: {machineId} from {node.State} to {ev.State}");
106+
_log.Info($"node state update: {machineId:Tag:MachineId} from {node.State:Tag:FromState} to {ev.State:Tag:ToState}");
107107
node = await _context.NodeOperations.SetState(node, ev.State);
108108

109109
if (ev.State == NodeState.Free) {
110-
_log.Info($"node now available for work: {machineId}");
110+
_log.Info($"node now available for work: {machineId:Tag:MachineId}");
111111
} else if (ev.State == NodeState.SettingUp) {
112112
if (ev.Data is NodeSettingUpEventData settingUpData) {
113113
if (!settingUpData.Tasks.Any()) {
@@ -124,7 +124,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
124124
Errors: new string[] { $"unable to find task: {taskId}" });
125125
}
126126

127-
_log.Info($"node starting task. machine_id: {machineId} job_id: {task.JobId} task_id: {task.TaskId}");
127+
_log.Info($"node starting task. {machineId:Tag:MachineId} {task.JobId:Tag:JobId} {task.TaskId:Tag:TaskId}");
128128

129129
// The task state may be `running` if it has `vm_count` > 1, and
130130
// another node is concurrently executing the task. If so, leave
@@ -142,7 +142,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
142142
State: NodeTaskState.SettingUp);
143143
var r = await _context.NodeTasksOperations.Replace(nodeTask);
144144
if (!r.IsOk) {
145-
_log.WithHttpStatus(r.ErrorV).Error($"Failed to replace node task {task.TaskId}");
145+
_log.WithHttpStatus(r.ErrorV).Error($"Failed to replace node task {task.TaskId:Tag:TaskId}");
146146
}
147147
}
148148
}
@@ -152,7 +152,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
152152
if (doneData.Error is not null) {
153153
var errorText = EntityConverter.ToJsonString(doneData);
154154
error = new Error(ErrorCode.TASK_FAILED, Errors: new string[] { errorText });
155-
_log.Error($"node 'done' with error: machine_id:{machineId}, data:{errorText}");
155+
_log.Error($"node 'done' {machineId:Tag:MachineId} - {errorText:Tag:Error}");
156156
}
157157
}
158158

@@ -208,15 +208,15 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
208208
State: NodeTaskState.Running);
209209
var r = await _context.NodeTasksOperations.Replace(nodeTask);
210210
if (!r.IsOk) {
211-
_log.WithHttpStatus(r.ErrorV).Error($"failed to replace node task {nodeTask.TaskId}");
211+
_log.WithHttpStatus(r.ErrorV).Error($"failed to replace node task {nodeTask.TaskId:Tag:TaskId}");
212212
}
213213

214214
if (task.State.ShuttingDown()) {
215-
_log.Info($"ignoring task start from node. machine_id:{machineId} job_id:{task.JobId} task_id:{task.TaskId} (state: {task.State})");
215+
_log.Info($"ignoring task start from node. {machineId:Tag:MachineId} {task.JobId:Tag:JobId} {task.TaskId:Tag:TaskId} ({task.State:Tag:State})");
216216
return null;
217217
}
218218

219-
_log.Info($"task started on node. machine_id:{machineId} job_id:{task.JobId} task_id:{task.TaskId}");
219+
_log.Info($"task started on node. {machineId:Tag:MachineId} {task.JobId:Tag:JobId} {task.TaskId:Tag:TaskId}");
220220
task = await _context.TaskOperations.SetState(task, TaskState.Running);
221221

222222
var taskEvent = new TaskEvent(
@@ -225,7 +225,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
225225
EventData: new WorkerEvent(Running: running));
226226
r = await _context.TaskEventOperations.Replace(taskEvent);
227227
if (!r.IsOk) {
228-
_log.WithHttpStatus(r.ErrorV).Error($"failed to replace taskEvent for task with id {taskEvent.TaskId}");
228+
_log.WithHttpStatus(r.ErrorV).Error($"failed to replace taskEvent {taskEvent.TaskId:Tag:TaskId}");
229229
}
230230

231231
return null;
@@ -255,15 +255,15 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
255255
};
256256

257257
if (done.ExitStatus.Success) {
258-
_log.Info($"task done. {task.JobId}:{task.TaskId} status:{done.ExitStatus}");
258+
_log.Info($"task done. {task.JobId:Tag:JobId}:{task.TaskId:Tag:TaskId} {done.ExitStatus:Tag:Status}");
259259
await _context.TaskOperations.MarkStopping(task);
260260

261261
// keep node if keep-on-completion is set
262262
if (task.Config.Debug?.Contains(TaskDebugFlag.KeepNodeOnCompletion) == true) {
263263
node = node with { DebugKeepNode = true };
264264
var r = await _context.NodeOperations.Replace(node);
265265
if (!r.IsOk) {
266-
_log.WithHttpStatus(r.ErrorV).Error($"keepNodeOnCompletion: failed to replace node {node.MachineId} when setting debug keep node to true");
266+
_log.WithHttpStatus(r.ErrorV).Error($"keepNodeOnCompletion: failed to replace node {node.MachineId:Tag:MachineId} when setting debug keep node to true");
267267
}
268268
}
269269
} else {
@@ -283,22 +283,22 @@ await _context.TaskOperations.MarkFailed(
283283
node = node with { DebugKeepNode = true };
284284
var r = await _context.NodeOperations.Replace(node);
285285
if (!r.IsOk) {
286-
_log.WithHttpStatus(r.ErrorV).Error($"keepNodeOnfFailure: failed to replace node {node.MachineId} when setting debug keep node to true");
286+
_log.WithHttpStatus(r.ErrorV).Error($"keepNodeOnfFailure: failed to replace node {node.MachineId:Tag:MachineId} when setting debug keep node to true");
287287
}
288288
}
289289
}
290290

291291
if (!node.DebugKeepNode) {
292292
var r = await _context.NodeTasksOperations.Delete(new NodeTasks(machineId, done.TaskId));
293293
if (!r.IsOk) {
294-
_log.WithHttpStatus(r.ErrorV).Error($"failed to deleting node task since DebugKeepNode is false");
294+
_log.WithHttpStatus(r.ErrorV).Error($"failed to deleting node task {done.TaskId:Tag:TaskId} for: {machineId:Tag:MachineId} since DebugKeepNode is false");
295295
}
296296
}
297297

298298
var taskEvent = new TaskEvent(done.TaskId, machineId, new WorkerEvent { Done = done });
299299
var r1 = await _context.TaskEventOperations.Replace(taskEvent);
300300
if (!r1.IsOk) {
301-
_log.WithHttpStatus(r1.ErrorV).Error($"failed to update task event for done task {done.TaskId}");
301+
_log.WithHttpStatus(r1.ErrorV).Error($"failed to update task event for done task {done.TaskId:Tag:TaskId}");
302302
}
303303
return null;
304304
}

src/ApiService/ApiService/Functions/AgentRegistration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
109109

110110
var version = uri["version"] ?? "1.0.0";
111111

112-
_log.Info($"registration request: machine_id: {machineId} pool_name: {poolName} scaleset_id: {scalesetId} version: {version}");
112+
_log.Info($"registration request: {machineId:Tag:MachineId} {poolName:Tag:PoolName} {scalesetId:Tag:ScalesetId} {version:Tag:Version}");
113113
var poolResult = await _context.PoolOperations.GetByName(poolName);
114114
if (!poolResult.IsOk) {
115115
return await _context.RequestHandling.NotOk(
@@ -136,7 +136,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
136136

137137
var r = await _context.NodeOperations.Replace(node);
138138
if (!r.IsOk) {
139-
_log.WithHttpStatus(r.ErrorV).WithTag("MachineId", node.MachineId.ToString()).Error("failed to replace node operations for node {MachineId}");
139+
_log.WithHttpStatus(r.ErrorV).Error($"failed to replace node operations for {node.MachineId:Tag:MachineId}");
140140
}
141141

142142
return await RequestHandling.Ok(req, await CreateRegistrationResponse(pool));

src/ApiService/ApiService/Functions/Containers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
7474
}
7575

7676
var delete = request.OkV;
77-
_logger.Info($"container - deleting {delete.Name}");
77+
_logger.Info($"deleting {delete.Name:Tag:ContainerName}");
7878
var container = await _context.Containers.FindContainer(delete.Name, StorageType.Corpus);
7979

8080
var deleted = false;
@@ -92,7 +92,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
9292
}
9393

9494
var post = request.OkV;
95-
_logger.Info($"container - creating {post.Name}");
95+
_logger.Info($"creating {post.Name:Tag:ContainerName}");
9696
var sas = await _context.Containers.CreateContainer(
9797
post.Name,
9898
StorageType.Corpus,

src/ApiService/ApiService/Functions/InstanceConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Async.Task<HttpResponseData> Post(HttpRequestData req) {
6161
await _context.ConfigOperations.Save(request.OkV.config, false, false);
6262
if (updateNsg) {
6363
await foreach (var nsg in _context.NsgOperations.ListNsgs()) {
64-
_log.Info($"Checking if nsg: {nsg.Data.Location!} ({nsg.Data.Name}) owned by OneFuzz");
64+
_log.Info($"Checking if nsg: {nsg.Data.Location!:Tag:Location} ({nsg.Data.Name:Tag:NsgName}) owned by OneFuzz");
6565
if (nsg.Data.Location! == nsg.Data.Name) {
6666
var result = await _context.NsgOperations.SetAllowedSources(new Nsg(nsg.Data.Location!, nsg.Data.Location!), request.OkV.config.ProxyNsgConfig!);
6767
if (!result.IsOk) {

src/ApiService/ApiService/Functions/Jobs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private async Task<HttpResponseData> Post(HttpRequestData req) {
7070
job = job with { Config = job.Config with { Logs = logContainerUri.ToString() } };
7171
var r = await _context.JobOperations.Insert(job);
7272
if (!r.IsOk) {
73-
_logTracer.WithHttpStatus(r.ErrorV).Error($"failed to insert job {job.JobId}");
73+
_logTracer.WithTag("HttpRequest", "POST").WithHttpStatus(r.ErrorV).Error($"failed to insert job {job.JobId:Tag:JobId}");
7474
}
7575
return await RequestHandling.Ok(req, JobResponse.ForJob(job));
7676
}
@@ -96,7 +96,7 @@ private async Task<HttpResponseData> Delete(HttpRequestData req) {
9696
job = job with { State = JobState.Stopping };
9797
var r = await _context.JobOperations.Replace(job);
9898
if (!r.IsOk) {
99-
_logTracer.WithHttpStatus(r.ErrorV).Error($"Failed to replace job {job.JobId}");
99+
_logTracer.WithTag("HttpRequest", "DELETE").WithHttpStatus(r.ErrorV).Error($"Failed to replace job {job.JobId:Tag:JobId}");
100100
}
101101
}
102102

src/ApiService/ApiService/Functions/Node.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
142142

143143
var r = await _context.NodeOperations.Replace(node);
144144
if (!r.IsOk) {
145-
_log.WithHttpStatus(r.ErrorV).Error($"Failed to replace node {node.MachineId}");
145+
_log.WithTag("HttpRequest", "POST").WithHttpStatus(r.ErrorV).Error($"Failed to replace node {node.MachineId:Tag:MachineId}");
146146
}
147147
return await RequestHandling.Ok(req, true);
148148
}
@@ -176,7 +176,7 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
176176
if (node.DebugKeepNode) {
177177
var r = await _context.NodeOperations.Replace(node with { DebugKeepNode = false });
178178
if (!r.IsOk) {
179-
_log.WithHttpStatus(r.ErrorV).Error($"Failed to replace node {node.MachineId}");
179+
_log.WithTag("HttpRequest", "DELETE").WithHttpStatus(r.ErrorV).Error($"Failed to replace node {node.MachineId:Tag:MachineId}");
180180
}
181181
}
182182

src/ApiService/ApiService/Functions/Notifications.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public Notifications(ILogTracer log, IEndpointAuthorization auth, IOnefuzzContex
1616
}
1717

1818
private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
19-
_log.Info("Notification search");
19+
_log.WithTag("HttpRequest", "GET").Info($"Notification search");
2020
var request = await RequestHandling.ParseUri<NotificationSearch>(req);
2121
if (!request.IsOk) {
2222
return await _context.RequestHandling.NotOk(req, request.ErrorV, "notification search");
@@ -32,7 +32,7 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
3232

3333

3434
private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
35-
_log.Info("adding notification hook");
35+
_log.WithTag("HttpRequest", "POST").Info($"adding notification hook");
3636
var request = await RequestHandling.ParseRequest<NotificationCreate>(req);
3737
if (!request.IsOk) {
3838
return await _context.RequestHandling.NotOk(req, request.ErrorV, "notification create");

src/ApiService/ApiService/Functions/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
114114
var updated = forwardResult.OkV with { ProxyId = proxy.ProxyId };
115115
var r = await _context.ProxyForwardOperations.Replace(updated);
116116
if (!r.IsOk) {
117-
_log.WithHttpStatus(r.ErrorV).Error($"failed to update proxy forward with machine id {updated.MachineId} with new proxy id {proxy.ProxyId}");
117+
_log.WithTag("HttpRequest", "POST").WithHttpStatus(r.ErrorV).Error($"failed to update proxy forward with {updated.MachineId:Tag:MachineId} with new {proxy.ProxyId:Tag:ProxyId}");
118118
}
119119
await _context.ProxyOperations.SaveProxyConfig(proxy);
120120
}

0 commit comments

Comments
 (0)