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

Commit aa54a15

Browse files
authored
Add extra_output container, rename extra container (#3064)
## Summary of the Pull Request - **Breaking** (but as far as I know this feature is not yet in use): rename the `extra_container` to `extra_setup_container`. - **Add**: the `extra_output_container`, which pushes its outputs continually. - We may also want a type of container which both pushes & pulls? See discussion below. - **Improved**: if `onefuzz-task` fails upon launch, we will log its output for diagnosis (might close #3113) --- Some thoughts for the future: We might want to redesign the containers so that we have something like the following which is passed to the agent, and the agent doesn't need to know the specifics of the containers supplied: ```jsonc { // ... "containers": { "extra_setup_dir": { "mode": "pull", "container_name": "yyy", }, "extra_output_dir": { "mode": "push", "continuous": true, // keep pushing while job is running "container_name": "xxx" } } } ``` At the moment the agent needs to know what each container is for, for each task type. A more generic and flexible method might be simpler overall.
1 parent 630b083 commit aa54a15

Some content is hidden

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

50 files changed

+1545
-1409
lines changed

docs/command-replacements.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ The following values are replaced with the specific values at runtime.
2626
* `{crashes_container}`: Container name for the `crashes` container
2727
* `{microsoft_telemetry_key}`: Application Insights key used for collecting [non-attributable telemetry](telemetry.md) to improve OneFuzz.
2828
* `{instance_telemetry_key}`: Application Insights key used for private, instance-owned telemetry and logging (See [OneFuzz Telemetry](telemetry.md).
29-
* `{extra_dir}`: Path to the optionally provided `extra` directory
29+
* `{extra_setup_dir}`: Path to the optionally provided `extra_setup` directory
30+
* `{extra_output_dir}`: Path to the optionally provided `extra_output` directory
3031

3132
## Example
3233

docs/webhook_events.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ If webhook is set to have Event Grid message format then the payload will look a
152152
"unique_reports",
153153
"regression_reports",
154154
"logs",
155-
"extra"
155+
"extra_setup",
156+
"extra_output"
156157
],
157158
"title": "ContainerType"
158159
},
@@ -1957,7 +1958,8 @@ If webhook is set to have Event Grid message format then the payload will look a
19571958
"unique_reports",
19581959
"regression_reports",
19591960
"logs",
1960-
"extra"
1961+
"extra_setup",
1962+
"extra_output"
19611963
],
19621964
"title": "ContainerType"
19631965
},
@@ -2860,7 +2862,8 @@ If webhook is set to have Event Grid message format then the payload will look a
28602862
"unique_reports",
28612863
"regression_reports",
28622864
"logs",
2863-
"extra"
2865+
"extra_setup",
2866+
"extra_output"
28642867
],
28652868
"title": "ContainerType"
28662869
},
@@ -3343,7 +3346,8 @@ If webhook is set to have Event Grid message format then the payload will look a
33433346
"unique_reports",
33443347
"regression_reports",
33453348
"logs",
3346-
"extra"
3349+
"extra_setup",
3350+
"extra_output"
33473351
],
33483352
"title": "ContainerType"
33493353
},
@@ -3844,7 +3848,8 @@ If webhook is set to have Event Grid message format then the payload will look a
38443848
"unique_reports",
38453849
"regression_reports",
38463850
"logs",
3847-
"extra"
3851+
"extra_setup",
3852+
"extra_output"
38483853
],
38493854
"title": "ContainerType"
38503855
},
@@ -4293,7 +4298,8 @@ If webhook is set to have Event Grid message format then the payload will look a
42934298
"unique_reports",
42944299
"regression_reports",
42954300
"logs",
4296-
"extra"
4301+
"extra_setup",
4302+
"extra_output"
42974303
],
42984304
"title": "ContainerType"
42994305
},
@@ -4769,7 +4775,8 @@ If webhook is set to have Event Grid message format then the payload will look a
47694775
"unique_reports",
47704776
"regression_reports",
47714777
"logs",
4772-
"extra"
4778+
"extra_setup",
4779+
"extra_output"
47734780
],
47744781
"title": "ContainerType"
47754782
},
@@ -5375,7 +5382,8 @@ If webhook is set to have Event Grid message format then the payload will look a
53755382
"unique_reports",
53765383
"regression_reports",
53775384
"logs",
5378-
"extra"
5385+
"extra_setup",
5386+
"extra_output"
53795387
],
53805388
"title": "ContainerType"
53815389
},

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public enum ContainerType {
112112
UniqueReports,
113113
RegressionReports,
114114
Logs,
115-
Extra
115+
ExtraSetup,
116+
ExtraOutput,
116117
}
117118

118119

src/ApiService/ApiService/OneFuzzTypes/Model.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -963,42 +963,36 @@ public record TaskDefinition(
963963
public record WorkSet(
964964
bool Reboot,
965965
Uri SetupUrl,
966-
Uri? ExtraUrl,
966+
Uri? ExtraSetupUrl,
967967
bool Script,
968968
List<WorkUnit> WorkUnits
969969
);
970970

971-
972-
973-
974-
975-
public record ContainerDefinition(
971+
public readonly record struct ContainerDefinition(
976972
ContainerType Type,
977973
Compare Compare,
978974
long Value,
979975
ContainerPermission Permissions);
980976

981-
982977
// TODO: service shouldn't pass SyncedDir, but just the url and let the agent
983978
// come up with paths
984-
public record SyncedDir(string Path, Uri Url);
985-
979+
public readonly record struct SyncedDir(string Path, Uri Url);
986980

987981
[JsonConverter(typeof(ContainerDefConverter))]
988982
public interface IContainerDef { }
989983
public record SingleContainer(SyncedDir SyncedDir) : IContainerDef;
990-
public record MultipleContainer(List<SyncedDir> SyncedDirs) : IContainerDef;
984+
public record MultipleContainer(IReadOnlyList<SyncedDir> SyncedDirs) : IContainerDef;
991985

992986

993987
public class ContainerDefConverter : JsonConverter<IContainerDef> {
994988
public override IContainerDef? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
995989
if (reader.TokenType == JsonTokenType.StartObject) {
996990
var result = (SyncedDir?)JsonSerializer.Deserialize(ref reader, typeof(SyncedDir), options);
997-
if (result is null) {
998-
return null;
991+
if (result is SyncedDir sd) {
992+
return new SingleContainer(sd);
999993
}
1000994

1001-
return new SingleContainer(result);
995+
return null;
1002996
}
1003997

1004998
if (reader.TokenType == JsonTokenType.StartArray) {
@@ -1093,8 +1087,8 @@ Dictionary<string, string> Tags
10931087
public IContainerDef? UniqueInputs { get; set; }
10941088
public IContainerDef? UniqueReports { get; set; }
10951089
public IContainerDef? RegressionReports { get; set; }
1096-
public IContainerDef? Extra { get; set; }
1097-
1090+
public IContainerDef? ExtraSetup { get; set; }
1091+
public IContainerDef? ExtraOutput { get; set; }
10981092
}
10991093

11001094
public record NodeCommandEnvelope(

src/ApiService/ApiService/onefuzzlib/Config.cs

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -75,75 +75,82 @@ private static BlobContainerSasPermissions ConvertPermissions(ContainerPermissio
7575
);
7676

7777
if (definition.MonitorQueue != null) {
78-
config.inputQueue = await _queue.GetQueueSas(task.TaskId.ToString(), StorageType.Corpus, QueueSasPermissions.Add | QueueSasPermissions.Read | QueueSasPermissions.Update | QueueSasPermissions.Process);
79-
}
80-
81-
var containersByType = definition.Containers.Where(c => c.Type != ContainerType.Setup && task.Config.Containers != null)
82-
.ToAsyncEnumerable()
83-
.SelectAwait(async countainerDef => {
84-
var containers = await
85-
task.Config.Containers!
86-
.Where(c => c.Type == countainerDef.Type).Select(container => (countainerDef, container))
87-
.Where(x => x.container != null)
88-
.ToAsyncEnumerable()
89-
.SelectAwait(async (x, i) =>
90-
new SyncedDir(
91-
string.Join("_", "task", x.Item1.Type.ToString().ToLower(), i),
92-
await _containers.GetContainerSasUrl(x.Item2.Name, StorageType.Corpus, ConvertPermissions(x.Item1.Permissions)))
93-
).ToListAsync();
94-
return (countainerDef, containers);
95-
}
96-
);
97-
98-
await foreach (var data in containersByType) {
99-
100-
if (!data.containers.Any()) {
101-
continue;
102-
}
78+
config.inputQueue = await _queue.GetQueueSas(task.TaskId.ToString(), StorageType.Corpus, QueueSasPermissions.All);
79+
}
80+
81+
if (task.Config.Containers is not null) {
82+
var containersByType =
83+
await Async.Task.WhenAll(
84+
definition.Containers
85+
.Where(c => c.Type is not ContainerType.Setup)
86+
.Select(async countainerDef => {
87+
var syncedDirs =
88+
await Async.Task.WhenAll(
89+
task.Config.Containers
90+
.Where(c => c.Type == countainerDef.Type)
91+
.Select(async (container, i) =>
92+
new SyncedDir(
93+
string.Join("_", "task", countainerDef.Type.ToString().ToLower(), i),
94+
await _containers.GetContainerSasUrl(container.Name, StorageType.Corpus, ConvertPermissions(countainerDef.Permissions)))
95+
));
96+
97+
return (countainerDef, syncedDirs);
98+
}));
99+
100+
foreach (var (containerDef, syncedDirs) in containersByType) {
101+
if (!syncedDirs.Any()) {
102+
continue;
103+
}
103104

104-
IContainerDef def = data.countainerDef switch {
105-
ContainerDefinition { Compare: Compare.Equal, Value: 1 } or
106-
ContainerDefinition { Compare: Compare.AtMost, Value: 1 } when data.containers.Count == 1 => new SingleContainer(data.containers[0]),
107-
_ => new MultipleContainer(data.containers)
108-
};
109-
110-
switch (data.countainerDef.Type) {
111-
case ContainerType.Analysis:
112-
config.Analysis = def;
113-
break;
114-
case ContainerType.Coverage:
115-
config.Coverage = def;
116-
break;
117-
case ContainerType.Crashes:
118-
config.Crashes = def;
119-
break;
120-
case ContainerType.Inputs:
121-
config.Inputs = def;
122-
break;
123-
case ContainerType.NoRepro:
124-
config.NoRepro = def;
125-
break;
126-
case ContainerType.ReadonlyInputs:
127-
config.ReadonlyInputs = def;
128-
break;
129-
case ContainerType.Reports:
130-
config.Reports = def;
131-
break;
132-
case ContainerType.Tools:
133-
config.Tools = def;
134-
break;
135-
case ContainerType.UniqueInputs:
136-
config.UniqueInputs = def;
137-
break;
138-
case ContainerType.UniqueReports:
139-
config.UniqueReports = def;
140-
break;
141-
case ContainerType.RegressionReports:
142-
config.RegressionReports = def;
143-
break;
144-
case ContainerType.Extra:
145-
config.Extra = def;
146-
break;
105+
IContainerDef def = containerDef switch {
106+
ContainerDefinition { Compare: Compare.Equal or Compare.AtMost, Value: 1 }
107+
when syncedDirs is [var syncedDir] => new SingleContainer(syncedDir),
108+
_ => new MultipleContainer(syncedDirs)
109+
};
110+
111+
switch (containerDef.Type) {
112+
case ContainerType.Analysis:
113+
config.Analysis = def;
114+
break;
115+
case ContainerType.Coverage:
116+
config.Coverage = def;
117+
break;
118+
case ContainerType.Crashes:
119+
config.Crashes = def;
120+
break;
121+
case ContainerType.Inputs:
122+
config.Inputs = def;
123+
break;
124+
case ContainerType.NoRepro:
125+
config.NoRepro = def;
126+
break;
127+
case ContainerType.ReadonlyInputs:
128+
config.ReadonlyInputs = def;
129+
break;
130+
case ContainerType.Reports:
131+
config.Reports = def;
132+
break;
133+
case ContainerType.Tools:
134+
config.Tools = def;
135+
break;
136+
case ContainerType.UniqueInputs:
137+
config.UniqueInputs = def;
138+
break;
139+
case ContainerType.UniqueReports:
140+
config.UniqueReports = def;
141+
break;
142+
case ContainerType.RegressionReports:
143+
config.RegressionReports = def;
144+
break;
145+
case ContainerType.ExtraSetup:
146+
config.ExtraSetup = def;
147+
break;
148+
case ContainerType.ExtraOutput:
149+
config.ExtraOutput = def;
150+
break;
151+
default:
152+
throw new InvalidDataException($"unknown container type: {containerDef.Type}");
153+
}
147154
}
148155
}
149156

0 commit comments

Comments
 (0)