Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store build steps and logs as structured data [breaking change] #1981

Merged
merged 9 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enable granular step data for matrix
  • Loading branch information
bradrydzewski committed Apr 4, 2017
commit 16a07e660ad24d3306f64ff6504aa7e50928a453
9 changes: 7 additions & 2 deletions server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ func PostApproval(c *gin.Context) {
//
// publish topic
//
buildCopy := *build
buildCopy.Procs = model.Tree(buildCopy.Procs)
message := pubsub.Message{
Labels: map[string]string{
"repo": repo.FullName,
Expand All @@ -267,10 +269,11 @@ func PostApproval(c *gin.Context) {
message.Data, _ = json.Marshal(model.Event{
Type: model.Enqueued,
Repo: *repo,
Build: *build,
Build: buildCopy,
})
// TODO remove global reference
config.pubsub.Publish(c, "topic/events", message)

//
// end publish topic
//
Expand Down Expand Up @@ -517,6 +520,8 @@ func PostBuild(c *gin.Context) {
//
// publish topic
//
buildCopy := *build
buildCopy.Procs = model.Tree(buildCopy.Procs)
message := pubsub.Message{
Labels: map[string]string{
"repo": repo.FullName,
Expand All @@ -526,7 +531,7 @@ func PostBuild(c *gin.Context) {
message.Data, _ = json.Marshal(model.Event{
Type: model.Enqueued,
Repo: *repo,
Build: *build,
Build: buildCopy,
})
// TODO remove global reference
config.pubsub.Publish(c, "topic/events", message)
Expand Down
9 changes: 7 additions & 2 deletions server/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ func PostHook(c *gin.Context) {
}
}
}
store.FromContext(c).ProcCreate(build.Procs)
err = store.FromContext(c).ProcCreate(build.Procs)
if err != nil {
logrus.Errorf("error persisting procs %s/%d: %s", repo.FullName, build.Number, err)
}

//
// publish topic
Expand All @@ -304,10 +307,12 @@ func PostHook(c *gin.Context) {
"private": strconv.FormatBool(repo.IsPrivate),
},
}
buildCopy := *build
buildCopy.Procs = model.Tree(buildCopy.Procs)
message.Data, _ = json.Marshal(model.Event{
Type: model.Enqueued,
Repo: *repo,
Build: *build,
Build: buildCopy,
})
// TODO remove global reference
config.pubsub.Publish(c, "topic/events", message)
Expand Down
22 changes: 14 additions & 8 deletions server/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
}

build.Procs, _ = s.store.ProcList(build)
build.Procs = model.Tree(build.Procs)
message := pubsub.Message{
Labels: map[string]string{
"repo": repo.FullName,
Expand Down Expand Up @@ -305,29 +306,34 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
log.Printf("error: done: cannot ack proc_id %d: %s", procID, err)
}

done := false
status := model.StatusSuccess
// TODO handle this error
procs, _ := s.store.ProcList(build)
for _, p := range procs {
if p.Running() && p.PPID == proc.PID {
p.State = model.StatusSkipped
if p.Started != 0 {
p.State = model.StatusKilled
p.State = model.StatusSuccess // for deamons that are killed
p.Stopped = proc.Stopped
}
if err := s.store.ProcUpdate(p); err != nil {
log.Printf("error: done: cannot update proc_id %d child state: %s", p.ID, err)
}
}
if !p.Running() && p.PPID == 0 {
done = true
}

running := false
status := model.StatusSuccess
for _, p := range procs {
if p.PPID == 0 {
if p.Running() {
running = true
}
if p.Failing() {
status = model.StatusFailure
status = p.State
}
}
}
if done {
if !running {
build.Status = status
build.Finished = proc.Stopped
if err := s.store.UpdateBuild(build); err != nil {
Expand All @@ -339,7 +345,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
log.Printf("error: done: cannot close build_id %d logger: %s", proc.ID, err)
}

build.Procs = procs
build.Procs = model.Tree(procs)
message := pubsub.Message{
Labels: map[string]string{
"repo": repo.FullName,
Expand Down
1 change: 0 additions & 1 deletion store/datastore/ddl/mysql/13.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ CREATE TABLE procs (
,proc_platform VARCHAR(250)
,proc_environ VARCHAR(2000)
,UNIQUE(proc_build_id, proc_pid)
,UNIQUE(proc_build_id, proc_name)
);

CREATE INDEX proc_build_ix ON procs (proc_build_id);
Expand Down
1 change: 0 additions & 1 deletion store/datastore/ddl/postgres/13.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ CREATE TABLE procs (
,proc_environ VARCHAR(2000)

,UNIQUE(proc_build_id, proc_pid)
,UNIQUE(proc_build_id, proc_name)
);

CREATE INDEX proc_build_ix ON procs (proc_build_id);
Expand Down
1 change: 0 additions & 1 deletion store/datastore/ddl/sqlite3/13.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ CREATE TABLE procs (
,proc_platform TEXT
,proc_environ TEXT
,UNIQUE(proc_build_id, proc_pid)
,UNIQUE(proc_build_id, proc_name)
);

CREATE INDEX proc_build_ix ON procs (proc_build_id);
Expand Down