go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/config/placeholder_projectconfig_creator.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 config
    16  
    17  import (
    18  	"google.golang.org/protobuf/proto"
    19  
    20  	"go.chromium.org/luci/analysis/internal/analysis/metrics"
    21  	configpb "go.chromium.org/luci/analysis/proto/config"
    22  )
    23  
    24  // createPlaceholderMonorailProject creates a Monorail project config with
    25  // fake values. The returned proto is for use at
    26  // ProjectConfig.bug_management.monorail.
    27  func createPlaceholderMonorailProject() *configpb.MonorailProject {
    28  	return &configpb.MonorailProject{
    29  		Project:         "chromium",
    30  		PriorityFieldId: 10,
    31  		DefaultFieldValues: []*configpb.MonorailFieldValue{
    32  			{
    33  				FieldId: 1234,
    34  				Value:   "Bug",
    35  			},
    36  		},
    37  		DisplayPrefix:    "crbug.com",
    38  		MonorailHostname: "bugs.chromium.org",
    39  	}
    40  }
    41  
    42  // createPlaceholderBuganizerProject creates a Buganizer project config
    43  // with fake values. The returned proto is for use at
    44  // ProjectConfig.bug_management.buganizer.
    45  func createPlaceholderBuganizerProject() *configpb.BuganizerProject {
    46  	return &configpb.BuganizerProject{
    47  		DefaultComponent: &configpb.BuganizerComponent{
    48  			Id: 1,
    49  		},
    50  	}
    51  }
    52  
    53  // Creates a placeholder Clustering config with default values.
    54  func createPlaceholderClustering() *configpb.Clustering {
    55  	return &configpb.Clustering{
    56  		TestNameRules: []*configpb.TestNameClusteringRule{
    57  			{
    58  				Name:         "Google Test (Value-parameterized)",
    59  				Pattern:      `^ninja:(?P<target>[\w/]+:\w+)/` + `(\w+/)?(?P<suite>\w+)\.(?P<case>\w+)/\w+$`,
    60  				LikeTemplate: `ninja:${target}/%${suite}.${case}%`,
    61  			},
    62  			{
    63  				Name:         "Google Test (Type-parameterized)",
    64  				Pattern:      `^ninja:(?P<target>[\w/]+:\w+)/` + `(\w+/)?(?P<suite>\w+)/\w+\.(?P<case>\w+)$`,
    65  				LikeTemplate: `ninja:${target}/%${suite}/%.${case}`,
    66  			},
    67  		},
    68  		ReasonMaskPatterns: []string{
    69  			`^\[Fixture failure\] ([a-zA-Z0-9_]+)[:]`,
    70  		},
    71  	}
    72  }
    73  
    74  func createPlaceholderMetrics() *configpb.Metrics {
    75  	return &configpb.Metrics{
    76  		Overrides: []*configpb.Metrics_MetricOverride{
    77  			{
    78  				MetricId:     string(metrics.HumanClsFailedPresubmit.ID),
    79  				IsDefault:    proto.Bool(true),
    80  				SortPriority: proto.Int32(1000),
    81  			},
    82  			{
    83  				MetricId:     string(metrics.Failures.ID),
    84  				IsDefault:    proto.Bool(false),
    85  				SortPriority: proto.Int32(10),
    86  			},
    87  		},
    88  	}
    89  }
    90  
    91  func createPlaceholderBugManagementPolicies() []*configpb.BugManagementPolicy {
    92  	return []*configpb.BugManagementPolicy{
    93  		CreatePlaceholderBugManagementPolicy("exoneration"),
    94  	}
    95  }
    96  
    97  func CreatePlaceholderBugManagementPolicy(id string) *configpb.BugManagementPolicy {
    98  	return &configpb.BugManagementPolicy{
    99  		Id:                id,
   100  		Owners:            []string{"username@google.com"},
   101  		HumanReadableName: "test variant(s) are being exonerated in presubmit",
   102  		Priority:          configpb.BuganizerPriority_P2,
   103  		Metrics: []*configpb.BugManagementPolicy_Metric{
   104  			{
   105  				MetricId: "critical-failures-exonerated",
   106  				ActivationThreshold: &configpb.MetricThreshold{
   107  					OneDay: proto.Int64(50),
   108  				},
   109  				DeactivationThreshold: &configpb.MetricThreshold{
   110  					ThreeDay: proto.Int64(20),
   111  				},
   112  			},
   113  		},
   114  		Explanation: &configpb.BugManagementPolicy_Explanation{
   115  			ProblemHtml: "Test variant(s) in the cluster are being exonerated because they are too flaky or failing.",
   116  			ActionHtml:  "<ul><li>View recent failures and fix them</li><li>Demote the test(s) from CQ</li></ul>",
   117  		},
   118  		BugTemplate: &configpb.BugManagementPolicy_BugTemplate{
   119  			CommentTemplate: `Policy ID: ` + id + "\n" +
   120  				`{{if .BugID.IsBuganizer }}Buganizer Bug ID: {{ .BugID.BuganizerBugID }}{{end}}` +
   121  				`{{if .BugID.IsMonorail }}Monorail Project: {{ .BugID.MonorailProject }}; ID: {{ .BugID.MonorailBugID }}{{end}}` +
   122  				`Rule URL: {{.RuleURL}}`,
   123  			Monorail: &configpb.BugManagementPolicy_BugTemplate_Monorail{
   124  				Labels: []string{"Test-Exonerated"},
   125  			},
   126  			Buganizer: &configpb.BugManagementPolicy_BugTemplate_Buganizer{
   127  				Hotlists: []int64{1234},
   128  			},
   129  		},
   130  	}
   131  }
   132  
   133  // CreateConfigWithBothBuganizerAndMonorail creates a placeholder config
   134  // for a project that uses both Monorail and Buganizer.
   135  func CreateConfigWithBothBuganizerAndMonorail(defaultBugSystem configpb.BugSystem) *configpb.ProjectConfig {
   136  	return &configpb.ProjectConfig{
   137  		Clustering: createPlaceholderClustering(),
   138  		Metrics:    createPlaceholderMetrics(),
   139  		BugManagement: &configpb.BugManagement{
   140  			Policies:         createPlaceholderBugManagementPolicies(),
   141  			DefaultBugSystem: defaultBugSystem,
   142  			Monorail:         createPlaceholderMonorailProject(),
   143  			Buganizer:        createPlaceholderBuganizerProject(),
   144  		},
   145  		TestStabilityCriteria: &configpb.TestStabilityCriteria{
   146  			FailureRate: &configpb.TestStabilityCriteria_FailureRateCriteria{
   147  				FailureThreshold:            6,
   148  				ConsecutiveFailureThreshold: 3,
   149  			},
   150  			FlakeRate: &configpb.TestStabilityCriteria_FlakeRateCriteria{
   151  				MinWindow:          100,
   152  				FlakeThreshold:     2,
   153  				FlakeRateThreshold: 0.01,
   154  			},
   155  		},
   156  	}
   157  }