8000 fix(api): add tag "cds" on all metrics (#3897) · ovh/cds@8f814c7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 8f814c7

Browse files
yesnaultsguiheux
authored andcommitted
fix(api): add tag "cds" on all metrics (#3897)
1 parent 74b56c8 commit 8f814c7

File tree

11 files changed

+13
-183
lines changed

11 files changed

+13
-183
lines changed

engine/api/event/elasticsearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func PushInElasticSearch(c context.Context, db gorp.SqlExecutor, store cache.Sto
3737
}
3838

3939
switch e.EventType {
40-
case "sdk.EventPipelineBuild", "sdk.EventJob", "sdk.EventEngine":
40+
case "sdk.EventJob", "sdk.EventEngine":
4141
continue
4242
}
4343
e.Payload = nil

engine/api/events.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func (b *eventsBroker) cacheSubscribe(c context.Context, cacheMsgChan chan<- sdk
9191
}
9292

9393
switch e.EventType {
94-
case "sdk.EventPipelineBuild", "sdk.EventJob":
94+
case "sdk.EventJob":
9595
continue
9696
}
97-
observability.Record(c, b.router.Stats.SSEEvents, 1)
97+
observability.Record(b.router.Background, b.router.Stats.SSEEvents, 1)
9898
cacheMsgChan <- e
9999
}
100100
}
@@ -119,7 +119,6 @@ func (b *eventsBroker) Start(ctx context.Context, panicCallback func(s string) (
119119
delete(b.clients, uuid)
120120
}
121121
observability.Record(b.router.Background, b.router.Stats.SSEClients, 0)
122-
123122
}
124123
if ctx.Err() != nil {
125124
log.Error("eventsBroker.Start> Exiting: %v", ctx.Err())

engine/api/observability/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func NewViewLastFloat64(name string, s *stats.Float64Measure, tags []tag.Key) *v
133133
}
134134
}
135135

136-
// NewViewCount creates a new view via aggregation LastValue()
136+
// NewViewCount creates a new view via aggregation Count()
137137
func NewViewCount(name string, s *stats.Int64Measure, tags []tag.Key) *view.View {
138138
return &view.View{
139139
Name: name,

engine/api/repositoriesmanager/events.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,7 @@ func processEvent(ctx context.Context, db *gorp.DbMap, event sdk.Event, store ca
4848
var c sdk.VCSAuthorizedClient
4949
var errC error
5050

51-
if event.EventType == fmt.Sprintf("%T", sdk.EventPipelineBuild{}) {
52-
var eventpb sdk.EventPipelineBuild
53-
if err := mapstructure.Decode(event.Payload, &eventpb); err != nil {
54-
log.Error("Error during consumption: %s", err)
55-
return err
56-
}
57-
if eventpb.RepositoryManagerName == "" {
58-
return nil
59-
}
60-
vcsServer, err := LoadForProject(db, eventpb.ProjectKey, eventpb.RepositoryManagerName)
61-
if err != nil {
62-
return fmt.Errorf("repositoriesmanager>processEvent> AuthorizedClient (%s, %s) > err:%s", eventpb.ProjectKey, eventpb.RepositoryManagerName, err)
63-
}
64-
65-
c, errC = AuthorizedClient(ctx, db, store, vcsServer)
66-
if errC != nil {
67-
return fmt.Errorf("repositoriesmanager>processEvent> AuthorizedClient (%s, %s) > err:%s", eventpb.ProjectKey, eventpb.RepositoryManagerName, errC)
68-
}
69-
70-
} else if event.EventType == fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}) {
51+
if event.EventType == fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}) {
7152
var eventWNR sdk.EventRunWorkflowNode
7253

7354
if err := mapstructure.Decode(event.Payload, &eventWNR); err != nil {

engine/api/router.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ func (r *Router) Handle(uri string, handlers ...*service.HandlerConfig) {
210210
w.WriteHeader(http.StatusOK)
211211
return
212212
}
213-
observability.Record(ctx, r.Stats.Hits, 1)
213+
observability.Record(r.Background, r.Stats.Hits, 1)
214214

215215
//Get route configuration
216216
rc := cfg.Config[req.Method]
217217
if rc == nil || rc.Handler == nil {
218-
observability.Record(ctx, r.Stats.Errors, 1)
218+
observability.Record(r.Background, r.Stats.Errors, 1)
219219
service.WriteError(w, req, sdk.ErrNotFound)
220220
return
221221
}
@@ -236,14 +236,14 @@ func (r *Router) Handle(uri string, handlers ...*service.HandlerConfig) {
236236
var err error
237237
ctx, err = m(ctx, w, req, rc)
238238
if err != nil {
239-
observability.Record(ctx, r.Stats.Errors, 1)
239+
observability.Record(r.Background, r.Stats.Errors, 1)
240240
service.WriteError(w, req, err)
241241
return
242242
}
243243
}
244244

245245
if err := rc.Handler(ctx, w, req); err != nil {
246-
observability.Record(ctx, r.Stats.Errors, 1)
246+
observability.Record(r.Background, r.Stats.Errors, 1)
247247
observability.End(ctx, w, req)
248248
service.WriteError(w, req, err)
249249
return

engine/api/workflow_queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (api *API) postWorkflowJobResultHandler() service.Handler {
424424
observability.Tag(observability.TagWorkflow, workflowRuns[0].Workflow.Name))
425425

426426
if workflowRuns[0].Status == sdk.StatusFail.String() {
427-
observability.Record(ctx, api.Metrics.WorkflowRunFailed, 1)
427+
observability.Record(api.Router.Background, api.Metrics.WorkflowRunFailed, 1)
428428
}
429429
}
430430

engine/api/workflow_run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func (api *API) stopWorkflowRunHandler() service.Handler {
358358
)
359359

360360
if workflowRuns[0].Status == sdk.StatusFail.String() {
361-
observability.Record(ctx, api.Metrics.WorkflowRunFailed, 1)
361+
observability.Record(api.Router.Background, api.Metrics.WorkflowRunFailed, 1)
362362
}
363363
}
364364

@@ -689,7 +689,7 @@ func (api *API) stopWorkflowNodeRun(ctx context.Context, dbFunc func() *gorp.DbM
689689
observability.Tag(observability.TagWorkflow, wr.Workflow.Name),
690690
)
691691
if wr.Status == sdk.StatusFail.String() {
692-
observability.Record(ctx, api.Metrics.WorkflowRunFailed, 1)
692+
observability.Record(api.Router.Background, api.Metrics.WorkflowRunFailed, 1)
693693
}
694694

695695
if errC := tx.Commit(); errC != nil {
@@ -754,7 +754,7 @@ func (api *API) postWorkflowRunHandler() service.Handler {
754754
observability.Tag(observability.TagProjectKey, key),
755755
observability.Tag(observability.TagWorkflow, name),
756756
)
757-
observability.Record(ctx, api.Metrics.WorkflowRunStarted, 1)
757+
observability.Record(api.Router.Background, api.Metrics.WorkflowRunStarted, 1)
758758

759759
_, next := observability.Span(ctx, "project.Load")
760760
p, errP := project.Load(api.mustDB(), api.Cache, key, u,

engine/vcs/bitbucket/client_status.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ func (b *bitbucketClient) SetStatus(ctx context.Context, event sdk.Event) error
3232
var statusData statusData
3333
var err error
3434
switch event.EventType {
35-
case fmt.Sprintf("%T", sdk.EventPipelineBuild{}):
36-
statusData, err = processPipelineBuildEvent(event, b.consumer.uiURL)
3735
case fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}):
3836
statusData, err = processWorkflowNodeRunEvent(event, b.consumer.uiURL)
3937
default:
@@ -147,38 +145,6 @@ func processWorkflowNodeRunEvent(event sdk.Event, uiURL string) (statusData, err
147145
return data, nil
148146
}
149147

150-
func processPipelineBuildEvent(event sdk.Event, uiURL string) (statusData, error) {
151-
data := statusData{}
152-
var eventpb sdk.EventPipelineBuild
153-
if err := mapstructure.Decode(event.Payload, &eventpb); err != nil {
154-
return data, sdk.WrapError(err, "Error during consumption")
155-
}
156-
cdsProject := eventpb.ProjectKey
157-
cdsApplication := eventpb.ApplicationName
158-
cdsPipelineName := eventpb.PipelineName
159-
cdsBuildNumber := eventpb.BuildNumber
160-
cdsEnvironmentName := eventpb.EnvironmentName
161-
162-
data.key = fmt.Sprintf("%s-%s-%s",
163-
cdsProject,
164-
cdsApplication,
165-
cdsPipelineName,
166-
)
167-
168-
data.url = fmt.Sprintf("%s/project/%s/application/%s/pipeline/%s/build/%d?envName=%s",
169-
uiURL,
170-
cdsProject,
171-
cdsApplication,
172-
cdsPipelineName,
173-
cdsBuildNumber,
174-
url.QueryEscape(cdsEnvironmentName),
175-
)
176-
data.buildNumber = cdsBuildNumber
177-
data.status = eventpb.Status.String()
178-
data.hash = eventpb.Hash
179-
return data, nil
180-
}
181-
182148
func getBitbucketStateFromStatus(status string) string {
183149
switch status {
184150
case sdk.StatusSuccess.String():

engine/vcs/github/client_status.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io/ioutil"
99
"net/http"
10-
"net/url"
1110
"strings"
1211

1312
"github.com/mitchellh/mapstructure"
@@ -38,8 +37,6 @@ func (g *githubClient) SetStatus(ctx context.Context, event sdk.Event) error {
3837
var data statusData
3938
var err error
4039
switch event.EventType {
41-
case fmt.Sprintf("%T", sdk.EventPipelineBuild{}):
42-
data, err = processEventPipelineBuild(event, g.uiURL, g.DisableStatusDetail)
4340
case fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}):
4441
data, err = processEventWorkflowNodeRun(event, g.uiURL, g.DisableStatusDetail)
4542
default:
@@ -190,59 +187,3 @@ func processEventWorkflowNodeRun(event sdk.Event, githubURL string, disabledStat
190187
data.desc = eventNR.NodeName + ": " + eventNR.Status
191188
return data, nil
192189
}
193-
194-
func processEventPipelineBuild(event sdk.Event, githubURL string, disabledStatusDetail bool) (statusData, error) {
195-
data := statusData{}
196-
var eventpb sdk.EventPipelineBuild
197-
if err := mapstructure.Decode(event.Payload, &eventpb); err != nil {
198-
return data, sdk.WrapError(err, "Error durring consumption")
199-
}
200-
//We only manage status Success and Failure
201-
if eventpb.Status == sdk.StatusChecking ||
202-
eventpb.Status == sdk.StatusDisabled ||
203-
eventpb.Status == sdk.StatusNeverBuilt ||
204-
eventpb.Status == sdk.StatusSkipped ||
205-
eventpb.Status == sdk.StatusUnknown ||
206-
eventpb.Status == sdk.StatusWaiting {
207-
return data, nil
208-
}
209-
210-
switch eventpb.Status {
211-
case sdk.StatusFail:
212-
data.status = "error"
213-
case sdk.StatusSuccess:
214-
data.status = "success"
215-
default:
216-
data.status = "pending"
217-
}
218-
data.urlPipeline = fmt.Sprintf("%s/project/%s/application/%s/pipeline/%s/build/%d?envName=%s",
219-
githubURL,
220-
eventpb.ProjectKey,
221-
eventpb.ApplicationName,
222-
eventpb.PipelineName,
223-
eventpb.BuildNumber,
224-
url.QueryEscape(eventpb.EnvironmentName),
225-
)
226-
data.hash = eventpb.Hash
227-
data.repoFullName = eventpb.RepositoryFullname
228-
//CDS can avoid sending github targer url in status, if it's disable
229-
if disabledStatusDetail {
230-
data.urlPipeline = ""
231-
}
232-
233-
switch eventpb.PipelineType {
234-
case sdk.BuildPipeline:
235-
data.desc = fmt.Sprintf("Build pipeline %s: %s", eventpb.PipelineName, eventpb.Status.String())
236-
case sdk.TestingPipeline:
237-
data.desc = fmt.Sprintf("Testing pipeline %s: %s", eventpb.PipelineName, eventpb.Status.String())
238-
if eventpb.Status == sdk.StatusFail {
239-
data.status = "failure"
240-
}
241-
case sdk.DeploymentPipeline:
242-
data.desc = fmt.Sprintf("Deployment pipeline %s: %s", eventpb.PipelineName, eventpb.Status.String())
243-
default:
244-
log.Warning("Unrecognized pipeline type : %v", eventpb.PipelineType)
245-
}
246-
247-
return data, nil
248-
}

engine/vcs/gitlab/client_status.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gitlab
33
import (
44
"context"
55
"fmt"
6-
"net/url"
76
"strings"
87

98
"github.com/mitchellh/mapstructure"
@@ -57,8 +56,6 @@ func (c *gitlabClient) SetStatus(ctx context.Context, event sdk.Event) error {
5756
var data statusData
5857
var err error
5958
switch event.EventType {
60-
case fmt.Sprintf("%T", sdk.EventPipelineBuild{}):
61-
data, err = processPipelineBuildEvent(event, c.uiURL)
6259
case fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}):
6360
data, err = processWorkflowNodeRunEvent(event, c.uiURL)
6461
default:
@@ -147,39 +144,3 @@ func processWorkflowNodeRunEvent(event sdk.Event, uiURL string) (statusData, err
147144
data.branchName = eventNR.BranchName
148145
return data, nil
149146
}
150-
151-
func processPipelineBuildEvent(event sdk.Event, uiURL string) (statusData, error) {
152-
data := statusData{}
153-
var eventpb sdk.EventPipelineBuild
154-
if err := mapstructure.Decode(event.Payload, &eventpb); err != nil {
155-
return data, sdk.WrapError(err, "cannot read payload")
1 DE46 56-
}
157-
158-
cdsProject := eventpb.ProjectKey
159-
cdsApplication := eventpb.ApplicationName
160-
cdsPipelineName := eventpb.PipelineName
161-
cdsBuildNumber := eventpb.BuildNumber
162-
cdsEnvironmentName := eventpb.EnvironmentName
163-
164-
key := fmt.Sprintf("%s-%s-%s",
165-
cdsProject,
166-
cdsApplication,
167-
cdsPipelineName,
168-
)
169-
170-
data.url = fmt.Sprintf("%s/project/%s/application/%s/pipeline/%s/build/%d?envName=%s",
171-
uiURL,
172-
cdsProject,
173-
cdsApplication,
174-
cdsPipelineName,
175-
cdsBuildNumber,
176-
url.QueryEscape(cdsEnvironmentName),
177-
)
178-
179-
data.desc = fmt.Sprintf("Build #%d %s", eventpb.BuildNumber, key)
180-
data.hash = eventpb.Hash
181-
data.repoFullName = eventpb.RepositoryFullname
182-
data.status = eventpb.Status.String()
183-
data.branchName = eventpb.BranchName
184-
return data, nil
185-
}

0 commit comments

Comments
 (0)
0