示例#1
0
        public ModelTrackingIssueResult AddTrackingResult(
            ModelTrackingIssue trackingIssue,
            ModelBuildAttempt attempt,
            bool isPresent = true)
        {
            var result = new ModelTrackingIssueResult()
            {
                ModelTrackingIssue = trackingIssue,
                ModelBuildAttempt  = attempt,
                IsPresent          = isPresent,
            };

            Context.ModelTrackingIssueResults.Add(result);
            return(result);
        }
示例#2
0
        public async Task TriageAsync(ModelBuildAttempt modelBuildAttempt, ModelTrackingIssue modelTrackingIssue)
        {
            if (modelBuildAttempt.ModelBuild is null)
            {
                throw new Exception("The attempt must include the build");
            }

            if (modelTrackingIssue.ModelBuildDefinitionId is { } definitionId&&
                definitionId != modelBuildAttempt.ModelBuild.ModelBuildDefinitionId)
            {
                return;
            }

            // Quick spot check to avoid doing extra work if we've already triaged this attempt against this
            // issue
            if (await WasTriaged().ConfigureAwait(false))
            {
                return;
            }

            bool isPresent;

            switch (modelTrackingIssue.TrackingKind)
            {
            case TrackingKind.Test:
                isPresent = await TriageTestAsync(modelBuildAttempt, modelTrackingIssue).ConfigureAwait(false);

                break;

            case TrackingKind.Timeline:
                isPresent = await TriageTimelineAsync(modelBuildAttempt, modelTrackingIssue).ConfigureAwait(false);

                break;

            case TrackingKind.HelixLogs:
                isPresent = await TriageHelixLogsAsync(modelBuildAttempt, modelTrackingIssue).ConfigureAwait(false);

                break;

#pragma warning disable 618
            case TrackingKind.HelixConsole:
            case TrackingKind.HelixRunClient:
                // TODO: delete this once the DB is cleaned up
                // These are old data types that we ignore.
                isPresent = false;
                break;

#pragma warning restore 618
            default:
                throw new Exception($"Unknown value {modelTrackingIssue.TrackingKind}");
            }

            var result = new ModelTrackingIssueResult()
            {
                ModelBuildAttempt  = modelBuildAttempt,
                ModelTrackingIssue = modelTrackingIssue,
                IsPresent          = isPresent
            };
            Context.ModelTrackingIssueResults.Add(result);

            // This can race with other attempts to associate issues here. That is okay though because triage attempts are
            // retried because they assume races with other operations can happen.
            if (isPresent && modelTrackingIssue.GetGitHubIssueKey() is { } issueKey)
            {
                await TriageContextUtil.EnsureGitHubIssueAsync(modelBuildAttempt.ModelBuild, issueKey, saveChanges : false).ConfigureAwait(false);
            }

            await Context.SaveChangesAsync().ConfigureAwait(false);

            async Task <bool> WasTriaged()
            {
                var query = Context
                            .ModelTrackingIssueResults
                            .Where(x => x.ModelBuildAttemptId == modelBuildAttempt.Id && x.ModelTrackingIssueId == modelTrackingIssue.Id);

                return(await query.AnyAsync().ConfigureAwait(false));
            }
        }