Commit 714a8cbb authored by Alessio Caiazza's avatar Alessio Caiazza

Send section markers only if GitLab has the `trace_sections` feature

parent 438ea749
Pipeline #12204462 passed with stages
in 78 minutes and 45 seconds
......@@ -171,8 +171,9 @@ func (b *Build) executeStage(ctx context.Context, buildStage BuildStage, executo
}
section := helpers.BuildSection{
Name: string(buildStage),
Run: func() error { return executor.Run(cmd) },
Name: string(buildStage),
SkipMetrics: !b.JobResponse.Features.TraceSections,
Run: func() error { return executor.Run(cmd) },
}
return section.RunAndCollectMetrics(&b.logger)
}
......
......@@ -231,21 +231,26 @@ type Dependency struct {
type Dependencies []Dependency
type GitlabFeatures struct {
TraceSections bool `json:"trace_sections"`
}
type JobResponse struct {
ID int `json:"id"`
Token string `json:"token"`
AllowGitFetch bool `json:"allow_git_fetch"`
JobInfo JobInfo `json:"job_info"`
GitInfo GitInfo `json:"git_info"`
RunnerInfo RunnerInfo `json:"runner_info"`
Variables JobVariables `json:"variables"`
Steps Steps `json:"steps"`
Image Image `json:"image"`
Services Services `json:"services"`
Artifacts Artifacts `json:"artifacts"`
Cache Caches `json:"cache"`
Credentials []Credentials `json:"credentials"`
Dependencies Dependencies `json:"dependencies"`
ID int `json:"id"`
Token string `json:"token"`
AllowGitFetch bool `json:"allow_git_fetch"`
JobInfo JobInfo `json:"job_info"`
GitInfo GitInfo `json:"git_info"`
RunnerInfo RunnerInfo `json:"runner_info"`
Variables JobVariables `json:"variables"`
Steps Steps `json:"steps"`
Image Image `json:"image"`
Services Services `json:"services"`
Artifacts Artifacts `json:"artifacts"`
Cache Caches `json:"cache"`
Credentials []Credentials `json:"credentials"`
Dependencies Dependencies `json:"dependencies"`
Features GitlabFeatures `json:"features"`
TLSCAChain string `json:"-"`
TLSAuthCert string `json:"-"`
......
......@@ -10,8 +10,9 @@ type RawLogger interface {
}
type BuildSection struct {
Name string
Run func() error
Name string
SkipMetrics bool
Run func() error
}
const (
......@@ -24,6 +25,10 @@ func nowUnixUTC() int64 {
}
func (s *BuildSection) timestamp(format string, logger RawLogger) {
if s.SkipMetrics {
return
}
sectionLine := fmt.Sprintf(format, nowUnixUTC(), s.Name)
logger.SendRawLog(sectionLine)
}
......
......@@ -100,3 +100,13 @@ func TestBuildSection(t *testing.T) {
assert.Equal(t, tc.delay, firstSection.Duration(), "case %d: wrong duration")
}
}
func TestBuildSectionSkipMetrics(t *testing.T) {
parser := newSectionParser()
section := BuildSection{Name: "SkipMetrics", SkipMetrics: true, Run: func() error { return nil }}
section.RunAndCollectMetrics(parser)
assert.Nil(t, parser.Error)
assert.Equal(t, 0, len(parser.Sections))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment