Skip to content

Commit 915246a

Browse files
committed
add build substatus
1 parent 53a4d1b commit 915246a

33 files changed

+2050
-242
lines changed

api/protobuf-spec/github_com_openshift_origin_pkg_build_api_v1.proto

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger-spec/oapi-v1.json

+52
Original file line numberDiff line numberDiff line change
@@ -24394,6 +24394,13 @@
2439424394
"output": {
2439524395
"$ref": "v1.BuildStatusOutput",
2439624396
"description": "output describes the Docker image the build has produced."
24397+
},
24398+
"stages": {
24399+
"type": "array",
24400+
"items": {
24401+
"$ref": "v1.StageInfo"
24402+
},
24403+
"description": "stages contains details about each stage that occurs during the build including start time, duration (in milliseconds), and the steps that occured within each stage."
2439724404
}
2439824405
}
2439924406
},
@@ -24417,6 +24424,51 @@
2441724424
}
2441824425
}
2441924426
},
24427+
"v1.StageInfo": {
24428+
"id": "v1.StageInfo",
24429+
"description": "StageInfo contains details about a build stage.",
24430+
"properties": {
24431+
"name": {
24432+
"type": "string",
24433+
"description": "name is a unique identifier for each build stage that occurs."
24434+
},
24435+
"startTime": {
24436+
"type": "string",
24437+
"description": "startTime is a timestamp representing the server time when this Stage started. It is represented in RFC3339 form and is in UTC."
24438+
},
24439+
"durationMilliseconds": {
24440+
"type": "integer",
24441+
"format": "int64",
24442+
"description": "durationMilliseconds identifies how long the stage took to complete in milliseconds. Note: the duration of a stage can exceed the sum of the duration of the steps within the stage as not all actions are accounted for in explicit build steps."
24443+
},
24444+
"steps": {
24445+
"type": "array",
24446+
"items": {
24447+
"$ref": "v1.StepInfo"
24448+
},
24449+
"description": "steps contains details about each step that occurs during a build stage including start time and duration in milliseconds."
24450+
}
24451+
}
24452+
},
24453+
"v1.StepInfo": {
24454+
"id": "v1.StepInfo",
24455+
"description": "StepInfo contains details about a build step.",
24456+
"properties": {
24457+
"name": {
24458+
"type": "string",
24459+
"description": "name is a unique identifier for each build step."
24460+
},
24461+
"startTime": {
24462+
"type": "string",
24463+
"description": "startTime is a timestamp representing the server time when this Step started. it is represented in RFC3339 form and is in UTC."
24464+
},
24465+
"durationMilliseconds": {
24466+
"type": "integer",
24467+
"format": "int64",
24468+
"description": "durationMilliseconds identifies how long the step took to complete in milliseconds."
24469+
}
24470+
}
24471+
},
2442024472
"v1.BuildLog": {
2442124473
"id": "v1.BuildLog",
2442224474
"description": "BuildLog is the (unused) resource associated with the build log redirector",

api/swagger-spec/openshift-openapi-spec.json

+50
Original file line numberDiff line numberDiff line change
@@ -68300,6 +68300,13 @@
6830068300
"description": "reason is a brief CamelCase string that describes any failure and is meant for machine parsing and tidy display in the CLI.",
6830168301
"type": "string"
6830268302
},
68303+
"stages": {
68304+
"description": "stages contains details about each stage that occurs during the build including start time, duration (in milliseconds), and the steps that occured within each stage.",
68305+
"type": "array",
68306+
"items": {
68307+
"$ref": "#/definitions/v1.StageInfo"
68308+
}
68309+
},
6830368310
"startTimestamp": {
6830468311
"description": "startTimestamp is a timestamp representing the server time when this Build started running in a Pod. It is represented in RFC3339 form and is in UTC.",
6830568312
"$ref": "#/definitions/unversioned.Time"
@@ -76213,6 +76220,49 @@
7621376220
}
7621476221
}
7621576222
},
76223+
"v1.StageInfo": {
76224+
"description": "StageInfo contains details about a build stage.",
76225+
"properties": {
76226+
"durationMilliseconds": {
76227+
"description": "durationMilliseconds identifies how long the stage took to complete in milliseconds. Note: the duration of a stage can exceed the sum of the duration of the steps within the stage as not all actions are accounted for in explicit build steps.",
76228+
"type": "integer",
76229+
"format": "int64"
76230+
},
76231+
"name": {
76232+
"description": "name is a unique identifier for each build stage that occurs.",
76233+
"type": "string"
76234+
},
76235+
"startTime": {
76236+
"description": "startTime is a timestamp representing the server time when this Stage started. It is represented in RFC3339 form and is in UTC.",
76237+
"$ref": "#/definitions/unversioned.Time"
76238+
},
76239+
"steps": {
76240+
"description": "steps contains details about each step that occurs during a build stage including start time and duration in milliseconds.",
76241+
"type": "array",
76242+
"items": {
76243+
"$ref": "#/definitions/v1.StepInfo"
76244+
}
76245+
}
76246+
}
76247+
},
76248+
"v1.StepInfo": {
76249+
"description": "StepInfo contains details about a build step.",
76250+
"properties": {
76251+
"durationMilliseconds": {
76252+
"description": "durationMilliseconds identifies how long the step took to complete in milliseconds.",
76253+
"type": "integer",
76254+
"format": "int64"
76255+
},
76256+
"name": {
76257+
"description": "name is a unique identifier for each build step.",
76258+
"type": "string"
76259+
},
76260+
"startTime": {
76261+
"description": "startTime is a timestamp representing the server time when this Step started. it is represented in RFC3339 form and is in UTC.",
76262+
"$ref": "#/definitions/unversioned.Time"
76263+
}
76264+
}
76265+
},
7621676266
"v1.SubjectAccessReview": {
7621776267
"description": "SubjectAccessReview is an object for requesting information about whether a user or group can perform an action",
7621876268
"required": [

pkg/build/api/helpers.go

+54
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package api
22

33
import (
4+
"time"
5+
46
kapi "k8s.io/kubernetes/pkg/api"
7+
"k8s.io/kubernetes/pkg/api/unversioned"
8+
9+
"github.com/golang/glog"
510
)
611

712
// BuildToPodLogOptions builds a PodLogOptions object out of a BuildLogOptions.
@@ -75,3 +80,52 @@ func HasTriggerType(triggerType BuildTriggerType, bc *BuildConfig) bool {
7580
matches := FindTriggerPolicy(triggerType, bc)
7681
return len(matches) > 0
7782
}
83+
84+
// RecordStageAndStepInfo records details about each build stage and step
85+
func RecordStageAndStepInfo(stages []StageInfo, stageName StageName, stepName StepName, startTime unversioned.Time, endTime unversioned.Time) []StageInfo {
86+
// If the stage already exists in the slice, update the DurationMilliseconds, and append the new step.
87+
for stageKey, stageVal := range stages {
88+
if stageVal.Name == stageName {
89+
for _, step := range stages[stageKey].Steps {
90+
if step.Name == stepName {
91+
glog.Warningf("error recording build timing information, step %v already exists in stage %v", stepName, stageName)
92+
}
93+
}
94+
stages[stageKey].DurationMilliseconds = endTime.Time.Sub(stages[stageKey].StartTime.Time).Nanoseconds() / int64(time.Millisecond)
95+
if len(stages[stageKey].Steps) == 0 {
96+
stages[stageKey].Steps = make([]StepInfo, 0)
97+
}
98+
stages[stageKey].Steps = append(stages[stageKey].Steps, StepInfo{
99+
Name: stepName,
100+
StartTime: startTime,
101+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
102+
})
103+
return stages
104+
}
105+
}
106+
107+
// If the stageName does not exist, add it to the slice along with the new step.
108+
var steps []StepInfo
109+
steps = append(steps, StepInfo{
110+
Name: stepName,
111+
StartTime: startTime,
112+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
113+
})
114+
stages = append(stages, StageInfo{
115+
Name: stageName,
116+
StartTime: startTime,
117+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
118+
Steps: steps,
119+
})
120+
return stages
121+
}
122+
123+
// AppendStageAndStepInfo appends the step info from one stages slice into another.
124+
func AppendStageAndStepInfo(stages []StageInfo, stagesToMerge []StageInfo) []StageInfo {
125+
for _, stage := range stagesToMerge {
126+
for _, step := range stage.Steps {
127+
stages = RecordStageAndStepInfo(stages, stage.Name, step.Name, step.StartTime, unversioned.NewTime(step.StartTime.Add(time.Duration(step.DurationMilliseconds)*time.Millisecond)))
128+
}
129+
}
130+
return stages
131+
}

pkg/build/api/types.go

+88
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,96 @@ type BuildStatus struct {
283283

284284
// Output describes the Docker image the build has produced.
285285
Output BuildStatusOutput
286+
287+
// Stages contains details about each stage that occurs during the build
288+
// including start time, duration (in milliseconds), and the steps that
289+
// occured within each stage.
290+
Stages []StageInfo
291+
}
292+
293+
// StageInfo contains details about a build stage.
294+
type StageInfo struct {
295+
// Name is a unique identifier for each build stage that occurs.
296+
Name StageName
297+
298+
// StartTime is a timestamp representing the server time when this Stage started.
299+
// It is represented in RFC3339 form and is in UTC.
300+
StartTime unversioned.Time
301+
302+
// DurationMilliseconds identifies how long the stage took
303+
// to complete in milliseconds.
304+
// Note: the duration of a stage can exceed the sum of the duration of the steps within
305+
// the stage as not all actions are accounted for in explicit build steps.
306+
DurationMilliseconds int64
307+
308+
// Steps contains details about each step that occurs during a build stage
309+
// including start time and duration in milliseconds.
310+
Steps []StepInfo
286311
}
287312

313+
// StageName is the identifier for each build stage.
314+
type StageName string
315+
316+
// Valid values for StageName
317+
const (
318+
// StageFetchInputs fetches any inputs such as source code.
319+
StageFetchInputs StageName = "FetchInputs"
320+
321+
// StagePullImages pulls any images that are needed such as
322+
// base images or input images.
323+
StagePullImages StageName = "PullImages"
324+
325+
// StageBuild performs the steps necessary to build the image.
326+
StageBuild StageName = "Build"
327+
328+
// StagePostCommit executes any post commit steps.
329+
StagePostCommit StageName = "PostCommit"
330+
331+
// StagePushImage pushes the image to the node.
332+
StagePushImage StageName = "PushImage"
333+
)
334+
335+
// StepInfo contains details about a build step.
336+
type StepInfo struct {
337+
// Name is a unique identifier for each build step.
338+
Name StepName
339+
340+
// StartTime is a timestamp representing the server time when this Step started.
341+
// it is represented in RFC3339 form and is in UTC.
342+
StartTime unversioned.Time
343+
344+
// DurationMilliseconds identifies how long the step took
345+
// to complete in milliseconds.
346+
DurationMilliseconds int64
347+
}
348+
349+
// StepName is a unique identifier for each build step.
350+
type StepName string
351+
352+
// Valid values for StepName
353+
const (
354+
// StepExecPostCommitHook executes the buildconfigs post commit hook.
355+
StepExecPostCommitHook StepName = "RunPostCommitHook"
356+
357+
// StepFetchGitSource fetches the source code for the build.
358+
StepFetchGitSource StepName = "FetchGitSource"
359+
360+
// StepPullBaseImage pulls the base image for the build.
361+
StepPullBaseImage StepName = "PullBaseImage"
362+
363+
// StepPullInputImage pulls the input image for the build.
364+
StepPullInputImage StepName = "PullInputImage"
365+
366+
// StepPushImage pushed the image to the registry.
367+
StepPushImage StepName = "PushImage"
368+
369+
// StepPushDockerImage pushes the docker image to the registry.
370+
StepPushDockerImage StepName = "PushDockerImage"
371+
372+
//StepDockerBuild performs the docker build
373+
StepDockerBuild StepName = "DockerBuild"
374+
)
375+
288376
// BuildPhase represents the status of a build at a point in time.
289377
type BuildPhase string
290378

0 commit comments

Comments
 (0)