go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/ingestion/join/invocation.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 join 16 17 import ( 18 "context" 19 "strconv" 20 21 "go.chromium.org/luci/common/errors" 22 "go.chromium.org/luci/resultdb/pbutil" 23 rdbpb "go.chromium.org/luci/resultdb/proto/v1" 24 "go.chromium.org/luci/server/auth/realms" 25 26 "go.chromium.org/luci/analysis/internal/ingestion/control" 27 controlpb "go.chromium.org/luci/analysis/internal/ingestion/control/proto" 28 ) 29 30 // JoinInvocation notifies ingestion that the given invocation has finalized. 31 // Ingestion tasks are created for buildbucket builds when all required data 32 // for a build (including any invocation) is available. 33 func JoinInvocation(ctx context.Context, notification *rdbpb.InvocationFinalizedNotification) (processed bool, err error) { 34 project, _ := realms.Split(notification.Realm) 35 id, err := pbutil.ParseInvocationName(notification.Invocation) 36 if err != nil { 37 return false, errors.Annotate(err, "parse invocation name").Err() 38 } 39 40 match := buildInvocationRE.FindStringSubmatch(id) 41 if match == nil { 42 // Invocations that are not of the form build-<BUILD ID> are ignored. 43 return false, nil 44 } 45 bbBuildID, err := strconv.ParseInt(match[1], 10, 64) 46 if err != nil { 47 return false, errors.Annotate(err, "parse build ID").Err() 48 } 49 50 // This proto has no fields for now. If we need to pass anything about the invocation, 51 // we can add it in here in future. 52 result := &controlpb.InvocationResult{} 53 54 buildID := control.BuildID(bbHost, bbBuildID) 55 if err := JoinInvocationResult(ctx, buildID, project, result); err != nil { 56 return true, errors.Annotate(err, "joining invocation result").Err() 57 } 58 return true, nil 59 }