go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/clustering/failure.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 clustering 16 17 import ( 18 "google.golang.org/protobuf/proto" 19 20 cpb "go.chromium.org/luci/analysis/internal/clustering/proto" 21 pb "go.chromium.org/luci/analysis/proto/v1" 22 ) 23 24 // Failure captures the minimal information required to cluster a failure. 25 // This is a subset of the information captured by LUCI Analysis for failures. 26 type Failure struct { 27 // The name of the test that failed. 28 TestID string 29 // The failure reason explaining the reason why the test failed. 30 Reason *pb.FailureReason 31 } 32 33 // FailureFromProto extracts failure information relevant for clustering from 34 // a LUCI Analysis failure proto. 35 func FailureFromProto(f *cpb.Failure) *Failure { 36 result := &Failure{ 37 TestID: f.TestId, 38 } 39 if f.FailureReason != nil { 40 result.Reason = proto.Clone(f.FailureReason).(*pb.FailureReason) 41 } 42 return result 43 } 44 45 // FailuresFromProtos extracts failure information relevant for clustering 46 // from a set of LUCI Analysis failure protos. 47 func FailuresFromProtos(protos []*cpb.Failure) []*Failure { 48 result := make([]*Failure, len(protos)) 49 for i, p := range protos { 50 result[i] = FailureFromProto(p) 51 } 52 return result 53 }