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

Add another truncation case #3075

Merged
merged 5 commits into from
May 2, 2023
Merged
Changes from 3 commits
Commits
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
23 changes: 21 additions & 2 deletions src/ApiService/ApiService/onefuzzlib/Events.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Azure;
using Azure.Storage.Sas;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;

Expand Down Expand Up @@ -47,8 +48,26 @@ public Events(ILogTracer log, IOnefuzzContext context) {
}

public virtual async Async.Task QueueSignalrEvent(DownloadableEventMessage message) {
var ev = new SignalREvent("events", new List<DownloadableEventMessage>() { message });
await _queue.SendMessage("signalr-events", JsonSerializer.Serialize(ev, _options), StorageType.Config);
var tags = new (string, string)[] {
("event_type", message.EventType.ToString()),
("event_id", message.EventId.ToString())
};
try {
var ev = new SignalREvent("events", new List<DownloadableEventMessage>() { message });
await _queue.SendMessage("signalr-events", JsonSerializer.Serialize(ev, _options), StorageType.Config);
chkeita marked this conversation as resolved.
Show resolved Hide resolved
} catch (RequestFailedException ex) {
if (ex.Message.Contains("The request body is too large") && message.Event is ITruncatable<BaseEvent> truncatableEvent) {
_log.WithTags(tags).Warning($"The EventMessage was too large for Azure Queue. Truncating event data and trying again.");
message = message with {
Event = truncatableEvent.Truncate(1000)
};
var ev = new SignalREvent("events", new List<DownloadableEventMessage>() { message });
await _queue.SendMessage("signalr-events", JsonSerializer.Serialize(ev, _options), StorageType.Config);
} else {
// Not handled
throw ex;
}
}
}

public async Async.Task SendEvent(BaseEvent anEvent) {
Expand Down