go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/autogardener/types.go (about)

     1  // Copyright 2022 The Fuchsia Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
     9  	resultpb "go.chromium.org/luci/resultdb/proto/v1"
    10  )
    11  
    12  // failureSignature represents a single failure mode of a Buildbucket build,
    13  // used for clustering builds to identify common failure modes.
    14  //
    15  // A single build might have multiple failure signatures.
    16  type failureSignature struct {
    17  	FailedTest    string `json:"failed_test"`
    18  	FailureReason string `json:"failure_reason"`
    19  
    20  	// TestGNLabel is the GN label of the failed test. It might be empty.
    21  	//
    22  	// TODO(olivernewman): GN label is just metadata and shouldn't be used for
    23  	// clustering. Figure out a way to avoid considering the GN label when
    24  	// grouping failed builds by failure mode; if a test gets moved from one GN
    25  	// label to another we shouldn't consider that a separate test.
    26  	TestGNLabel string `json:"gn_label"`
    27  
    28  	// TODO(olivernewman): also cluster by build summary text as a fallback.
    29  }
    30  
    31  // buildResult is a convenience type for bundling together the metadata of a
    32  // build with the failed test results.
    33  type buildResult struct {
    34  	Build       *buildbucketpb.Build
    35  	FailedTests []*resultpb.TestResult
    36  }
    37  
    38  func (b buildResult) integrationRevisionCount() (int, bool) {
    39  	outputProps := b.Build.Output.Properties.AsMap()
    40  	count, ok := outputProps["integration-revision-count"]
    41  	if !ok {
    42  		return 0, false
    43  	}
    44  	return int(count.(float64)), true
    45  }
    46  
    47  // culpritFeature represents a numerical feature used to estimate a potential
    48  // culprit change's likelihood of causing a given failure mode.
    49  type culpritFeature struct {
    50  	Name   string `json:"name"`
    51  	Score  int    `json:"score"`
    52  	Weight int    `json:"weight"`
    53  }