go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/bugs/interface.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 bugs 16 17 import ( 18 "time" 19 20 "go.chromium.org/luci/analysis/internal/analysis/metrics" 21 bugspb "go.chromium.org/luci/analysis/internal/bugs/proto" 22 "go.chromium.org/luci/analysis/internal/clustering" 23 ) 24 25 type BugUpdateRequest struct { 26 // The bug to update. 27 Bug BugID 28 // Whether the user enabled priority updates and auto-closure for the bug. 29 // If this if false, the BugUpdateRequest is only made to determine if the 30 // bug is the duplicate of another bug and if the rule should be archived. 31 IsManagingBug bool 32 // Whether the user enabled priority updates for the Bug. 33 // If this is false, the bug priority will not change. 34 IsManagingBugPriority bool 35 // The time when the field `IsManagingBugPriority` was last updated. 36 // This is used to determine whether or not we should make priority updates by 37 // if the user manually took control of the bug priority before 38 // or after automatic priority updates were (re-)enabled. 39 IsManagingBugPriorityLastUpdated time.Time 40 // The identity of the rule associated with the bug. 41 RuleID string 42 // The bug management state of the rule. Only set if policy-based bug 43 // management should be used; see Metrics field otherwise. 44 BugManagementState *bugspb.BugManagementState 45 } 46 47 type BugUpdateResponse struct { 48 // Error is the error encountered updating this specific bug (if any). 49 // 50 // Even if an error is set here, partial success is possible and 51 // actions may have been taken on the bug which require corresponding 52 // rule updates. As such, even if an error is set here, the consumer 53 // of this response must action the rule updates specified by 54 // DisableRulePriorityUpdates, RuleAssociationNotified and 55 // PolicyActivationsNotified to avoid us unnecessarily repeating 56 // these actions on the bug the next time bug management runs. 57 // 58 // Similarly, even when an error occurs, the producer of this response 59 // still has an an obligation to set DisableRulePriorityUpdates, 60 // RuleAssociationNotified and PolicyActivationsNotified correctly. 61 // In case of complete failures, leaving DisableRulePriorityUpdates 62 // and PolicyActivationsNotified set to false, and PolicyActivationsNotified 63 // empty will satisfy this requirement. 64 Error error 65 66 // IsDuplicate is set if the bug is a duplicate of another. 67 // Set to true to trigger updating/merging failure association rules. 68 // 69 // If we could not fetch the bug for some reason and cannot determine 70 // if the bug should be archived, this must be set to false. 71 IsDuplicate bool 72 73 // IsDuplicateAndAssigned is set if the bug is assigned to a user. 74 // Only set if IsDuplicate is set. 75 IsDuplicateAndAssigned bool 76 77 // ShouldArchive indicates if the rule for this bug should be archived. 78 // This should be set if: 79 // - The bug is managed by LUCI Analysis (IsManagingBug = true) and it has 80 // been marked as Closed (verified) by LUCI Analysis for the last 30 81 // days. 82 // - The bug is managed by the user (IsManagingBug = false), and the 83 // bug has been closed for the last 30 days. 84 // 85 // If we could not fetch the bug for some reason and cannot determine 86 // if the bug should be archived, this must be set to false. 87 ShouldArchive bool 88 89 // DisableRulePriorityUpdates indicates that the rules `IsManagingBugUpdates` 90 // field should be disabled. 91 // This is set when a user manually takes control of the priority of a bug. 92 // 93 // If we could not fetch the bug for some reason and cannot determine 94 // if the user has taken control of the bug, this must be set to false. 95 DisableRulePriorityUpdates bool 96 97 // Whether the association between the rule and the bug was notified. 98 // Set to true to set BugManagementState.RuleAssociationNotified. 99 RuleAssociationNotified bool 100 101 // The set of policy IDs for which activation was notified. 102 // This may differ from the set which is pending notification in the case of 103 // partial or total failure to update the bug. 104 // If a policy ID is included here, 105 // BugManagementState.Policies[<policyID>].ActivationNotified will be 106 // set to true on the rule. 107 PolicyActivationsNotified map[PolicyID]struct{} 108 } 109 110 // DuplicateBugDetails holds the data of a duplicate bug, this includes it's bug id, 111 // and whether or not it is assigned to a user. 112 type DuplicateBugDetails struct { 113 // The rule ID. 114 RuleID string 115 // Bug is the source bug that was merged-into another bug. 116 Bug BugID 117 // IsAssigned indicated whether this bug is assigned or not. 118 IsAssigned bool 119 } 120 121 // UpdateDuplicateSourceRequest represents a request to update the source 122 // bug of a duplicate bug (source bug, destination bug) pair, after 123 // LUCI Analysis has attempted to merge the failure association rule 124 // of the source to the destination. 125 type UpdateDuplicateSourceRequest struct { 126 // BugDetails are details of the bug to be updated. 127 // This includes the bug ID and whether or not it is assigned. 128 BugDetails DuplicateBugDetails 129 // ErrorMessage is the error that occured handling the duplicate bug. 130 // If this is set, it will be posted to the bug and bug will marked as 131 // no longer a duplicate to avoid repeately triggering the same error. 132 ErrorMessage string 133 // DestinationRuleID is the rule ID for the destination bug, that the rule 134 // for the source bug was merged into. 135 // Only populated if Error is unset. 136 DestinationRuleID string 137 } 138 139 // BugCreateRequest captures a request to a bug filing system to 140 // file a new bug for a suggested cluster. 141 type BugCreateRequest struct { 142 // The ID of the rule that is in the process of being created. 143 RuleID string 144 // Description is the human-readable description of the cluster. 145 Description *clustering.ClusterDescription 146 // The monorail components (if any) to use. 147 // This value is ignored for Buganizer. 148 MonorailComponents []string 149 // The buganizer component id (if any) to use. 150 // This value is ignored for Monorail. 151 BuganizerComponent int64 152 // The bug management policies which activated for this 153 // cluster and are triggering the filing of this bug. 154 ActivePolicyIDs map[PolicyID]struct{} 155 } 156 157 type BugCreateResponse struct { 158 // The error encountered creating the bug. Note that this error 159 // may have occured after a partial success; for example, we may have 160 // successfully created a bug but failed on a subequent RPC to 161 // posting comments for the policies that have activated. 162 // 163 // In the case of partial success, ID shall still be set to allow 164 // creation of the rule. This avoids duplicate bugs being created 165 // from repeated failed attempts to completely create a bug. 166 // The policies for which comments could not be posted will 167 // not be set to true under BugManagementState.Policies[<policyID>].ActivationNotified 168 // so that these are retried as part of the bug update process. 169 Error error 170 171 // Simulated indicates whether the bug creation was simulated, 172 // i.e. did not actually occur. If this is set, the returned 173 // bug ID should be ignored. 174 Simulated bool 175 176 // The system-specific bug ID for the bug that was created. 177 // See BugID.ID. 178 // If we failed to create a bug, set to "" (empty). 179 ID string 180 181 // The set of policy IDs for which activation was successfully notified. 182 // This may differ from the list in the request in the case of 183 // partial or total failure to create the bug. 184 // If a policy ID is included here, 185 // BugManagementState.Policies[<policyID>].ActivationNotified will be 186 // set to true on the rule. 187 PolicyActivationsNotified map[PolicyID]struct{} 188 } 189 190 // ClusterMetrics captures measurements of a cluster's impact and 191 // other variables, as needed to control the priority and verified 192 // status of bugs. 193 type ClusterMetrics map[metrics.ID]MetricValues 194 195 // MetricValues captures measurements for one metric, over 196 // different timescales. 197 type MetricValues struct { 198 OneDay int64 199 ThreeDay int64 200 SevenDay int64 201 }