From 08230cbc0980a9d09ad0571d38384406cf4aa407 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 8 Sep 2025 13:47:16 +0300 Subject: [PATCH] Chore: Remove unused bus.Bus events (#110738) --- pkg/events/events.go | 44 ------------------- pkg/services/datasources/service/store.go | 8 ---- .../datasources/service/store_test.go | 27 ------------ pkg/services/org/orgimpl/store.go | 24 ---------- pkg/services/sqlstore/session.go | 4 -- pkg/services/sqlstore/user.go | 15 ------- pkg/services/user/userimpl/store.go | 16 ------- 7 files changed, 138 deletions(-) diff --git a/pkg/events/events.go b/pkg/events/events.go index 38b6dce4090..c45ccaab0a2 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -7,26 +7,6 @@ import ( // Events can be passed to external systems via for example AMQP // Treat these events as basically DTOs so changes has to be backward compatible -type OrgCreated struct { - Timestamp time.Time `json:"timestamp"` - Id int64 `json:"id"` - Name string `json:"name"` -} - -type OrgUpdated struct { - Timestamp time.Time `json:"timestamp"` - Id int64 `json:"id"` - Name string `json:"name"` -} - -type UserCreated struct { - Timestamp time.Time `json:"timestamp"` - Id int64 `json:"id"` - Name string `json:"name"` - Login string `json:"login"` - Email string `json:"email"` -} - type SignUpStarted struct { Timestamp time.Time `json:"timestamp"` Email string `json:"email"` @@ -39,14 +19,6 @@ type SignUpCompleted struct { Email string `json:"email"` } -type UserUpdated struct { - Timestamp time.Time `json:"timestamp"` - Id int64 `json:"id"` - Name string `json:"name"` - Login string `json:"login"` - Email string `json:"email"` -} - type DataSourceDeleted struct { Timestamp time.Time `json:"timestamp"` Name string `json:"name"` @@ -55,22 +27,6 @@ type DataSourceDeleted struct { OrgID int64 `json:"org_id"` } -type DataSourceSecretDeleted struct { - Timestamp time.Time `json:"timestamp"` - Name string `json:"name"` - ID int64 `json:"id"` - UID string `json:"uid"` - OrgID int64 `json:"org_id"` -} - -type DataSourceCreated struct { - Timestamp time.Time `json:"timestamp"` - Name string `json:"name"` - ID int64 `json:"id"` - UID string `json:"uid"` - OrgID int64 `json:"org_id"` -} - // FolderFullPathUpdated is emitted when the full path of the folder(s) is updated. // For example, when the folder is renamed or moved to another folder. // It does not contain the full path of the folders because calculating diff --git a/pkg/services/datasources/service/store.go b/pkg/services/datasources/service/store.go index f005516433a..c89200ee2fc 100644 --- a/pkg/services/datasources/service/store.go +++ b/pkg/services/datasources/service/store.go @@ -300,14 +300,6 @@ func (ss *SqlStore) AddDataSource(ctx context.Context, cmd *datasources.AddDataS return err } } - - sess.PublishAfterCommit(&events.DataSourceCreated{ - Timestamp: time.Now(), - Name: cmd.Name, - ID: ds.ID, - UID: cmd.UID, - OrgID: cmd.OrgID, - }) return nil }) } diff --git a/pkg/services/datasources/service/store_test.go b/pkg/services/datasources/service/store_test.go index 7acb1dbafca..e5a76714b8a 100644 --- a/pkg/services/datasources/service/store_test.go +++ b/pkg/services/datasources/service/store_test.go @@ -109,33 +109,6 @@ func TestIntegrationDataAccess(t *testing.T) { _, err := ss.AddDataSource(context.Background(), &cmd) require.ErrorContains(t, err, "invalid format of UID") }) - - t.Run("fires an event when the datasource is added", func(t *testing.T) { - db := db.InitTestDB(t) - sqlStore := SqlStore{db: db} - var created *events.DataSourceCreated - db.Bus().AddEventListener(func(ctx context.Context, e *events.DataSourceCreated) error { - created = e - return nil - }) - - _, err := sqlStore.AddDataSource(context.Background(), &defaultAddDatasourceCommand) - require.NoError(t, err) - - require.Eventually(t, func() bool { - return assert.NotNil(t, created) - }, time.Second, time.Millisecond) - - query := datasources.GetDataSourcesQuery{OrgID: 10} - dataSources, err := sqlStore.GetDataSources(context.Background(), &query) - require.NoError(t, err) - require.Equal(t, 1, len(dataSources)) - - require.Equal(t, dataSources[0].ID, created.ID) - require.Equal(t, dataSources[0].UID, created.UID) - require.Equal(t, int64(10), created.OrgID) - require.Equal(t, "nisse", created.Name) - }) }) t.Run("UpdateDataSource", func(t *testing.T) { diff --git a/pkg/services/org/orgimpl/store.go b/pkg/services/org/orgimpl/store.go index 46b96483df5..50bbd68ec82 100644 --- a/pkg/services/org/orgimpl/store.go +++ b/pkg/services/org/orgimpl/store.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" @@ -96,11 +95,6 @@ func (ss *sqlStore) Insert(ctx context.Context, orga *org.Org) (int64, error) { return err } } - sess.PublishAfterCommit(&events.OrgCreated{ - Timestamp: orga.Created, - Id: orga.ID, - Name: orga.Name, - }) return nil }) if err != nil { @@ -156,12 +150,6 @@ func (ss *sqlStore) Update(ctx context.Context, cmd *org.UpdateOrgCommand) error return org.ErrOrgNotFound.Errorf("failed to update organization with ID: %d", cmd.OrgId) } - sess.PublishAfterCommit(&events.OrgUpdated{ - Timestamp: orga.Updated, - Id: orga.ID, - Name: orga.Name, - }) - return nil }) } @@ -200,12 +188,6 @@ func (ss *sqlStore) UpdateAddress(ctx context.Context, cmd *org.UpdateOrgAddress return err } - sess.PublishAfterCommit(&events.OrgUpdated{ - Timestamp: org.Updated, - Id: org.ID, - Name: org.Name, - }) - return nil }) } @@ -345,12 +327,6 @@ func (ss *sqlStore) CreateWithMember(ctx context.Context, cmd *org.CreateOrgComm _, err := sess.Insert(&user) - sess.PublishAfterCommit(&events.OrgCreated{ - Timestamp: orga.Created, - Id: orga.ID, - Name: orga.Name, - }) - return err }); err != nil { return &orga, err diff --git a/pkg/services/sqlstore/session.go b/pkg/services/sqlstore/session.go index 1ded27a3559..8269683493f 100644 --- a/pkg/services/sqlstore/session.go +++ b/pkg/services/sqlstore/session.go @@ -31,10 +31,6 @@ type DBSession struct { type DBTransactionFunc func(sess *DBSession) error -func (sess *DBSession) publishAfterCommit(msg any) { - sess.events = append(sess.events, msg) -} - func (sess *DBSession) PublishAfterCommit(msg any) { sess.events = append(sess.events, msg) } diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 991643b73ae..a76261c465a 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/util" @@ -99,14 +98,6 @@ func (ss *SQLStore) createUser(ctx context.Context, sess *DBSession, args user.C return usr, err } - sess.publishAfterCommit(&events.UserCreated{ - Timestamp: usr.Created, - Id: usr.ID, - Name: usr.Name, - Login: usr.Login, - Email: usr.Email, - }) - orgUser := org.OrgUser{ OrgID: orgID, UserID: usr.ID, @@ -183,11 +174,5 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro } } - sess.publishAfterCommit(&events.OrgCreated{ - Timestamp: org.Created, - Id: org.ID, - Name: org.Name, - }) - return org.ID, nil } diff --git a/pkg/services/user/userimpl/store.go b/pkg/services/user/userimpl/store.go index 49d437e8cb9..a7773147373 100644 --- a/pkg/services/user/userimpl/store.go +++ b/pkg/services/user/userimpl/store.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" @@ -63,13 +62,6 @@ func (ss *sqlStore) Insert(ctx context.Context, cmd *user.User) (int64, error) { if _, err = sess.Insert(cmd); err != nil { return err } - sess.PublishAfterCommit(&events.UserCreated{ - Timestamp: cmd.Created, - Id: cmd.ID, - Name: cmd.Name, - Login: cmd.Login, - Email: cmd.Email, - }) return nil }) @@ -294,14 +286,6 @@ func (ss *sqlStore) Update(ctx context.Context, cmd *user.UpdateUserCommand) err } } - sess.PublishAfterCommit(&events.UserUpdated{ - Timestamp: usr.Created, - Id: usr.ID, - Name: usr.Name, - Login: usr.Login, - Email: usr.Email, - }) - return nil }) }