pass agent hostname to all rpc calls

This commit is contained in:
Brad Rydzewski 2017-07-20 12:21:15 -04:00
parent 1c01cd3612
commit eaa6d41699
4 changed files with 47 additions and 33 deletions

View file

@ -100,6 +100,9 @@ const (
func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error { func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
log.Println("pipeline: request next execution") log.Println("pipeline: request next execution")
meta, _ := metadata.FromOutgoingContext(ctx)
ctxmeta := metadata.NewOutgoingContext(context.Background(), meta)
// get the next job from the queue // get the next job from the queue
work, err := client.Next(ctx, filter) work, err := client.Next(ctx, filter)
if err != nil { if err != nil {
@ -121,7 +124,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
timeout = time.Duration(minutes) * time.Minute timeout = time.Duration(minutes) * time.Minute
} }
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(ctxmeta, timeout)
defer cancel() defer cancel()
cancelled := abool.New() cancelled := abool.New()
@ -150,7 +153,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
state := rpc.State{} state := rpc.State{}
state.Started = time.Now().Unix() state.Started = time.Now().Unix()
err = client.Init(context.Background(), work.ID, state) err = client.Init(ctxmeta, work.ID, state)
if err != nil { if err != nil {
log.Printf("pipeline: error signaling pipeline init: %s: %s", work.ID, err) log.Printf("pipeline: error signaling pipeline init: %s: %s", work.ID, err)
} }
@ -182,7 +185,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
file.Size = len(file.Data) file.Size = len(file.Data)
file.Time = time.Now().Unix() file.Time = time.Now().Unix()
if serr := client.Upload(context.Background(), work.ID, file); serr != nil { if serr := client.Upload(ctxmeta, work.ID, file); serr != nil {
log.Printf("pipeline: cannot upload logs: %s: %s: %s", work.ID, file.Mime, serr) log.Printf("pipeline: cannot upload logs: %s: %s: %s", work.ID, file.Mime, serr)
} else { } else {
log.Printf("pipeline: finish uploading logs: %s: step %s: %s", file.Mime, work.ID, proc.Alias) log.Printf("pipeline: finish uploading logs: %s: step %s: %s", file.Mime, work.ID, proc.Alias)
@ -207,7 +210,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
file.Size = len(file.Data) file.Size = len(file.Data)
file.Time = time.Now().Unix() file.Time = time.Now().Unix()
if serr := client.Upload(context.Background(), work.ID, file); serr != nil { if serr := client.Upload(ctxmeta, work.ID, file); serr != nil {
log.Printf("pipeline: cannot upload artifact: %s: %s: %s", work.ID, file.Mime, serr) log.Printf("pipeline: cannot upload artifact: %s: %s: %s", work.ID, file.Mime, serr)
} else { } else {
log.Printf("pipeline: finish uploading artifact: %s: step %s: %s", file.Mime, work.ID, proc.Alias) log.Printf("pipeline: finish uploading artifact: %s: step %s: %s", file.Mime, work.ID, proc.Alias)
@ -224,7 +227,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
Finished: time.Now().Unix(), Finished: time.Now().Unix(),
} }
defer func() { defer func() {
if uerr := client.Update(context.Background(), work.ID, procState); uerr != nil { if uerr := client.Update(ctxmeta, work.ID, procState); uerr != nil {
log.Printf("Pipeine: error updating pipeline step status: %s: %s: %s", work.ID, procState.Proc, uerr) log.Printf("Pipeine: error updating pipeline step status: %s: %s: %s", work.ID, procState.Proc, uerr)
} }
}() }()
@ -285,7 +288,7 @@ func run(ctx context.Context, client rpc.Peer, filter rpc.Filter) error {
log.Printf("pipeline: logging complete: %s", work.ID) log.Printf("pipeline: logging complete: %s", work.ID)
err = client.Done(context.Background(), work.ID, state) err = client.Done(ctxmeta, work.ID, state)
if err != nil { if err != nil {
log.Printf("Pipeine: error signaling pipeline done: %s: %s", work.ID, err) log.Printf("Pipeine: error signaling pipeline done: %s: %s", work.ID, err)
} else { } else {

View file

@ -79,6 +79,14 @@ type RPC struct {
// Next implements the rpc.Next function // Next implements the rpc.Next function
func (s *RPC) Next(c context.Context, filter rpc.Filter) (*rpc.Pipeline, error) { func (s *RPC) Next(c context.Context, filter rpc.Filter) (*rpc.Pipeline, error) {
metadata, ok := metadata.FromContext(c)
if ok {
hostname, ok := metadata["hostname"]
if ok && len(hostname) != 0 {
logrus.Debugf("agent connected: %s: polling", hostname[0])
}
}
fn := func(task *queue.Task) bool { fn := func(task *queue.Task) bool {
for k, v := range filter.Labels { for k, v := range filter.Labels {
if task.Labels[k] != v { if task.Labels[k] != v {

View file

@ -47,6 +47,9 @@ func (c *client) Next(ctx context.Context, f Filter) (*Pipeline, error) {
if grpc.Code(err) == codes.Unknown { if grpc.Code(err) == codes.Unknown {
return nil, err return nil, err
} }
if ctx.Err() != nil {
return nil, ctx.Err()
}
<-time.After(backoff) <-time.After(backoff)
} }

54
vendor/vendor.json vendored
View file

@ -39,80 +39,80 @@
{ {
"checksumSHA1": "W3AuK8ocqHwlUajGmQLFvnRhTZE=", "checksumSHA1": "W3AuK8ocqHwlUajGmQLFvnRhTZE=",
"path": "github.com/cncd/pipeline/pipeline", "path": "github.com/cncd/pipeline/pipeline",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "rO+djTfB4LrT+FBbpotyUUobOtU=", "checksumSHA1": "rO+djTfB4LrT+FBbpotyUUobOtU=",
"path": "github.com/cncd/pipeline/pipeline/backend", "path": "github.com/cncd/pipeline/pipeline/backend",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "DzP4c915B+gJTE5RCKQHzxwrUg4=", "checksumSHA1": "DzP4c915B+gJTE5RCKQHzxwrUg4=",
"path": "github.com/cncd/pipeline/pipeline/backend/docker", "path": "github.com/cncd/pipeline/pipeline/backend/docker",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "8Hj/OZnYZyz5N2hqENCTTaGtkNQ=", "checksumSHA1": "8Hj/OZnYZyz5N2hqENCTTaGtkNQ=",
"path": "github.com/cncd/pipeline/pipeline/frontend", "path": "github.com/cncd/pipeline/pipeline/frontend",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "9KYIsY8WlWbrRAP7caEpWT70P9c=", "checksumSHA1": "9KYIsY8WlWbrRAP7caEpWT70P9c=",
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "k+JVxks9V84qd+3kefHEtlqLEAA=", "checksumSHA1": "k+JVxks9V84qd+3kefHEtlqLEAA=",
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/compiler", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/compiler",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "Q0GkNUFamVYIA1Fd8r0A5M6Gx54=", "checksumSHA1": "Q0GkNUFamVYIA1Fd8r0A5M6Gx54=",
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/linter", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/linter",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "kx2sPUIMozPC/g6E4w48h3FfH3k=", "checksumSHA1": "kx2sPUIMozPC/g6E4w48h3FfH3k=",
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/matrix", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/matrix",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "L7Q5qJmPITNmvFEEaj5MPwCWFRk=", "checksumSHA1": "L7Q5qJmPITNmvFEEaj5MPwCWFRk=",
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/types", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/types",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "2/3f3oNmxXy5kcrRLCFa24Oc9O4=", "checksumSHA1": "2/3f3oNmxXy5kcrRLCFa24Oc9O4=",
"path": "github.com/cncd/pipeline/pipeline/interrupt", "path": "github.com/cncd/pipeline/pipeline/interrupt",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "uOjTfke7Qxosrivgz/nVTHeIP5g=", "checksumSHA1": "uOjTfke7Qxosrivgz/nVTHeIP5g=",
"path": "github.com/cncd/pipeline/pipeline/multipart", "path": "github.com/cncd/pipeline/pipeline/multipart",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "ndDase2wF8bWu83aDT8PFxVNSiU=", "checksumSHA1": "YlIaMsvB5fFXRolugambNzkSu4I=",
"path": "github.com/cncd/pipeline/pipeline/rpc", "path": "github.com/cncd/pipeline/pipeline/rpc",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "WAQJYKWUIFBnL1s8AnY4fePnzJ8=", "checksumSHA1": "WAQJYKWUIFBnL1s8AnY4fePnzJ8=",
"path": "github.com/cncd/pipeline/pipeline/rpc/proto", "path": "github.com/cncd/pipeline/pipeline/rpc/proto",
"revision": "a117e57da055285a2385d5f09314d1f3f8b8073e", "revision": "d98623616df20e535445b08baef41bde554454e3",
"revisionTime": "2017-07-19T00:51:24Z" "revisionTime": "2017-07-20T13:40:08Z"
}, },
{ {
"checksumSHA1": "7Qj1DK0ceAXkYztW0l3+L6sn+V8=", "checksumSHA1": "7Qj1DK0ceAXkYztW0l3+L6sn+V8=",