-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proxy audit log and other assorted fixes (#8781)
* Use a unified lock for all access to a recording. sanitizers or recording entries. * Creating an audit log so we can see raw associated information for important events about a specific recording. * obtain a lock before stopping playback, ensuring that ongoing writes in other threads won't be broken --------- Co-authored-by: semick-dev <[email protected]>
- Loading branch information
1 parent
3c8f30f
commit 920afb2
Showing
14 changed files
with
306 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Sdk.Tools.TestProxy.Common; | ||
using Azure.Sdk.Tools.TestProxy.Common.Exceptions; | ||
using Azure.Sdk.Tools.TestProxy.Store; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Sdk.Tools.TestProxy | ||
{ | ||
[ApiController] | ||
[Route("[controller]/[action]")] | ||
public sealed class Audit : ControllerBase | ||
{ | ||
private readonly RecordingHandler _recordingHandler; | ||
|
||
public Audit(RecordingHandler recordingHandler) | ||
{ | ||
_recordingHandler = recordingHandler; | ||
} | ||
|
||
[HttpGet] | ||
public async Task Logs() | ||
{ | ||
|
||
var allAuditSessions = _recordingHandler.RetrieveOngoingAuditLogs(); | ||
allAuditSessions.AddRange(_recordingHandler.AuditSessions.Values); | ||
|
||
StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
foreach (var auditLogQueue in allAuditSessions) { | ||
while (auditLogQueue.TryDequeue(out var logItem)) | ||
{ | ||
stringBuilder.Append(logItem.ToCsvString() + Environment.NewLine); | ||
} | ||
} | ||
|
||
Response.ContentType = "text/plain"; | ||
|
||
await Response.WriteAsync(stringBuilder.ToString()); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/AuditLogItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
|
||
namespace Azure.Sdk.Tools.TestProxy.Common | ||
{ | ||
public class AuditLogItem | ||
{ | ||
public string RecordingId { get; set; } | ||
|
||
public DateTime Timestamp { get; set; } | ||
|
||
public string Uri { get; set; } | ||
|
||
public string Verb { get; set; } | ||
|
||
public string Message { get; set; } | ||
|
||
public AuditLogItem(string recordingId, string requestUri, string requestMethod) { | ||
RecordingId = recordingId; | ||
Timestamp = DateTime.UtcNow; | ||
|
||
Uri = requestUri; | ||
Verb = requestMethod; | ||
} | ||
|
||
public string ToCsvString() | ||
{ | ||
return $"{RecordingId},{Timestamp.ToString("o")},{Verb},{Uri},{Message}"; | ||
} | ||
|
||
public AuditLogItem(string recordingId, string message) | ||
{ | ||
RecordingId = recordingId; | ||
Timestamp = DateTime.UtcNow; | ||
|
||
Message = message; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.