go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/proto.go (about)

     1  // Copyright 2018 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 buildbucket
    16  
    17  import (
    18  	"time"
    19  
    20  	"go.chromium.org/luci/common/data/stringset"
    21  	"go.chromium.org/luci/common/errors"
    22  
    23  	pb "go.chromium.org/luci/buildbucket/proto"
    24  )
    25  
    26  // This file contains helper functions for pb package.
    27  // TODO(nodir): move existing helpers from pb to this file.
    28  
    29  // BuildbucketTokenHeader is the name of gRPC metadata header indicating a
    30  // buildbucket token.
    31  //
    32  // Tokens include an authenticatable purpose field, we only need one header for
    33  // all incoming RPCs.
    34  const BuildbucketTokenHeader = "x-buildbucket-token"
    35  
    36  // BuildTokenHeader is the old name of the gRPC metadata header indicating the build
    37  // token (see BuildSecrets.BuildToken). It is still used by `kitchen`, but is
    38  // otherwise deprecated in favor of BuildbucketTokenHeader for all uses.
    39  //
    40  // DEPRECATED
    41  const BuildTokenHeader = "x-build-token"
    42  
    43  // DummyBuildbucketToken is the dummy token for led builds.
    44  const DummyBuildbucketToken = "dummy token"
    45  
    46  // MinUpdateBuildInterval is the minimum interval bbagent should call UpdateBuild.
    47  const MinUpdateBuildInterval = 30 * time.Second
    48  
    49  // Well-known experiment strings.
    50  //
    51  // See the Builder.experiments field documentation.
    52  const (
    53  	ExperimentBackendAlt          = "luci.buildbucket.backend_alt"
    54  	ExperimentBackendGo           = "luci.buildbucket.backend_go"
    55  	ExperimentBBAgent             = "luci.buildbucket.use_bbagent"
    56  	ExperimentBBAgentDownloadCipd = "luci.buildbucket.agent.cipd_installation"
    57  	ExperimentBBAgentGetBuild     = "luci.buildbucket.bbagent_getbuild"
    58  	ExperimentBBCanarySoftware    = "luci.buildbucket.canary_software"
    59  	ExperimentBqExporterGo        = "luci.buildbucket.bq_exporter_go"
    60  	ExperimentNonProduction       = "luci.non_production"
    61  	ExperimentParentTracking      = "luci.buildbucket.parent_tracking"
    62  	ExperimentWaitForCapacity     = "luci.buildbucket.wait_for_capacity_in_slices"
    63  )
    64  
    65  var (
    66  	// DuplicateTask means the backend has created multiple tasks for the same build.
    67  	// After the build has associated with one of those tasks (either by StartBuild or RegisterBuildTask),
    68  	// requests of associating other tasks with the build will fail with this error.
    69  	DuplicateTask = errors.BoolTag{Key: errors.NewTagKey("duplicate_backend_task")}
    70  	// TaskWithCollidedRequestID the backend has created multiple tasks for the same build,
    71  	// and two tasks among them have generated the same request_id for calling RegisterBuildTask.
    72  	TaskWithCollidedRequestID = errors.BoolTag{Key: errors.NewTagKey("task_with_collided_request_id")}
    73  )
    74  
    75  var (
    76  	// DisallowedAppendTagKeys is the set of tag keys which cannot be set via
    77  	// UpdateBuild. Clients calling UpdateBuild must strip these before making
    78  	// the request.
    79  	DisallowedAppendTagKeys = stringset.NewFromSlice("build_address", "buildset", "builder")
    80  )
    81  
    82  // WithoutDisallowedTagKeys returns tags whose key are not in
    83  // `DisallowedAppendTagKeys`.
    84  func WithoutDisallowedTagKeys(tags []*pb.StringPair) []*pb.StringPair {
    85  	if len(tags) == 0 {
    86  		return tags
    87  	}
    88  	ret := make([]*pb.StringPair, 0, len(tags))
    89  	for _, tag := range tags {
    90  		if !DisallowedAppendTagKeys.Has(tag.Key) {
    91  			ret = append(ret, tag)
    92  		}
    93  	}
    94  	return ret
    95  }