mirror of https://github.com/harness/drone.git
feat: [CDE-263]: Changes to track Gitspaces usage across installations. (#2584)
* feat: [CDE-263]: Changes to track Gitspaces usage across installations.pull/3545/head
parent
2595b5dba5
commit
01e26bdb82
|
@ -40,6 +40,7 @@ type metricData struct {
|
||||||
Repos int64 `json:"repo_count"`
|
Repos int64 `json:"repo_count"`
|
||||||
Pipelines int64 `json:"pipeline_count"`
|
Pipelines int64 `json:"pipeline_count"`
|
||||||
Executions int64 `json:"execution_count"`
|
Executions int64 `json:"execution_count"`
|
||||||
|
Gitspaces int64 `json:"gitspace_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
|
@ -52,6 +53,7 @@ type Collector struct {
|
||||||
pipelineStore store.PipelineStore
|
pipelineStore store.PipelineStore
|
||||||
executionStore store.ExecutionStore
|
executionStore store.ExecutionStore
|
||||||
scheduler *job.Scheduler
|
scheduler *job.Scheduler
|
||||||
|
gitspaceConfigStore store.GitspaceConfigStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Register(ctx context.Context) error {
|
func (c *Collector) Register(ctx context.Context) error {
|
||||||
|
@ -107,6 +109,12 @@ func (c *Collector) Handle(ctx context.Context, _ string, _ job.ProgressReporter
|
||||||
return "", fmt.Errorf("failed to get executions total count: %w", err)
|
return "", fmt.Errorf("failed to get executions total count: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// total gitspaces (configs) in the system
|
||||||
|
totalGitspaces, err := c.gitspaceConfigStore.Count(ctx, &types.GitspaceFilter{IncludeDeleted: true})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get gitspace total count: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
data := metricData{
|
data := metricData{
|
||||||
Hostname: c.hostname,
|
Hostname: c.hostname,
|
||||||
Installer: users[0].Email,
|
Installer: users[0].Email,
|
||||||
|
@ -116,6 +124,7 @@ func (c *Collector) Handle(ctx context.Context, _ string, _ job.ProgressReporter
|
||||||
Repos: totalRepos,
|
Repos: totalRepos,
|
||||||
Pipelines: totalPipelines,
|
Pipelines: totalPipelines,
|
||||||
Executions: totalExecutions,
|
Executions: totalExecutions,
|
||||||
|
Gitspaces: totalGitspaces,
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
|
@ -34,6 +34,7 @@ func ProvideCollector(
|
||||||
executionStore store.ExecutionStore,
|
executionStore store.ExecutionStore,
|
||||||
scheduler *job.Scheduler,
|
scheduler *job.Scheduler,
|
||||||
executor *job.Executor,
|
executor *job.Executor,
|
||||||
|
gitspaceConfigStore store.GitspaceConfigStore,
|
||||||
) (*Collector, error) {
|
) (*Collector, error) {
|
||||||
job := &Collector{
|
job := &Collector{
|
||||||
hostname: config.InstanceID,
|
hostname: config.InstanceID,
|
||||||
|
@ -45,6 +46,7 @@ func ProvideCollector(
|
||||||
pipelineStore: pipelineStore,
|
pipelineStore: pipelineStore,
|
||||||
executionStore: executionStore,
|
executionStore: executionStore,
|
||||||
scheduler: scheduler,
|
scheduler: scheduler,
|
||||||
|
gitspaceConfigStore: gitspaceConfigStore,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := executor.Register(jobType, job)
|
err := executor.Register(jobType, job)
|
||||||
|
|
|
@ -100,10 +100,18 @@ func (s gitspaceConfigStore) Count(ctx context.Context, filter *types.GitspaceFi
|
||||||
db := dbtx.GetAccessor(ctx, s.db)
|
db := dbtx.GetAccessor(ctx, s.db)
|
||||||
countStmt := database.Builder.
|
countStmt := database.Builder.
|
||||||
Select("COUNT(*)").
|
Select("COUNT(*)").
|
||||||
From(gitspaceConfigsTable).
|
From(gitspaceConfigsTable)
|
||||||
Where(squirrel.Eq{"gconf_is_deleted": false}).
|
|
||||||
Where(squirrel.Eq{"gconf_user_uid": filter.UserID}).
|
if !filter.IncludeDeleted {
|
||||||
Where(squirrel.Eq{"gconf_space_id": filter.SpaceIDs})
|
countStmt = countStmt.Where(squirrel.Eq{"gconf_is_deleted": false})
|
||||||
|
}
|
||||||
|
if filter.UserID != "" {
|
||||||
|
countStmt = countStmt.Where(squirrel.Eq{"gconf_user_uid": filter.UserID})
|
||||||
|
}
|
||||||
|
if filter.SpaceIDs != nil {
|
||||||
|
countStmt = countStmt.Where(squirrel.Eq{"gconf_space_id": filter.SpaceIDs})
|
||||||
|
}
|
||||||
|
|
||||||
sql, args, err := countStmt.ToSql()
|
sql, args, err := countStmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
return 0, errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
||||||
|
|
|
@ -448,7 +448,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
collector, err := metric.ProvideCollector(config, principalStore, repoStore, pipelineStore, executionStore, jobScheduler, executor)
|
collector, err := metric.ProvideCollector(config, principalStore, repoStore, pipelineStore, executionStore, jobScheduler, executor, gitspaceConfigStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,4 +80,5 @@ type GitspaceFilter struct {
|
||||||
QueryFilter ListQueryFilter
|
QueryFilter ListQueryFilter
|
||||||
UserID string
|
UserID string
|
||||||
SpaceIDs []int64
|
SpaceIDs []int64
|
||||||
|
IncludeDeleted bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue