Skip to content

Commit cfbba4e

Browse files
committed
feat: add new telemetry events (#574)
1 parent f2f3e92 commit cfbba4e

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

engine/internal/srv/branch.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package srv
22

33
import (
4+
"context"
45
"fmt"
56
"net/http"
67
"regexp"
@@ -12,6 +13,7 @@ import (
1213
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/pool"
1314
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/resources"
1415
"gitlab.com/postgres-ai/database-lab/v3/internal/srv/api"
16+
"gitlab.com/postgres-ai/database-lab/v3/internal/telemetry"
1517
"gitlab.com/postgres-ai/database-lab/v3/internal/webhooks"
1618
"gitlab.com/postgres-ai/database-lab/v3/pkg/client/dblabapi/types"
1719
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
@@ -246,6 +248,10 @@ func (s *Server) createBranch(w http.ResponseWriter, r *http.Request) {
246248
EntityID: branch.Name,
247249
}
248250

251+
s.tm.SendEvent(context.Background(), telemetry.BranchCreatedEvent, telemetry.BranchCreated{
252+
Name: branch.Name,
253+
})
254+
249255
if err := api.WriteJSON(w, http.StatusOK, branch); err != nil {
250256
api.SendError(w, r, err)
251257
return
@@ -439,6 +445,8 @@ func (s *Server) snapshot(w http.ResponseWriter, r *http.Request) {
439445
return
440446
}
441447

448+
s.tm.SendEvent(context.Background(), telemetry.SnapshotCreatedEvent, telemetry.SnapshotCreated{})
449+
442450
if err := api.WriteJSON(w, http.StatusOK, types.SnapshotResponse{SnapshotID: targetSnap}); err != nil {
443451
api.SendError(w, r, err)
444452
return
@@ -640,6 +648,10 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
640648
EntityID: deleteRequest.BranchName,
641649
}
642650

651+
s.tm.SendEvent(context.Background(), telemetry.BranchDestroyedEvent, telemetry.BranchDestroyed{
652+
Name: deleteRequest.BranchName,
653+
})
654+
643655
if err := api.WriteJSON(w, http.StatusOK, models.Response{
644656
Status: models.ResponseOK,
645657
Message: "Deleted branch",

engine/internal/srv/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/logical"
1818
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools/db"
1919
"gitlab.com/postgres-ai/database-lab/v3/internal/srv/api"
20+
"gitlab.com/postgres-ai/database-lab/v3/internal/telemetry"
2021
"gitlab.com/postgres-ai/database-lab/v3/pkg/config"
2122
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
2223
"gitlab.com/postgres-ai/database-lab/v3/pkg/models"
@@ -78,6 +79,8 @@ func (s *Server) setProjectedAdminConfig(w http.ResponseWriter, r *http.Request)
7879
return
7980
}
8081

82+
s.tm.SendEvent(context.Background(), telemetry.ConfigUpdatedEvent, telemetry.ConfigUpdated{})
83+
8184
retrievalStatus := s.Retrieval.State.Status
8285

8386
if err := s.Retrieval.RemovePendingMarker(); err != nil {

engine/internal/srv/routes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ func (s *Server) patchClone(w http.ResponseWriter, r *http.Request) {
434434
return
435435
}
436436

437+
s.tm.SendEvent(context.Background(), telemetry.CloneUpdatedEvent, telemetry.CloneUpdated{
438+
ID: util.HashID(cloneID),
439+
Protected: patchClone.Protected,
440+
})
441+
437442
if err := api.WriteJSON(w, http.StatusOK, updatedClone); err != nil {
438443
api.SendError(w, r, err)
439444
return

engine/internal/telemetry/events.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,30 @@ type CloneCreated struct {
4949
DSADiff *float64 `json:"dsa_diff,omitempty"`
5050
}
5151

52+
// CloneUpdated describes the clone updates.
53+
type CloneUpdated struct {
54+
ID string `json:"id"`
55+
Protected bool `json:"protected"`
56+
}
57+
5258
// CloneDestroyed describes a clone destruction event.
5359
type CloneDestroyed struct {
5460
ID string `json:"id"`
5561
}
5662

63+
// BranchCreated describes a branch creation event.
64+
type BranchCreated struct {
65+
Name string `json:"name"`
66+
}
67+
68+
// BranchDestroyed describes a branch destruction event.
69+
type BranchDestroyed struct {
70+
Name string `json:"name"`
71+
}
72+
73+
// ConfigUpdated describes the config updates.
74+
type ConfigUpdated struct{}
75+
5776
// Alert describes alert events.
5877
type Alert struct {
5978
Level models.AlertType `json:"level"`

engine/internal/telemetry/telemetry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@ const (
2929
// CloneDestroyedEvent describes a clone destruction event.
3030
CloneDestroyedEvent = "clone_destroyed"
3131

32+
// CloneUpdatedEvent describes a clone update event.
33+
CloneUpdatedEvent = "clone_updated"
34+
3235
// SnapshotCreatedEvent describes a snapshot creation event.
3336
SnapshotCreatedEvent = "snapshot_created"
3437

38+
// BranchCreatedEvent describes a branch creation event.
39+
BranchCreatedEvent = "branch_created"
40+
41+
// BranchDestroyedEvent describes a branch destruction event.
42+
BranchDestroyedEvent = "branch_destroyed"
43+
44+
ConfigUpdatedEvent = "config_updated"
45+
3546
// AlertEvent describes alert events.
3647
AlertEvent = "alert"
3748
)

0 commit comments

Comments
 (0)