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:
Brad Fitzpatrick 2016-05-02 16:42:38 +00:00
Родитель 04c53475f9
Коммит 51b13f2f04
4 изменённых файлов: 63 добавлений и 1 удалений

Просмотреть файл

@ -29,6 +29,7 @@ import (
compute "google.golang.org/api/compute/v1"
dm "google.golang.org/api/deploymentmanager/v2"
"google.golang.org/api/googleapi"
"google.golang.org/cloud/datastore"
)
var (
@ -241,6 +242,7 @@ func createCoordinator() error {
compute.DevstorageFullControlScope,
compute.ComputeScope,
compute.CloudPlatformScope,
datastore.ScopeDatastore,
},
},
},

Просмотреть файл

@ -55,7 +55,10 @@ import (
const subrepoPrefix = "golang.org/x/"
var processStartTime = time.Now()
var (
processStartTime = time.Now()
processID = "P" + randHex(9)
)
var Version string // set by linker -X
@ -268,6 +271,9 @@ func main() {
kubeErr = err
log.Printf("Kube support disabled due to eror initializing Kubernetes: %v", err)
}
go updateInstanceRecord()
switch *mode {
case "dev", "prod":
log.Printf("Running in %s mode", *mode)

Просмотреть файл

@ -33,6 +33,7 @@ import (
"google.golang.org/api/googleapi"
"google.golang.org/cloud"
"google.golang.org/cloud/compute/metadata"
"google.golang.org/cloud/datastore"
"google.golang.org/cloud/storage"
)
@ -53,6 +54,7 @@ func gceAPIGate() {
var (
buildEnv *buildenv.Environment
dsClient *datastore.Client
computeService *compute.Service
tokenSource oauth2.TokenSource
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)
errTryDeps = checkTryBuildDeps()
if errTryDeps != nil {

46
cmd/coordinator/log.go Normal file
Просмотреть файл

@ -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)
}
}