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

Commit

Permalink
report CrashReported instead
Browse files Browse the repository at this point in the history
  • Loading branch information
chkeita committed Oct 30, 2023
1 parent 8da70e5 commit 3cc48d9
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/ApiService/ApiService/Functions/Jobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ private async Task<HttpResponseData> Get(HttpRequestData req) {
var tasks = _context.TaskOperations.SearchStates(jobId);

IAsyncEnumerable<IJobTaskInfo> taskInfo = search.WithTasks ?? false ? tasks : tasks.Select(TaskToJobTaskInfo);
var hasBugs = await _context.AdoNotificationEntryOperations.WasNotfied(jobId);
return await RequestHandling.Ok(req, JobResponse.ForJob(job, taskInfo.ToEnumerable(), hasBugs));

var crashReported = await _context.JobCrashReportedOperations.CrashReported(jobId);
return await RequestHandling.Ok(req, JobResponse.ForJob(job, taskInfo.ToEnumerable(), crashReported));
}

var jobs = await _context.JobOperations.SearchState(states: search.State ?? Enumerable.Empty<JobState>()).ToListAsync();
Expand Down
4 changes: 4 additions & 0 deletions src/ApiService/ApiService/Functions/QueueJobResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public async Async.Task Run([QueueTrigger("job-result", Connection = "AzureWebJo
var jobResultType = data.Type;
_log.LogInformation($"job result data type: {jobResultType}");

if (jobResultType == "CrashReported") {
var _result = await _context.JobCrashReportedOperations.ReportCrash(job.JobId, jr.TaskId);
}

Dictionary<string, double> value;
if (jr.Value.Count > 0) {
value = jr.Value;
Expand Down
7 changes: 5 additions & 2 deletions src/ApiService/ApiService/OneFuzzTypes/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,12 @@ public record Job(
StoredUserInfo? UserInfo,
string? Error = null,
DateTimeOffset? EndTime = null
) : StatefulEntityBase<JobState>(State) {
) : StatefulEntityBase<JobState>(State);

}
public record JobCrashReported(
[PartitionKey] Guid JobId,
[RowKey] Guid TaskId
) : EntityBase;

// This is like UserInfo but lacks the UPN:
public record StoredUserInfo(Guid? ApplicationId, Guid? ObjectId);
Expand Down
6 changes: 3 additions & 3 deletions src/ApiService/ApiService/OneFuzzTypes/Responses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public record JobResponse(
StoredUserInfo? UserInfo,
[property: JsonPropertyName("Timestamp")] // must retain capital T for backcompat
DateTimeOffset? Timestamp,
bool HasBugs
bool CrashReported
// not including UserInfo from Job model
) : BaseResponse() {
public static JobResponse ForJob(Job j, IEnumerable<IJobTaskInfo>? taskInfo, bool hasBugs = false)
public static JobResponse ForJob(Job j, IEnumerable<IJobTaskInfo>? taskInfo, bool crashReported = false)
=> new(
JobId: j.JobId,
State: j.State,
Expand All @@ -116,7 +116,7 @@ public static JobResponse ForJob(Job j, IEnumerable<IJobTaskInfo>? taskInfo, boo
TaskInfo: taskInfo,
UserInfo: j.UserInfo,
Timestamp: j.Timestamp,
HasBugs: hasBugs
CrashReported: crashReported
);
public DateTimeOffset? StartTime => EndTime is DateTimeOffset endTime ? endTime.Subtract(TimeSpan.FromHours(Config.Duration)) : null;
}
Expand Down
1 change: 1 addition & 0 deletions src/ApiService/ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public static async Async.Task Main() {
.AddScoped<ISubnet, Subnet>()
.AddScoped<IAutoScaleOperations, AutoScaleOperations>()
.AddScoped<IAdoNotificationEntryOperations, AdoNotificationEntryOperations>()
.AddScoped<IJobCrashReportedOperations, JobCrashReportedOperations>()
.AddSingleton<GraphServiceClient>(new GraphServiceClient(new DefaultAzureCredential()))
.AddSingleton<DependencyTrackingTelemetryModule>()
.AddSingleton<ICreds, Creds>()
Expand Down
28 changes: 28 additions & 0 deletions src/ApiService/ApiService/onefuzzlib/JobCrashReported.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Threading.Tasks;
using ApiService.OneFuzzLib.Orm;
using Microsoft.Extensions.Logging;
namespace Microsoft.OneFuzz.Service;

public interface IJobCrashReportedOperations : IOrm<JobCrashReported> {
public Task<bool> CrashReported(Guid jobId);
public Task<OneFuzzResultVoid> ReportCrash(Guid jobId, Guid taskId);
}

public class JobCrashReportedOperations : Orm<JobCrashReported>, IJobCrashReportedOperations {
public JobCrashReportedOperations(ILogger<NsgOperations> logTracer, IOnefuzzContext context) : base(logTracer, context) {
}

public async Task<bool> CrashReported(Guid jobId) {
return await QueryAsync(Query.RowKey(jobId.ToString())).AnyAsync();
}

public async Task<OneFuzzResultVoid> ReportCrash(Guid jobId, Guid taskId) {

var result = await Update(new JobCrashReported(jobId, taskId));
if (!result.IsOk) {
return OneFuzzResultVoid.Error(ErrorCode.UNABLE_TO_UPDATE, "Failed to update job crash reported");
}

return OneFuzzResultVoid.Ok;
}
}
2 changes: 2 additions & 0 deletions src/ApiService/ApiService/onefuzzlib/OnefuzzContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface IOnefuzzContext {
IGithubIssues GithubIssues { get; }
IAdo Ado { get; }
IAdoNotificationEntryOperations AdoNotificationEntryOperations { get; }
IJobCrashReportedOperations JobCrashReportedOperations =>;

Check failure on line 53 in src/ApiService/ApiService/onefuzzlib/OnefuzzContext.cs

View workflow job for this annotation

GitHub Actions / service

Invalid expression term ';'

IFeatureManagerSnapshot FeatureManagerSnapshot { get; }
IConfigurationRefresher ConfigurationRefresher { get; }
Expand Down Expand Up @@ -102,6 +103,7 @@ public OnefuzzContext(IServiceProvider serviceProvider) {
public ITeams Teams => _serviceProvider.GetRequiredService<ITeams>();
public IGithubIssues GithubIssues => _serviceProvider.GetRequiredService<IGithubIssues>();
public IAdo Ado => _serviceProvider.GetRequiredService<IAdo>();
public IJobCrashReportedOperations JobCrashReportedOperations => _serviceProvider.GetRequiredService<IJobCrashReportedOperations>();

public IFeatureManagerSnapshot FeatureManagerSnapshot => _serviceProvider.GetRequiredService<IFeatureManagerSnapshot>();

Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/IntegrationTests/JobsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,6 @@ await Context.InsertAll(
var response = BodyAs<JobResponse>(result);
Assert.Equal(_jobId, response.JobId);
Assert.NotNull(response.TaskInfo);
Assert.True(response.HasBugs);
Assert.True(response.CrashReported);
}
}
2 changes: 1 addition & 1 deletion src/pytypes/onefuzztypes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class Job(BaseModel):
task_info: Optional[List[Union[Task, JobTaskInfo]]]
user_info: Optional[UserInfo]
start_time: Optional[datetime] = None
has_bugs: Optional[bool] = None
crash_reported: Optional[bool] = None


class NetworkConfig(BaseModel):
Expand Down

0 comments on commit 3cc48d9

Please sign in to comment.