go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/rerun/priority.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package rerun
    16  
    17  import (
    18  	"context"
    19  	"time"
    20  
    21  	"go.chromium.org/luci/bisection/model"
    22  	"go.chromium.org/luci/bisection/util/datastoreutil"
    23  )
    24  
    25  // These constants are used for offsetting the buildbucket run priortity
    26  // The priority ranges from 20 - 255. Lower number means higher priority.
    27  // See go/luci-bisection-run-prioritization for more details.
    28  const (
    29  	// Baseline priority
    30  	PriorityCulpritVerificationHighConfidence   = 100
    31  	PriorityCulpritVerificationMediumConfidence = 120
    32  	PriorityCulpritVerificationLowConfidence    = 140
    33  	PriorityNthSection                          = 130
    34  	PriorityTestFailure                         = 160
    35  
    36  	// Offset priority
    37  	PriorityTreeClosureOffset                    = -70
    38  	PriorityShortBuildOffset                     = -20
    39  	PriorityMediumBuildOffset                    = -10
    40  	PriorityLongBuildOffset                      = 0
    41  	PriorityVeryLongBuildOffset                  = 40
    42  	PriorityAnalysisTriggeredByNonSheriffsOffset = -5
    43  	PriorityAnalysisTriggeredBySheriffsOffset    = -10
    44  	PriorityFlakyBuilderOffset                   = 50
    45  	PriorityAnotherVerificationBuildExistOffset  = 20
    46  	PrioritySuspectInMultipleFailedBuildOffset   = -20
    47  	PrioritySuspectIsRevertedOffset              = 25
    48  	PriorityNthSectionNoSuspectOffset            = -10
    49  	PriorityScheduleOnSameBotOffset              = -15
    50  )
    51  
    52  // CapPriority caps priority into the range [20..255]
    53  func CapPriority(priority int32) int32 {
    54  	if priority < 20 {
    55  		return 20
    56  	}
    57  	if priority > 255 {
    58  		return 255
    59  	}
    60  	return priority
    61  }
    62  
    63  // OffsetPriorityBasedOnRunDuration offsets the priority based on run duration.
    64  // See go/luci-bisection-run-prioritization
    65  // We based on the duration of the failed build to adjust the priority
    66  // We favor faster builds than longer builds
    67  func OffsetPriorityBasedOnRunDuration(c context.Context, priority int32, cfa *model.CompileFailureAnalysis) (int32, error) {
    68  	failedBuild, err := datastoreutil.GetFailedBuildForAnalysis(c, cfa)
    69  	if err != nil {
    70  		return 0, err
    71  	}
    72  
    73  	duration := failedBuild.EndTime.Sub(failedBuild.StartTime)
    74  	if duration < 10*time.Minute {
    75  		return priority - 20, nil
    76  	}
    77  	if duration < time.Minute*30 {
    78  		return priority - 10, nil
    79  	}
    80  	if duration < time.Hour {
    81  		return priority, nil
    82  	}
    83  	if duration < 2*time.Hour {
    84  		return priority + 20, nil
    85  	}
    86  	return priority + 40, nil
    87  }