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

Commit 04879b4

Browse files
chkeitaAdamL-Microsoft
authored andcommitted
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 d4926cc commit 04879b4

File tree

6 files changed

+78
-185
lines changed

6 files changed

+78
-185
lines changed

src/ApiService/ApiService/OneFuzzTypes/Model.cs

Lines changed: 72 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
using System;
33
using System.Collections.Generic;
44
using PoolName = System.String;
5-
using Endpoint = System.String;
6-
using GroupId = System.Guid;
7-
using PrincipalId = System.Guid;
5+
using Region = System.String;
6+
using Container = System.String;
87

98
namespace Microsoft.OneFuzz.Service;
109

@@ -101,7 +100,7 @@ public enum NodeState
101100

102101
public record ProxyHeartbeat
103102
(
104-
string Region,
103+
Region Region,
105104
Guid ProxyId,
106105
List<ProxyForward> Forwards,
107106
DateTimeOffset TimeStamp
@@ -125,7 +124,7 @@ bool DebugKeepNode
125124

126125
public partial record ProxyForward
127126
(
128-
[PartitionKey] string Region,
127+
[PartitionKey] Region Region,
129128
[RowKey] int DstPort,
130129
int SrcPort,
131130
string DstIp
@@ -135,7 +134,7 @@ public partial record ProxyConfig
135134
(
136135
Uri Url,
137136
string Notification,
138-
string Region,
137+
Region Region,
139138
Guid? ProxyId,
140139
List<ProxyForward> Forwards,
141140
string InstanceTelemetryKey,
@@ -145,7 +144,7 @@ string MicrosoftTelemetryKey
145144

146145
public partial record Proxy
147146
(
148-
[PartitionKey] string Region,
147+
[PartitionKey] Region Region,
149148
[RowKey] Guid ProxyId,
150149
DateTimeOffset? CreatedTimestamp,
151150
VmState State,
@@ -170,9 +169,72 @@ String InstanceName
170169
) : EntityBase();
171170

172171

173-
//record AnyHttpUrl(AnyUrl):
174-
// allowed_schemes = {'http', 'https
175-
//
172+
public record TaskDetails(
173+
174+
TaskType Type,
175+
int Duration,
176+
string? TargetExe,
177+
Dictionary<string, string>? TargetEnv,
178+
List<string>? TargetOptions,
179+
int? TargetWorkers,
180+
bool? TargetOptionsMerge,
181+
bool? CheckAsanLog,
182+
bool? CheckDebugger,
183+
int? CheckRetryCount,
184+
bool? CheckFuzzerHelp,
185+
bool? ExpectCrashOnFailure,
186+
bool? RenameOutput,
187+
string? SupervisorExe,
188+
Dictionary<string, string>? SupervisorEnv,
189+
List<string>? SupervisorOptions,
190+
string? SupervisorInputMarker,
191+
string? GeneratorExe,
192+
Dictionary<string, string>? GeneratorEnv,
193+
List<string>? GeneratorOptions,
194+
string? AnalyzerExe,
195+
Dictionary<string, string>? AnalyzerEnv,
196+
List<string> AnalyzerOptions,
197+
ContainerType? WaitForFiles,
198+
string? StatsFile,
199+
StatsFormat? StatsFormat,
200+
bool? RebootAfterSetup,
201+
int? TargetTimeout,
202+
int? EnsembleSyncDelay,
203+
bool? PreserveExistingOutputs,
204+
List<string>? ReportList,
205+
int? MinimizedStackDepth,
206+
string? CoverageFilter
207+
);
208+
209+
public record TaskVm(
210+
Region Region,
211+
string Sku,
212+
string Image,
213+
int Count,
214+
bool SpotInstance,
215+
bool? RebootAfterSetup
216+
);
217+
218+
public record TaskPool(
219+
int Count,
220+
PoolName PoolName
221+
);
222+
223+
public record TaskContainers(
224+
ContainerType Type,
225+
Container Name
226+
);
227+
public record TaskConfig(
228+
Guid JobId,
229+
List<Guid>? PrereqTasks,
230+
TaskDetails Task,
231+
TaskVm? Vm,
232+
TaskPool? Pool,
233+
List<TaskContainers>? Containers,
234+
Dictionary<string, string>? Tags,
235+
List<TaskDebugFlag>? Debug,
236+
bool? Colocate
237+
);
176238

177239

178240
public record TaskEventSummary(
@@ -204,118 +266,5 @@ public record Task(
204266
{
205267
List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
206268
List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
207-
}
208-
public record AzureSecurityExtensionConfig();
209-
public record GenevaExtensionConfig();
210-
211-
212-
public record KeyvaultExtensionConfig(
213-
string KeyVaultName,
214-
string CertName,
215-
string CertPath,
216-
string ExtensionStore
217-
);
218-
219-
public record AzureMonitorExtensionConfig(
220-
string ConfigVersion,
221-
string Moniker,
222-
string Namespace,
223-
[property: JsonPropertyName("monitoringGSEnvironment")] string MonitoringGSEnvironment,
224-
[property: JsonPropertyName("monitoringGCSAccount")] string MonitoringGCSAccount,
225-
[property: JsonPropertyName("monitoringGCSAuthId")] string MonitoringGCSAuthId,
226-
[property: JsonPropertyName("monitoringGCSAuthIdType")] string MonitoringGCSAuthIdType
227-
);
228269

229-
public record AzureVmExtensionConfig(
230-
KeyvaultExtensionConfig? Keyvault,
231-
AzureMonitorExtensionConfig AzureMonitor
232-
);
233-
234-
public record NetworkConfig(
235-
string AddressSpace,
236-
string Subnet
237-
)
238-
{
239-
public NetworkConfig() : this("10.0.0.0/8", "10.0.0.0/16") { }
240-
}
241-
242-
public record NetworkSecurityGroupConfig(
243-
string[] AllowedServiceTags,
244-
string[] AllowedIps
245-
)
246-
{
247-
public NetworkSecurityGroupConfig() : this(Array.Empty<string>(), Array.Empty<string>()) { }
248-
}
249-
250-
public record ApiAccessRule(
251-
string[] Methods,
252-
Guid[] AllowedGroups
253-
);
254-
255-
public record InstanceConfig
256-
(
257-
[PartitionKey, RowKey] string InstanceName,
258-
//# initial set of admins can only be set during deployment.
259-
//# if admins are set, only admins can update instance configs.
260-
Guid[]? Admins,
261-
//# if set, only admins can manage pools or scalesets
262-
bool AllowPoolManagement,
263-
string[] AllowedAadTenants,
264-
NetworkConfig NetworkConfig,
265-
NetworkSecurityGroupConfig ProxyNsgConfig,
266-
AzureVmExtensionConfig? Extensions,
267-
string ProxyVmSku,
268-
IDictionary<Endpoint, ApiAccessRule>? ApiAccessRules,
269-
IDictionary<PrincipalId, GroupId[]>? GroupMembership,
270-
271-
IDictionary<string, string>? VmTags,
272-
IDictionary<string, string>? VmssTags
273-
) : EntityBase()
274-
{
275-
public InstanceConfig(string instanceName) : this(
276-
instanceName,
277-
null,
278-
true,
279-
Array.Empty<string>(),
280-
new NetworkConfig(),
281-
new NetworkSecurityGroupConfig(),
282-
null,
283-
"Standard_B2s",
284-
null,
285-
null,
286-
null,
287-
null)
288-
{ }
289-
290-
public List<Guid>? CheckAdmins(List<Guid>? value)
291-
{
292-
if (value is not null && value.Count == 0)
293-
{
294-
throw new ArgumentException("admins must be null or contain at least one UUID");
295-
}
296-
else
297-
{
298-
return value;
299-
}
300-
}
301-
302-
303-
//# At the moment, this only checks allowed_aad_tenants, however adding
304-
//# support for 3rd party JWT validation is anticipated in a future release.
305-
public ResultOk<List<string>> CheckInstanceConfig()
306-
{
307-
List<string> errors = new();
308-
if (AllowedAadTenants.Length == 0)
309-
{
310-
errors.Add("allowed_aad_tenants must not be empty");
311-
}
312-
if (errors.Count == 0)
313-
{
314-
return ResultOk<List<string>>.Ok();
315-
}
316-
else
317-
{
318-
return ResultOk<List<string>>.Error(errors);
319-
}
320-
}
321270
}

src/ApiService/ApiService/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
using System.Collections.Generic;
66
using Microsoft.Extensions.Hosting;
77
using Microsoft.Extensions.DependencyInjection;
8-
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
98
using ApiService.OneFuzzLib;
109

10+
11+
1112
namespace Microsoft.OneFuzz.Service;
1213

1314
public class Program
@@ -65,11 +66,11 @@ public static void Main()
6566
.ConfigureServices((context, services) =>
6667
services
6768
.AddSingleton<ILogTracerFactory>(_ => new LogTracerFactory(GetLoggers()))
68-
.AddSingleton<IStorageProvider>(_ => new StorageProvider(EnvironmentVariables.OneFuzz.FuncStorage ?? throw new InvalidOperationException("Missing account id")))
6969
.AddSingleton<INodeOperations, NodeOperations>()
7070
.AddSingleton<IEvents, Events>()
7171
.AddSingleton<IWebhookOperations, WebhookOperations>()
7272
.AddSingleton<IWebhookMessageLogOperations, WebhookMessageLogOperations>()
73+
.AddSingleton<ITaskOperations, TaskOperations>()
7374
.AddSingleton<IQueue, Queue>()
7475
.AddSingleton<ICreds>(_ => new Creds())
7576
.AddSingleton<IStorage, Storage>()

src/ApiService/ApiService/QueueFileChanges.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ public class QueueFileChanges
1414
const int MAX_DEQUEUE_COUNT = 5;
1515

1616
private readonly ILogTracerFactory _loggerFactory;
17-
private readonly IStorageProvider _storageProvider;
1817

1918
private readonly IStorage _storage;
2019

21-
public QueueFileChanges(ILogTracerFactory loggerFactory, IStorageProvider storageProvider, IStorage storage)
20+
public QueueFileChanges(ILogTracerFactory loggerFactory, IStorage storage)
2221
{
2322
_loggerFactory = loggerFactory;
24-
_storageProvider = storageProvider;
2523
_storage = storage;
2624
}
2725

@@ -52,7 +50,7 @@ public Async.Task Run(
5250
}
5351

5452
file_added(log, fileChangeEvent, lastTry);
55-
return Task.CompletedTask;
53+
return Async.Task.CompletedTask;
5654
}
5755

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

src/ApiService/ApiService/QueueProxyHeartbeat.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;
@@ -19,7 +18,7 @@ public QueueProxyHearbeat(ILogTracerFactory loggerFactory, IProxyOperations prox
1918
}
2019

2120
[Function("QueueProxyHearbeat")]
22-
public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
21+
public async Async.Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
2322
{
2423
var log = _loggerFactory.MakeLogTracer(Guid.NewGuid());
2524

src/ApiService/ApiService/onefuzzlib/Events.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Text;
66
using System.Text.Json;
77
using System.Text.Json.Serialization;
8-
using System.Threading.Tasks;
98

109
namespace Microsoft.OneFuzz.Service
1110
{

src/ApiService/ApiService/onefuzzlib/orm/StorageProvider.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)