diff --git a/internal/interactor/deploymentstatistics.go b/internal/interactor/deploymentstatistics.go new file mode 100644 index 00000000..49721f78 --- /dev/null +++ b/internal/interactor/deploymentstatistics.go @@ -0,0 +1,24 @@ +package interactor + +import ( + "context" + + "github.com/gitploy-io/gitploy/ent" +) + +func (i *Interactor) ProduceDeploymentStatisticsOfRepo(ctx context.Context, r *ent.Repo, d *ent.Deployment) (*ent.DeploymentStatistics, error) { + s, err := i.Store.FindDeploymentStatisticsOfRepoByEnv(ctx, r, d.Env) + + if ent.IsNotFound(err) { + return i.Store.CreateDeploymentStatistics(ctx, &ent.DeploymentStatistics{ + Namespace: r.Namespace, + Name: r.Name, + Env: d.Env, + Count: 1, + }) + } + + s.Count = s.Count + 1 + + return i.Store.UpdateDeploymentStatistics(ctx, s) +} diff --git a/internal/interactor/deploymentstatistics_test.go b/internal/interactor/deploymentstatistics_test.go new file mode 100644 index 00000000..2b6c4f0c --- /dev/null +++ b/internal/interactor/deploymentstatistics_test.go @@ -0,0 +1,50 @@ +package interactor + +import ( + "context" + "testing" + + "github.com/gitploy-io/gitploy/ent" + "github.com/gitploy-io/gitploy/internal/interactor/mock" + "github.com/golang/mock/gomock" +) + +func TestInteractor_ProduceDeploymentStatisticsOfRepo(t *testing.T) { + t.Run("Create the statistics when the record is not found.", func(t *testing.T) { + input := struct { + repo *ent.Repo + d *ent.Deployment + }{ + repo: &ent.Repo{ + Namespace: "octocat", + Name: "HelloWorld", + }, + d: &ent.Deployment{ + Env: "production", + }, + } + + ctrl := gomock.NewController(t) + store := mock.NewMockStore(ctrl) + scm := mock.NewMockSCM(ctrl) + + t.Log("MOCK - Find the deployment_statistics by the environment.") + store. + EXPECT(). + FindDeploymentStatisticsOfRepoByEnv(gomock.Any(), gomock.Eq(input.repo), gomock.Eq(input.d.Env)). + Return(nil, &ent.NotFoundError{}) + + t.Log("MOCK - Create a new statistics.") + store. + EXPECT(). + CreateDeploymentStatistics(gomock.Any(), gomock.AssignableToTypeOf(&ent.DeploymentStatistics{})). + Return(&ent.DeploymentStatistics{ID: 1}, nil) + + i := newMockInteractor(store, scm) + + _, err := i.ProduceDeploymentStatisticsOfRepo(context.Background(), input.repo, input.d) + if err != nil { + t.Fatalf("ProduceDeploymentStatisticsOfRepo returns an error: %s", err) + } + }) +} diff --git a/internal/interactor/interface.go b/internal/interactor/interface.go index 90e5c10e..06a7a4e7 100644 --- a/internal/interactor/interface.go +++ b/internal/interactor/interface.go @@ -56,8 +56,12 @@ type ( CreateDeploymentStatus(ctx context.Context, s *ent.DeploymentStatus) (*ent.DeploymentStatus, error) - ListAllDeploymentStatisticss(ctx context.Context) ([]*ent.DeploymentStatistics, error) - ListDeploymentStatisticssGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) + FindDeploymentStatisticsOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.DeploymentStatistics, error) + CreateDeploymentStatistics(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) + UpdateDeploymentStatistics(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) + + ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) + ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) diff --git a/internal/interactor/mock/pkg.go b/internal/interactor/mock/pkg.go index 3ca94fc9..a9894f30 100644 --- a/internal/interactor/mock/pkg.go +++ b/internal/interactor/mock/pkg.go @@ -143,6 +143,21 @@ func (mr *MockStoreMockRecorder) CreateDeployment(ctx, d interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDeployment", reflect.TypeOf((*MockStore)(nil).CreateDeployment), ctx, d) } +// CreateDeploymentStatistics mocks base method. +func (m *MockStore) CreateDeploymentStatistics(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateDeploymentStatistics", ctx, s) + ret0, _ := ret[0].(*ent.DeploymentStatistics) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateDeploymentStatistics indicates an expected call of CreateDeploymentStatistics. +func (mr *MockStoreMockRecorder) CreateDeploymentStatistics(ctx, s interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDeploymentStatistics", reflect.TypeOf((*MockStore)(nil).CreateDeploymentStatistics), ctx, s) +} + // CreateDeploymentStatus mocks base method. func (m *MockStore) CreateDeploymentStatus(ctx context.Context, s *ent.DeploymentStatus) (*ent.DeploymentStatus, error) { m.ctrl.T.Helper() @@ -409,6 +424,21 @@ func (mr *MockStoreMockRecorder) FindDeploymentOfRepoByNumber(ctx, r, number int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindDeploymentOfRepoByNumber", reflect.TypeOf((*MockStore)(nil).FindDeploymentOfRepoByNumber), ctx, r, number) } +// FindDeploymentStatisticsOfRepoByEnv mocks base method. +func (m *MockStore) FindDeploymentStatisticsOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.DeploymentStatistics, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindDeploymentStatisticsOfRepoByEnv", ctx, r, env) + ret0, _ := ret[0].(*ent.DeploymentStatistics) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindDeploymentStatisticsOfRepoByEnv indicates an expected call of FindDeploymentStatisticsOfRepoByEnv. +func (mr *MockStoreMockRecorder) FindDeploymentStatisticsOfRepoByEnv(ctx, r, env interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindDeploymentStatisticsOfRepoByEnv", reflect.TypeOf((*MockStore)(nil).FindDeploymentStatisticsOfRepoByEnv), ctx, r, env) +} + // FindLockByID mocks base method. func (m *MockStore) FindLockByID(ctx context.Context, id int) (*ent.Lock, error) { m.ctrl.T.Helper() @@ -589,19 +619,19 @@ func (mr *MockStoreMockRecorder) HasLockOfRepoForEnv(ctx, r, env interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasLockOfRepoForEnv", reflect.TypeOf((*MockStore)(nil).HasLockOfRepoForEnv), ctx, r, env) } -// ListAllDeploymentStatisticss mocks base method. -func (m *MockStore) ListAllDeploymentStatisticss(ctx context.Context) ([]*ent.DeploymentStatistics, error) { +// ListAllDeploymentStatistics mocks base method. +func (m *MockStore) ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListAllDeploymentStatisticss", ctx) + ret := m.ctrl.Call(m, "ListAllDeploymentStatistics", ctx) ret0, _ := ret[0].([]*ent.DeploymentStatistics) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListAllDeploymentStatisticss indicates an expected call of ListAllDeploymentStatisticss. -func (mr *MockStoreMockRecorder) ListAllDeploymentStatisticss(ctx interface{}) *gomock.Call { +// ListAllDeploymentStatistics indicates an expected call of ListAllDeploymentStatistics. +func (mr *MockStoreMockRecorder) ListAllDeploymentStatistics(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllDeploymentStatisticss", reflect.TypeOf((*MockStore)(nil).ListAllDeploymentStatisticss), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllDeploymentStatistics", reflect.TypeOf((*MockStore)(nil).ListAllDeploymentStatistics), ctx) } // ListApprovals mocks base method. @@ -619,19 +649,19 @@ func (mr *MockStoreMockRecorder) ListApprovals(ctx, d interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListApprovals", reflect.TypeOf((*MockStore)(nil).ListApprovals), ctx, d) } -// ListDeploymentStatisticssGreaterThanTime mocks base method. -func (m *MockStore) ListDeploymentStatisticssGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) { +// ListDeploymentStatisticsGreaterThanTime mocks base method. +func (m *MockStore) ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListDeploymentStatisticssGreaterThanTime", ctx, updated) + ret := m.ctrl.Call(m, "ListDeploymentStatisticsGreaterThanTime", ctx, updated) ret0, _ := ret[0].([]*ent.DeploymentStatistics) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListDeploymentStatisticssGreaterThanTime indicates an expected call of ListDeploymentStatisticssGreaterThanTime. -func (mr *MockStoreMockRecorder) ListDeploymentStatisticssGreaterThanTime(ctx, updated interface{}) *gomock.Call { +// ListDeploymentStatisticsGreaterThanTime indicates an expected call of ListDeploymentStatisticsGreaterThanTime. +func (mr *MockStoreMockRecorder) ListDeploymentStatisticsGreaterThanTime(ctx, updated interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDeploymentStatisticssGreaterThanTime", reflect.TypeOf((*MockStore)(nil).ListDeploymentStatisticssGreaterThanTime), ctx, updated) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDeploymentStatisticsGreaterThanTime", reflect.TypeOf((*MockStore)(nil).ListDeploymentStatisticsGreaterThanTime), ctx, updated) } // ListDeploymentsOfRepo mocks base method. @@ -829,6 +859,21 @@ func (mr *MockStoreMockRecorder) UpdateDeployment(ctx, d interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDeployment", reflect.TypeOf((*MockStore)(nil).UpdateDeployment), ctx, d) } +// UpdateDeploymentStatistics mocks base method. +func (m *MockStore) UpdateDeploymentStatistics(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateDeploymentStatistics", ctx, s) + ret0, _ := ret[0].(*ent.DeploymentStatistics) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateDeploymentStatistics indicates an expected call of UpdateDeploymentStatistics. +func (mr *MockStoreMockRecorder) UpdateDeploymentStatistics(ctx, s interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDeploymentStatistics", reflect.TypeOf((*MockStore)(nil).UpdateDeploymentStatistics), ctx, s) +} + // UpdatePerm mocks base method. func (m *MockStore) UpdatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error) { m.ctrl.T.Helper() diff --git a/internal/pkg/store/deployment.go b/internal/pkg/store/deployment.go index d1e96531..4d296732 100644 --- a/internal/pkg/store/deployment.go +++ b/internal/pkg/store/deployment.go @@ -7,10 +7,8 @@ import ( "entgo.io/ent/dialect/sql" "github.com/gitploy-io/gitploy/ent" "github.com/gitploy-io/gitploy/ent/deployment" - "github.com/gitploy-io/gitploy/ent/deploymentstatistics" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/predicate" - "go.uber.org/zap" ) func (s *Store) SearchDeployments(ctx context.Context, u *ent.User, ss []deployment.Status, owned bool, from time.Time, to time.Time, page, perPage int) ([]*ent.Deployment, error) { @@ -239,47 +237,5 @@ func (s *Store) UpdateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D return nil, err } - if d.Status != deployment.StatusSuccess { - return d, nil - } - - // Update the statistics of deployment by - // increasing the count. - err = s.WithTx(ctx, func(tx *ent.Tx) error { - r, err := tx.Repo.Get(ctx, d.RepoID) - if err != nil { - return err - } - - dc, err := s.c.DeploymentStatistics. - Query(). - Where( - deploymentstatistics.NamespaceEQ(r.Namespace), - deploymentstatistics.NameEQ(r.Name), - deploymentstatistics.EnvEQ(d.Env), - ). - Only(ctx) - if ent.IsNotFound(err) { - s.c.DeploymentStatistics. - Create(). - SetNamespace(r.Namespace). - SetName(r.Name). - SetEnv(d.Env). - Save(ctx) - return nil - } else if err != nil { - return err - } - - s.c.DeploymentStatistics. - UpdateOne(dc). - SetCount(dc.Count + 1). - Save(ctx) - return nil - }) - if err != nil { - zap.L().Error("It has failed to increase the deployment count.", zap.Error(err)) - } - return d, nil } diff --git a/internal/pkg/store/deployment_test.go b/internal/pkg/store/deployment_test.go index 34431fcf..b132f147 100644 --- a/internal/pkg/store/deployment_test.go +++ b/internal/pkg/store/deployment_test.go @@ -426,99 +426,4 @@ func TestStore_UpdateDeployment(t *testing.T) { t.Fatalf("UpdateDeployment = %v, wanted %v", d.Status, expected) } }) - - t.Run("Add a new statistics when the status of deployment is updated.", func(t *testing.T) { - ctx := context.Background() - - client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", - enttest.WithMigrateOptions(migrate.WithForeignKeys(false)), - ) - defer client.Close() - - client.Repo. - Create(). - SetID(1). - SetNamespace("octocat"). - SetName("Hello"). - SetDescription(""). - SaveX(ctx) - - d := client.Deployment.Create(). - SetType(deployment.TypeBranch). - SetNumber(1). - SetType("branch"). - SetRef("main"). - SetEnv("prod"). - SetStatus(deployment.StatusCreated). - SetUserID(1). - SetRepoID(1). - SaveX(ctx) - - s := NewStore(client) - - d.Status = deployment.StatusSuccess - - _, err := s.UpdateDeployment(ctx, d) - if err != nil { - t.Fatalf("UpdateDeployment returns an error: %s", err) - } - - expected := 1 - dc := client.DeploymentStatistics.GetX(ctx, 1) - - if dc.Count != expected { - t.Fatalf("The statistics was not created.") - } - }) - - t.Run("Update the statistics is updated when the status of deployment is updated.", func(t *testing.T) { - ctx := context.Background() - - client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", - enttest.WithMigrateOptions(migrate.WithForeignKeys(false)), - ) - defer client.Close() - - client.Repo. - Create(). - SetID(1). - SetNamespace("octocat"). - SetName("Hello"). - SetDescription(""). - SaveX(ctx) - - d := client.Deployment.Create(). - SetType(deployment.TypeBranch). - SetNumber(1). - SetType("branch"). - SetRef("main"). - SetEnv("prod"). - SetStatus(deployment.StatusCreated). - SetUserID(1). - SetRepoID(1). - SaveX(ctx) - - t.Log("Add the deployment count.") - client.DeploymentStatistics.Create(). - SetNamespace("octocat"). - SetName("Hello"). - SetEnv("prod"). - SaveX(ctx) - - s := NewStore(client) - - d.Status = deployment.StatusSuccess - - _, err := s.UpdateDeployment(ctx, d) - if err != nil { - t.Fatalf("UpdateDeployment returns an error: %s", err) - } - - expected := 2 - dc := client.DeploymentStatistics.GetX(ctx, 1) - - if dc.Count != expected { - t.Fatalf("The statistics was not created.") - } - }) } diff --git a/internal/pkg/store/deploymentcount.go b/internal/pkg/store/deploymentcount.go deleted file mode 100644 index dce74fbe..00000000 --- a/internal/pkg/store/deploymentcount.go +++ /dev/null @@ -1,24 +0,0 @@ -package store - -import ( - "context" - "time" - - "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/deploymentstatistics" -) - -func (s *Store) ListAllDeploymentStatisticss(ctx context.Context) ([]*ent.DeploymentStatistics, error) { - return s.c.DeploymentStatistics. - Query(). - All(ctx) -} - -func (s *Store) ListDeploymentStatisticssGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) { - return s.c.DeploymentStatistics. - Query(). - Where( - deploymentstatistics.UpdatedAtGT(updated), - ). - All(ctx) -} diff --git a/internal/pkg/store/deploymentstatistics.go b/internal/pkg/store/deploymentstatistics.go new file mode 100644 index 00000000..324a92ab --- /dev/null +++ b/internal/pkg/store/deploymentstatistics.go @@ -0,0 +1,52 @@ +package store + +import ( + "context" + "time" + + "github.com/gitploy-io/gitploy/ent" + "github.com/gitploy-io/gitploy/ent/deploymentstatistics" +) + +func (s *Store) ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) { + return s.c.DeploymentStatistics. + Query(). + All(ctx) +} + +func (s *Store) ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) { + return s.c.DeploymentStatistics. + Query(). + Where( + deploymentstatistics.UpdatedAtGT(updated), + ). + All(ctx) +} + +func (s *Store) FindDeploymentStatisticsOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.DeploymentStatistics, error) { + return s.c.DeploymentStatistics. + Query(). + Where( + deploymentstatistics.NamespaceEQ(r.Namespace), + deploymentstatistics.NameEQ(r.Name), + deploymentstatistics.EnvEQ(env), + ). + Only(ctx) +} + +func (s *Store) CreateDeploymentStatistics(ctx context.Context, ds *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) { + return s.c.DeploymentStatistics. + Create(). + SetNamespace(ds.Namespace). + SetName(ds.Name). + SetEnv(ds.Env). + SetCount(ds.Count). + Save(ctx) +} + +func (s *Store) UpdateDeploymentStatistics(ctx context.Context, ds *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) { + return s.c.DeploymentStatistics. + UpdateOne(ds). + SetCount(ds.Count). + Save(ctx) +} diff --git a/internal/pkg/store/deploymentcount_test.go b/internal/pkg/store/deploymentstatistics_test.go similarity index 87% rename from internal/pkg/store/deploymentcount_test.go rename to internal/pkg/store/deploymentstatistics_test.go index cde6dca1..618177b5 100644 --- a/internal/pkg/store/deploymentcount_test.go +++ b/internal/pkg/store/deploymentstatistics_test.go @@ -9,7 +9,7 @@ import ( "github.com/gitploy-io/gitploy/ent/migrate" ) -func TestStore_ListDeploymentStatisticssGreaterThanTime(t *testing.T) { +func TestStore_ListDeploymentStatisticsGreaterThanTime(t *testing.T) { ctx := context.Background() client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", @@ -37,7 +37,7 @@ func TestStore_ListDeploymentStatisticssGreaterThanTime(t *testing.T) { s := NewStore(client) - dcs, err := s.ListDeploymentStatisticssGreaterThanTime(ctx, tm) + dcs, err := s.ListDeploymentStatisticsGreaterThanTime(ctx, tm) if err != nil { t.Fatalf("ListDeploymentStatisticssGreaterThanTime returns an error: %s", err) } diff --git a/internal/server/hooks/hook.go b/internal/server/hooks/hook.go index fa3aca5a..915a87f6 100644 --- a/internal/server/hooks/hook.go +++ b/internal/server/hooks/hook.go @@ -119,6 +119,13 @@ func (h *Hooks) handleGithubHook(c *gin.Context) { h.log.Error("It has failed to create the event.", zap.Error(err)) } + // Produce statistics when the deployment is success. + if d.Status == deployment.StatusSuccess && d.Edges.Repo != nil { + if _, err := h.i.ProduceDeploymentStatisticsOfRepo(ctx, d.Edges.Repo, d); err != nil { + h.log.Error("It has failed to produce the statistics of deployment.", zap.Error(err)) + } + } + gb.Response(c, http.StatusCreated, ds) } diff --git a/internal/server/hooks/interface.go b/internal/server/hooks/interface.go index e8fd884e..5cf0d58b 100644 --- a/internal/server/hooks/interface.go +++ b/internal/server/hooks/interface.go @@ -13,6 +13,7 @@ type ( FindDeploymentByUID(ctx context.Context, uid int64) (*ent.Deployment, error) CreateDeploymentStatus(ctx context.Context, s *ent.DeploymentStatus) (*ent.DeploymentStatus, error) UpdateDeployment(ctx context.Context, d *ent.Deployment) (*ent.Deployment, error) + ProduceDeploymentStatisticsOfRepo(ctx context.Context, r *ent.Repo, d *ent.Deployment) (*ent.DeploymentStatistics, error) CreateEvent(ctx context.Context, e *ent.Event) (*ent.Event, error) } ) diff --git a/internal/server/hooks/mock/interactor.go b/internal/server/hooks/mock/interactor.go index 4a036a1b..c4bc4a2b 100644 --- a/internal/server/hooks/mock/interactor.go +++ b/internal/server/hooks/mock/interactor.go @@ -80,6 +80,21 @@ func (mr *MockInteractorMockRecorder) FindDeploymentByUID(ctx, uid interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindDeploymentByUID", reflect.TypeOf((*MockInteractor)(nil).FindDeploymentByUID), ctx, uid) } +// ProduceDeploymentStatisticsOfRepo mocks base method. +func (m *MockInteractor) ProduceDeploymentStatisticsOfRepo(ctx context.Context, r *ent.Repo, d *ent.Deployment) (*ent.DeploymentStatistics, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProduceDeploymentStatisticsOfRepo", ctx, r, d) + ret0, _ := ret[0].(*ent.DeploymentStatistics) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProduceDeploymentStatisticsOfRepo indicates an expected call of ProduceDeploymentStatisticsOfRepo. +func (mr *MockInteractorMockRecorder) ProduceDeploymentStatisticsOfRepo(ctx, r, d interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProduceDeploymentStatisticsOfRepo", reflect.TypeOf((*MockInteractor)(nil).ProduceDeploymentStatisticsOfRepo), ctx, r, d) +} + // UpdateDeployment mocks base method. func (m *MockInteractor) UpdateDeployment(ctx context.Context, d *ent.Deployment) (*ent.Deployment, error) { m.ctrl.T.Helper() diff --git a/internal/server/metrics/interface.go b/internal/server/metrics/interface.go index f6979b79..bf894d3a 100644 --- a/internal/server/metrics/interface.go +++ b/internal/server/metrics/interface.go @@ -10,8 +10,8 @@ import ( type ( Interactor interface { - ListAllDeploymentStatisticss(ctx context.Context) ([]*ent.DeploymentStatistics, error) - ListDeploymentStatisticssGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) + ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) + ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) GetLicense(ctx context.Context) (*vo.License, error) } ) diff --git a/internal/server/metrics/metrics.go b/internal/server/metrics/metrics.go index 82288602..bdf2fbd9 100644 --- a/internal/server/metrics/metrics.go +++ b/internal/server/metrics/metrics.go @@ -92,13 +92,13 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { if len(c.cache) == 0 { c.log.Debug("List all deployment_count.") - if dcs, err = c.i.ListAllDeploymentStatisticss(ctx); err != nil { + if dcs, err = c.i.ListAllDeploymentStatistics(ctx); err != nil { c.log.Error("It has failed to list all deployment_counts.", zap.Error(err)) return } } else { c.log.Debug("List deployment_count from the last time.", zap.Time("last", c.lastTime)) - if dcs, err = c.i.ListDeploymentStatisticssGreaterThanTime(ctx, c.lastTime); err != nil { + if dcs, err = c.i.ListDeploymentStatisticsGreaterThanTime(ctx, c.lastTime); err != nil { c.log.Error("It has failed to list deployment_counts.", zap.Error(err)) return }