зеркало из https://github.com/golang/build.git
cmd/coordinator: start of logging
For now, just log the process's start time and alive/heartbeat time. Updates golang/go#12669 Change-Id: I4dd28f7ba761b5487f86a4cdb0f721b2aeb4fa57 Reviewed-on: https://go-review.googlesource.com/22701 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Родитель
04c53475f9
Коммит
51b13f2f04
|
@ -29,6 +29,7 @@ import (
|
||||||
compute "google.golang.org/api/compute/v1"
|
compute "google.golang.org/api/compute/v1"
|
||||||
dm "google.golang.org/api/deploymentmanager/v2"
|
dm "google.golang.org/api/deploymentmanager/v2"
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
|
"google.golang.org/cloud/datastore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -241,6 +242,7 @@ func createCoordinator() error {
|
||||||
compute.DevstorageFullControlScope,
|
compute.DevstorageFullControlScope,
|
||||||
compute.ComputeScope,
|
compute.ComputeScope,
|
||||||
compute.CloudPlatformScope,
|
compute.CloudPlatformScope,
|
||||||
|
datastore.ScopeDatastore,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -55,7 +55,10 @@ import (
|
||||||
|
|
||||||
const subrepoPrefix = "golang.org/x/"
|
const subrepoPrefix = "golang.org/x/"
|
||||||
|
|
||||||
var processStartTime = time.Now()
|
var (
|
||||||
|
processStartTime = time.Now()
|
||||||
|
processID = "P" + randHex(9)
|
||||||
|
)
|
||||||
|
|
||||||
var Version string // set by linker -X
|
var Version string // set by linker -X
|
||||||
|
|
||||||
|
@ -268,6 +271,9 @@ func main() {
|
||||||
kubeErr = err
|
kubeErr = err
|
||||||
log.Printf("Kube support disabled due to eror initializing Kubernetes: %v", err)
|
log.Printf("Kube support disabled due to eror initializing Kubernetes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go updateInstanceRecord()
|
||||||
|
|
||||||
switch *mode {
|
switch *mode {
|
||||||
case "dev", "prod":
|
case "dev", "prod":
|
||||||
log.Printf("Running in %s mode", *mode)
|
log.Printf("Running in %s mode", *mode)
|
||||||
|
|
|
@ -33,6 +33,7 @@ import (
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
"google.golang.org/cloud"
|
"google.golang.org/cloud"
|
||||||
"google.golang.org/cloud/compute/metadata"
|
"google.golang.org/cloud/compute/metadata"
|
||||||
|
"google.golang.org/cloud/datastore"
|
||||||
"google.golang.org/cloud/storage"
|
"google.golang.org/cloud/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ func gceAPIGate() {
|
||||||
var (
|
var (
|
||||||
buildEnv *buildenv.Environment
|
buildEnv *buildenv.Environment
|
||||||
|
|
||||||
|
dsClient *datastore.Client
|
||||||
computeService *compute.Service
|
computeService *compute.Service
|
||||||
tokenSource oauth2.TokenSource
|
tokenSource oauth2.TokenSource
|
||||||
serviceCtx context.Context
|
serviceCtx context.Context
|
||||||
|
@ -122,6 +124,12 @@ func initGCE() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dsClient, err = datastore.NewClient(context.Background(), buildEnv.ProjectName)
|
||||||
|
if err != nil {
|
||||||
|
// TODO(bradfitz): make fatal later, once working.
|
||||||
|
log.Printf("Error creating datastore client: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
computeService, _ = compute.New(httpClient)
|
computeService, _ = compute.New(httpClient)
|
||||||
errTryDeps = checkTryBuildDeps()
|
errTryDeps = checkTryBuildDeps()
|
||||||
if errTryDeps != nil {
|
if errTryDeps != nil {
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/cloud/datastore"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Process is a datastore record about the lifetime of a coordinator process.
|
||||||
|
//
|
||||||
|
// Example GQL query:
|
||||||
|
// SELECT * From Process where LastHeartbeat > datetime("2016-01-01T00:00:00Z")
|
||||||
|
type Process struct {
|
||||||
|
ID string
|
||||||
|
Start time.Time
|
||||||
|
LastHeartbeat time.Time
|
||||||
|
|
||||||
|
// TODO: version, who deployed, CoreOS version, Docker version,
|
||||||
|
// GCE instance type?
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateInstanceRecord() {
|
||||||
|
if dsClient == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
for {
|
||||||
|
key := datastore.NewKey(ctx, "Process", processID, 0, nil)
|
||||||
|
_, err := dsClient.Put(ctx, key, &Process{
|
||||||
|
ID: processID,
|
||||||
|
Start: processStartTime,
|
||||||
|
LastHeartbeat: time.Now(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("datastore Process Put: %v", err)
|
||||||
|
}
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче