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

Commit 9d8d332

Browse files
authored
Migrating QueueTaskHeartbeat (#1777)
* Migrating QueueTaskHeartbeat * changing the name of the input queue * rename type alias Tasks to Async * Fix property casing * fixing types * Removing IStorageProvider * fix function name * address PR comments
1 parent 31b9163 commit 9d8d332

File tree

14 files changed

+288
-122
lines changed

14 files changed

+288
-122
lines changed

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,67 @@ public enum WebhookMessageState
4343
Retrying,
4444
Succeeded,
4545
Failed
46+
}
47+
48+
public enum TaskState
49+
{
50+
Init,
51+
Waiting,
52+
Scheduled,
53+
Setting_up,
54+
Running,
55+
Stopping,
56+
Stopped,
57+
WaitJob
58+
}
59+
60+
public enum TaskType
61+
{
62+
Coverage,
63+
LibfuzzerFuzz,
64+
LibfuzzerCoverage,
65+
LibfuzzerCrashReport,
66+
LibfuzzerMerge,
67+
LibfuzzerRegression,
68+
GenericAnalysis,
69+
GenericSupervisor,
70+
GenericMerge,
71+
GenericGenerator,
72+
GenericCrashReport,
73+
GenericRegression
74+
}
75+
76+
public enum Os
77+
{
78+
Windows,
79+
Linux
80+
}
81+
82+
public enum ContainerType
83+
{
84+
Analysis,
85+
Coverage,
86+
Crashes,
87+
Inputs,
88+
NoRepro,
89+
ReadonlyInputs,
90+
Reports,
91+
Setup,
92+
Tools,
93+
UniqueInputs,
94+
UniqueReports,
95+
RegressionReports,
96+
Logs
97+
}
98+
99+
100+
public enum StatsFormat
101+
{
102+
AFL
103+
}
104+
105+
public enum TaskDebugFlag
106+
{
107+
KeepNodeOnFailure,
108+
KeepNodeOnCompletion,
46109
}

src/ApiService/ApiService/OneFuzzTypes/Events.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public EventType GetEventType()
104104
// ) : BaseEvent();
105105

106106

107-
//record EventTaskHeartbeat(
108-
// JobId: Guid,
109-
// TaskId: Guid,
110-
// Config: TaskConfig
111-
//): BaseEvent();
107+
record EventTaskHeartbeat(
108+
Guid JobId,
109+
Guid TaskId,
110+
TaskConfig Config
111+
) : BaseEvent();
112112

113113

114114
//record EventPing(

src/ApiService/ApiService/OneFuzzTypes/Model.cs

Lines changed: 123 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System;
33
using System.Collections.Generic;
44
using PoolName = System.String;
5+
using Region = System.String;
6+
using Container = System.String;
57

68
namespace Microsoft.OneFuzz.Service;
79

@@ -29,9 +31,15 @@ public enum HeartbeatType
2931
TaskAlive,
3032
}
3133

32-
public record HeartbeatData(HeartbeatType type);
34+
public record HeartbeatData(HeartbeatType Type);
3335

34-
public record NodeHeartbeatEntry(Guid NodeId, HeartbeatData[] data);
36+
public record TaskHeartbeatEntry(
37+
Guid TaskId,
38+
Guid? JobId,
39+
Guid MachineId,
40+
HeartbeatData[] Data
41+
);
42+
public record NodeHeartbeatEntry(Guid NodeId, HeartbeatData[] Data);
3543

3644
public record NodeCommandStopIfFree();
3745

@@ -79,7 +87,7 @@ public enum NodeState
7987

8088
public record ProxyHeartbeat
8189
(
82-
string Region,
90+
Region Region,
8391
Guid ProxyId,
8492
List<ProxyForward> Forwards,
8593
DateTimeOffset TimeStamp
@@ -102,35 +110,35 @@ bool DebugKeepNode
102110

103111

104112
public partial record ProxyForward
105-
(
106-
[PartitionKey] string Region,
113+
(
114+
[PartitionKey] Region Region,
107115
[RowKey] int DstPort,
108-
int SrcPort,
116+
int SrcPort,
109117
string DstIp
110118
) : EntityBase();
111119

112-
public partial record ProxyConfig
113-
(
114-
Uri Url,
115-
string Notification,
116-
string Region,
117-
Guid? ProxyId,
118-
List<ProxyForward> Forwards,
119-
string InstanceTelemetryKey,
120+
public partial record ProxyConfig
121+
(
122+
Uri Url,
123+
string Notification,
124+
Region Region,
125+
Guid? ProxyId,
126+
List<ProxyForward> Forwards,
127+
string InstanceTelemetryKey,
120128
string MicrosoftTelemetryKey
121129

122130
);
123131

124132
public partial record Proxy
125133
(
126-
[PartitionKey] string Region,
134+
[PartitionKey] Region Region,
127135
[RowKey] Guid ProxyId,
128136
DateTimeOffset? CreatedTimestamp,
129-
VmState State,
130-
Authentication Auth,
131-
string? Ip,
132-
Error? Error,
133-
string Version,
137+
VmState State,
138+
Authentication Auth,
139+
string? Ip,
140+
Error? Error,
141+
string Version,
134142
ProxyHeartbeat? heartbeat
135143
) : EntityBase();
136144

@@ -148,23 +156,102 @@ String InstanceName
148156
) : EntityBase();
149157

150158

151-
//record AnyHttpUrl(AnyUrl):
152-
// allowed_schemes = {'http', 'https
153-
//
154-
155-
159+
public record TaskDetails(
160+
161+
TaskType Type,
162+
int Duration,
163+
string? TargetExe,
164+
Dictionary<string, string>? TargetEnv,
165+
List<string>? TargetOptions,
166+
int? TargetWorkers,
167+
bool? TargetOptionsMerge,
168+
bool? CheckAsanLog,
169+
bool? CheckDebugger,
170+
int? CheckRetryCount,
171+
bool? CheckFuzzerHelp,
172+
bool? ExpectCrashOnFailure,
173+
bool? RenameOutput,
174+
string? SupervisorExe,
175+
Dictionary<string, string>? SupervisorEnv,
176+
List<string>? SupervisorOptions,
177+
string? SupervisorInputMarker,
178+
string? GeneratorExe,
179+
Dictionary<string, string>? GeneratorEnv,
180+
List<string>? GeneratorOptions,
181+
string? AnalyzerExe,
182+
Dictionary<string, string>? AnalyzerEnv,
183+
List<string> AnalyzerOptions,
184+
ContainerType? WaitForFiles,
185+
string? StatsFile,
186+
StatsFormat? StatsFormat,
187+
bool? RebootAfterSetup,
188+
int? TargetTimeout,
189+
int? EnsembleSyncDelay,
190+
bool? PreserveExistingOutputs,
191+
List<string>? ReportList,
192+
int? MinimizedStackDepth,
193+
string? CoverageFilter
194+
);
156195

196+
public record TaskVm(
197+
Region Region,
198+
string Sku,
199+
string Image,
200+
int Count,
201+
bool SpotInstance,
202+
bool? RebootAfterSetup
203+
);
157204

205+
public record TaskPool(
206+
int Count,
207+
PoolName PoolName
208+
);
158209

159-
//public record TaskConfig(
160-
// Guid jobId,
161-
// List<Guid> PrereqTasks,
162-
// TaskDetails Task,
163-
// TaskVm? vm,
164-
// TaskPool pool: Optional[]
165-
// containers: List[TaskContainers]
166-
// tags: Dict[str, str]
167-
// debug: Optional[List[TaskDebugFlag]]
168-
// colocate: Optional[bool]
169-
// ): EntityBase();
210+
public record TaskContainers(
211+
ContainerType Type,
212+
Container Name
213+
);
214+
public record TaskConfig(
215+
Guid JobId,
216+
List<Guid>? PrereqTasks,
217+
TaskDetails Task,
218+
TaskVm? Vm,
219+
TaskPool? Pool,
220+
List<TaskContainers>? Containers,
221+
Dictionary<string, string>? Tags,
222+
List<TaskDebugFlag>? Debug,
223+
bool? Colocate
224+
);
225+
226+
227+
public record TaskEventSummary(
228+
DateTimeOffset? Timestamp,
229+
string EventData,
230+
string EventType
231+
);
232+
233+
234+
public record NodeAssignment(
235+
Guid NodeId,
236+
Guid? ScalesetId,
237+
NodeTaskState State
238+
);
239+
240+
241+
public record Task(
242+
// Timestamp: Optional[datetime] = Field(alias="Timestamp")
243+
[PartitionKey] Guid JobId,
244+
[RowKey] Guid TaskId,
245+
TaskState State,
246+
Os Os,
247+
TaskConfig Config,
248+
Error? Error,
249+
Authentication? Auth,
250+
DateTimeOffset? Heartbeat,
251+
DateTimeOffset? EndTime,
252+
UserInfo? UserInfo) : EntityBase()
253+
{
254+
List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
255+
List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
170256

257+
}

src/ApiService/ApiService/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// to avoid collision with Task in model.cs
2+
global using Async = System.Threading.Tasks;
3+
14
using System;
25
using System.Collections.Generic;
36
using Microsoft.Extensions.Hosting;
47
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
68
using ApiService.OneFuzzLib;
79

10+
11+
812
namespace Microsoft.OneFuzz.Service;
913

1014
public class Program
@@ -34,11 +38,11 @@ public static void Main()
3438
.ConfigureServices((context, services) =>
3539
services
3640
.AddSingleton<ILogTracerFactory>(_ => new LogTracerFactory(GetLoggers()))
37-
.AddSingleton<IStorageProvider>(_ => new StorageProvider(EnvironmentVariables.OneFuzz.FuncStorage ?? throw new InvalidOperationException("Missing account id")))
3841
.AddSingleton<INodeOperations, NodeOperations>()
3942
.AddSingleton<IEvents, Events>()
4043
.AddSingleton<IWebhookOperations, WebhookOperations>()
4144
.AddSingleton<IWebhookMessageLogOperations, WebhookMessageLogOperations>()
45+
.AddSingleton<ITaskOperations, TaskOperations>()
4246
.AddSingleton<IQueue, Queue>()
4347
.AddSingleton<ICreds>(_ => new Creds())
4448
.AddSingleton<IStorage, Storage>()

src/ApiService/ApiService/QueueFileChanges.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.Azure.Functions.Worker;
33
using System.Collections.Generic;
44
using System.Text.Json;
5-
using System.Threading.Tasks;
65
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
76
using System.Linq;
87

@@ -15,19 +14,17 @@ public class QueueFileChanges
1514
const int MAX_DEQUEUE_COUNT = 5;
1615

1716
private readonly ILogTracerFactory _loggerFactory;
18-
private readonly IStorageProvider _storageProvider;
1917

2018
private readonly IStorage _storage;
2119

22-
public QueueFileChanges(ILogTracerFactory loggerFactory, IStorageProvider storageProvider, IStorage storage)
20+
public QueueFileChanges(ILogTracerFactory loggerFactory, IStorage storage)
2321
{
2422
_loggerFactory = loggerFactory;
25-
_storageProvider = storageProvider;
2623
_storage = storage;
2724
}
2825

2926
[Function("QueueFileChanges")]
30-
public Task Run(
27+
public Async.Task Run(
3128
[QueueTrigger("file-changes-refactored", Connection = "AzureWebJobsStorage")] string msg,
3229
int dequeueCount)
3330
{
@@ -42,18 +39,18 @@ public Task Run(
4239
if (!fileChangeEvent.ContainsKey(eventType)
4340
|| fileChangeEvent[eventType] != "Microsoft.Storage.BlobCreated")
4441
{
45-
return Task.CompletedTask;
42+
return Async.Task.CompletedTask;
4643
}
4744

4845
const string topic = "topic";
4946
if (!fileChangeEvent.ContainsKey(topic)
5047
|| !_storage.CorpusAccounts(log).Contains(fileChangeEvent[topic]))
5148
{
52-
return Task.CompletedTask;
49+
return Async.Task.CompletedTask;
5350
}
5451

5552
file_added(log, fileChangeEvent, lastTry);
56-
return Task.CompletedTask;
53+
return Async.Task.CompletedTask;
5754
}
5855

5956
private void file_added(ILogTracer log, Dictionary<string, string> fileChangeEvent, bool failTaskOnTransientError)

src/ApiService/ApiService/QueueNodeHearbeat.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using Microsoft.Azure.Functions.Worker;
33
using System.Text.Json;
4-
using System.Threading.Tasks;
54
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
65

76
namespace Microsoft.OneFuzz.Service;
@@ -22,7 +21,7 @@ public QueueNodeHearbeat(ILogTracerFactory loggerFactory, INodeOperations nodes,
2221
}
2322

2423
[Function("QueueNodeHearbeat")]
25-
public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
24+
public async Async.Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
2625
{
2726
var log = _loggerFactory.MakeLogTracer(Guid.NewGuid());
2827
log.Info($"heartbeat: {msg}");

0 commit comments

Comments
 (0)