8000 feat: add observability on hook registration (#4352) · ovh/cds@a00966a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit a00966a

Browse files
authored
feat: add observability on hook registration (#4352)
1 parent b875fae commit a00966a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

engine/api/workflow/dao.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ func RenameNode(db gorp.SqlExecutor, w *sdk.Workflow) error {
931931

932932
// Update updates a workflow
933933
func Update(ctx context.Context, db gorp.SqlExecutor, store cache.Store, w *sdk.Workflow, oldWorkflow *sdk.Workflow, p *sdk.Project, u *sdk.User) error {
934+
ctx, end := observability.Span(ctx, "workflow.Update")
935+
defer end()
934936
if err := IsValid(ctx, store, db, w, p, u); err != nil {
935937
return err
936938
}

engine/api/workflow/hook.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/ovh/cds/engine/api/application"
1313
"github.com/ovh/cds/engine/api/cache"
14+
"github.com/ovh/cds/engine/api/observability"
1415
"github.com/ovh/cds/engine/api/repositoriesmanager"
1516
"github.com/ovh/cds/engine/api/services"
1617
"github.com/ovh/cds/sdk"
@@ -19,6 +20,9 @@ import (
1920

2021
// HookRegistration ensures hooks registration on Hook µSer 8000 vice
2122
func HookRegistration(ctx context.Context, db gorp.SqlExecutor, store cache.Store, oldW *sdk.Workflow, wf sdk.Workflow, p *sdk.Project) error {
23+
ctx, end := observability.Span(ctx, "workflow.HookRegistration")
24+
defer end()
25+
2226
var hookToUpdate map[string]sdk.WorkflowNodeHook
2327
var hookToDelete map[string]sdk.WorkflowNodeHook
2428
if oldW != nil {
@@ -27,6 +31,9 @@ func HookRegistration(ctx context.Context, db gorp.SqlExecutor, store cache.Stor
2731
hookToUpdate = wf.GetHooks()
2832
}
2933

34+
observability.Current(ctx, observability.Tag("hook_update_count", len(hookToUpdate)))
35+
observability.Current(ctx, observability.Tag("hook_delete_count", len(hookToDelete)))
36+
3037
if len(hookToUpdate) > 0 {
3138
//Push the hook to hooks µService
3239
//Load service "hooks"
@@ -151,8 +158,12 @@ func HookRegistration(ctx context.Context, db gorp.SqlExecutor, store cache.Stor
151158

152159
// DeleteHookConfiguration delete hooks configuration (and their vcs configuration)
153160
func DeleteHookConfiguration(ctx context.Context, db gorp.SqlExecutor, store cache.Store, p *sdk.Project, hookToDelete map[string]sdk.WorkflowNodeHook) error {
161+
ctx, end := observability.Span(ctx, "workflow.DeleteHookConfiguration")
162+
defer end()
154163
// Delete from vcs configuration if needed
164+
count := 0
155165
for _, h := range hookToDelete {
166+
count++
156167
if h.WorkflowHookModel.Name == sdk.RepositoryWebHookModelName {
157168
// Call VCS to know if repository allows webhook and get the configuration fields
158169
projectVCSServer := repositoriesmanager.GetProjectVCSServer(p, h.Config["vcsServer"].Value)
@@ -170,6 +181,8 @@ func DeleteHookConfiguration(ctx context.Context, db gorp.SqlExecutor, store cac
170181
if err := client.DeleteHook(ctx, h.Config["repoFullName"].Value, vcsHook); err != nil {
171182
log.Error("deleteHookConfiguration> Cannot delete hook on repository %s", err)
172183
}
184+
observability.Current(ctx, observability.Tag(fmt.Sprintf("UUID_%d", count), h.UUID))
185+
observability.Current(ctx, observability.Tag(fmt.Sprintf("VCS_ID_%d", count), vcsHook.ID))
173186
h.Config["webHookID"] = sdk.WorkflowNodeHookConfigValue{
174187
Value: vcsHook.ID,
175188
Configurable: false,
@@ -194,6 +207,9 @@ func DeleteHookConfiguration(ctx context.Context, db gorp.SqlExecutor, store cac
194207
}
195208

196209
func createVCSConfiguration(ctx context.Context, db gorp.SqlExecutor, store cache.Store, p *sdk.Project, h *sdk.WorkflowNodeHook) error {
210+
ctx, end := observability.Span(ctx, "workflow.createVCSConfiguration", observability.Tag("UUID", h.UUID))
211+
defer end()
212+
197213
// Call VCS to know if repository allows webhook and get the configuration fields
198214
projectVCSServer := repositoriesmanager.GetProjectVCSServer(p, h.Config["vcsServer"].Value)
199215
if projectVCSServer == nil {
@@ -219,6 +235,7 @@ func createVCSConfiguration(ctx context.Context, db gorp.SqlExecutor, store cach
219235
if err := client.CreateHook(ctx, h.Config["repoFullName"].Value, &vcsHook); err != nil {
220236
return sdk.WrapError(err, "Cannot create hook on repository: %+v", vcsHook)
221237
}
238+
observability.Current(ctx, observability.Tag("VCS_ID", vcsHook.ID))
222239
h.Config["webHookID"] = sdk.WorkflowNodeHookConfigValue{
223240
Value: vcsHook.ID,
224241
Configurable: false,

ui/src/app/shared/workflow/menu/edit-node/menu.edit.node.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
100100
return true;
101101
}
102102

103-
if (this.workflowrun) {
103+
if (this.workflowrun && this.workflowrun.workflow && this.workflowrun.workflow.workflow_data) {
104104
let nbNodeFound = 0;
105105
let parentNodes = Workflow.getParentNodeIds(this.workflowrun, this.node.id);
106106
for (let parentNodeId of parentNodes) {

0 commit comments

Comments
 (0)
0