Skip to content

Commit e42afb7

Browse files
committed
cmd/coordinator: give each build and try set a globally unique random ID
These IDs will become the cloud datastore keys for keeping history and logs. Many more CLs will follow: changing farmer URLs, logging to datastore, fetching old logs from datastore, etc. Updates golang/go#13076 (make all logs URLs permanent) Updates golang/go#12669 (collect logs, stats) Change-Id: I5b9fd21bf23581c59724b0ed32c8459baa9683f7 Reviewed-on: https://go-review.googlesource.com/21968 Reviewed-by: Andrew Gerrand <[email protected]>
1 parent 00477ab commit e42afb7

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cmd/coordinator/coordinator.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"archive/tar"
1616
"bytes"
1717
"compress/gzip"
18+
"crypto/rand"
1819
"crypto/sha1"
1920
"crypto/tls"
2021
"encoding/json"
@@ -831,6 +832,7 @@ func (k *tryKey) ChangeTriple() string {
831832
type trySet struct {
832833
// immutable
833834
tryKey
835+
tryID string // "T" + 9 random hex
834836

835837
// mu guards state and errMsg
836838
// See LOCK ORDER comment above.
@@ -878,6 +880,7 @@ func newTrySet(key tryKey) (*trySet, error) {
878880
log.Printf("Starting new trybot set for %v", key)
879881
ts := &trySet{
880882
tryKey: key,
883+
tryID: "T" + randHex(9),
881884
trySetState: trySetState{
882885
remain: len(builders),
883886
builds: make([]*buildStatus, len(builders)),
@@ -1202,6 +1205,7 @@ func newBuild(rev builderRev) (*buildStatus, error) {
12021205
}
12031206
ctx, cancel := context.WithCancel(context.Background())
12041207
return &buildStatus{
1208+
buildID: "B" + randHex(9),
12051209
builderRev: rev,
12061210
conf: conf,
12071211
startTime: time.Now(),
@@ -2516,8 +2520,9 @@ type eventAndTime struct {
25162520
type buildStatus struct {
25172521
// Immutable:
25182522
builderRev
2523+
buildID string // "B" + 9 random hex
25192524
conf dashboard.BuildConfig
2520-
startTime time.Time // actually time of newBuild (~same thing)
2525+
startTime time.Time // actually time of newBuild (~same thing); TODO(bradfitz): rename this createTime
25212526
trySet *trySet // or nil
25222527

25232528
onceInitHelpers sync.Once // guards call of onceInitHelpersFunc
@@ -2897,3 +2902,11 @@ func newFailureLogBlob(objName string) (obj io.WriteCloser, url_ string) {
28972902

28982903
return wr, fmt.Sprintf("https://storage.googleapis.com/%s/%s", bucket, objName)
28992904
}
2905+
2906+
func randHex(n int) string {
2907+
buf := make([]byte, n/2+1)
2908+
if _, err := rand.Read(buf); err != nil {
2909+
log.Fatalf("randHex: %v", err)
2910+
}
2911+
return fmt.Sprintf("%x", buf)[:n]
2912+
}

cmd/coordinator/gce.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package main
99

1010
import (
11-
"crypto/rand"
1211
"encoding/json"
1312
"errors"
1413
"fmt"
@@ -578,12 +577,3 @@ func hasComputeScope() bool {
578577
func hasStorageScope() bool {
579578
return hasScope(storage.ScopeReadWrite) || hasScope(storage.ScopeFullControl) || hasScope(compute.CloudPlatformScope)
580579
}
581-
582-
func randHex(n int) string {
583-
buf := make([]byte, n/2)
584-
_, err := rand.Read(buf)
585-
if err != nil {
586-
panic("Failed to get randomness: " + err.Error())
587-
}
588-
return fmt.Sprintf("%x", buf)
589-
}

0 commit comments

Comments
 (0)