Merge pull request #2125 from bradrydzewski/master

Pass agent hostname to server and persist
This commit is contained in:
Brad Rydzewski
2017-07-19 22:46:43 -04:00
committed by GitHub
3 changed files with 33 additions and 1 deletions

View File

@@ -10,6 +10,8 @@ import (
oldcontext "golang.org/x/net/context"
"google.golang.org/grpc/metadata"
"github.com/Sirupsen/logrus"
"github.com/cncd/logging"
"github.com/cncd/pipeline/pipeline/rpc"
@@ -207,6 +209,14 @@ func (s *RPC) Upload(c context.Context, id string, file *rpc.File) error {
return err
}
metadata, ok := metadata.FromContext(c)
if ok {
hostname, ok := metadata["hostname"]
if ok && len(hostname) != 0 {
proc.Machine = hostname[0]
}
}
if file.Mime == "application/json+logs" {
return s.store.LogSave(
proc,
@@ -238,6 +248,13 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
log.Printf("error: cannot find proc with id %d: %s", procID, err)
return err
}
metadata, ok := metadata.FromContext(c)
if ok {
hostname, ok := metadata["hostname"]
if ok && len(hostname) != 0 {
proc.Machine = hostname[0]
}
}
build, err := s.store.GetBuild(proc.BuildID)
if err != nil {