Skip to content

Commit 6282157

Browse files
authored
Merge pull request #116 from devtron-labs/git-cli-analytics-develop
fix: Git cli analytics develop
2 parents 29c649f + 2f948af commit 6282157

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

config.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# GITSENSOR CONFIGMAP
22

3-
| Key | Value | Description |
4-
|-----------------------------------|------------------------------------|-------------------------------|
5-
| PG_ADDR | postgresql-postgresql.devtroncd | PostgreSQL Server Address |
6-
| PG_USER | postgres | PostgreSQL User |
7-
| PG_DATABASE | git_sensor | PostgreSQL Database Name |
8-
| SENTRY_ENV | prod | Sentry Environment |
9-
| SENTRY_ENABLED | "false" | Sentry Enabled (boolean) |
10-
| POLL_DURATION | "1" | Polling Duration (in seconds) |
11-
| POLL_WORKER | "2" | Number of Polling Workers |
12-
| PG_LOG_QUERY | "false" | PostgreSQL Query Logging (boolean) |
13-
| COMMIT_STATS_TIMEOUT_IN_SEC | "2" | Commit Stats Timeout (in seconds) |
14-
| ENABLE_FILE_STATS | "false" | Enable File Stats (boolean) |
15-
| GIT_HISTORY_COUNT | "15" | Git History Count |
16-
| CLONING_MODE | FULL | Cloning Mode (Possible values: SHALLOW, FULL) |
3+
| Key | Value | Description |
4+
|-----------------------------|---------------------------------|---------------------------------------------------------------------|
5+
| PG_ADDR | postgresql-postgresql.devtroncd | PostgreSQL Server Address |
6+
| PG_USER | postgres | PostgreSQL User |
7+
| PG_DATABASE | git_sensor | PostgreSQL Database Name |
8+
| SENTRY_ENV | prod | Sentry Environment |
9+
| SENTRY_ENABLED | "false" | Sentry Enabled (boolean) |
10+
| POLL_DURATION | "1" | Polling Duration (in seconds) |
11+
| POLL_WORKER | "2" | Number of Polling Workers |
12+
| PG_LOG_QUERY | "false" | PostgreSQL Query Logging (boolean) |
13+
| COMMIT_STATS_TIMEOUT_IN_SEC | "2" | Commit Stats Timeout (in seconds) |
14+
| ENABLE_FILE_STATS | "false" | Enable File Stats (boolean) |
15+
| GIT_HISTORY_COUNT | "15" | Git History Count |
16+
| CLONING_MODE | FULL | Cloning Mode (Possible values: SHALLOW, FULL) |
17+
| USE_GIT_CLI | "false" | Use git cli commands directly for all git operations |
18+
| USE_GIT_CLI_ANALYTICS | "false" | Use git cli commands directly for getting commit data for analytics |

internals/Configuration.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ type Configuration struct {
2424
GitHistoryCount int `env:"GIT_HISTORY_COUNT" envDefault:"15"`
2525
MinLimit int `env:"MIN_LIMIT_FOR_PVC" envDefault:"1"` // in MB
2626
UseGitCli bool `env:"USE_GIT_CLI" envDefault:"false"`
27+
UseGitCliAnalytics bool `env:"USE_GIT_CLI_ANALYTICS" envDefault:"false"` // This flag is used to compute commitDiff using git-cli only for analytics
2728
AnalyticsDebug bool `env:"ANALYTICS_DEBUG" envDefault:"false"`
2829
CliCmdTimeoutGlobal int `env:"CLI_CMD_TIMEOUT_GLOBAL_SECONDS" envDefault:"0"`
2930
CliCmdTimeoutJson string `env:"CLI_CMD_TIMEOUT_JSON" envDefault:""`
30-
GoGitTimeout int `env:"GOGIT_TIMEOUT_SECONDS" envDefault:"10"`
31+
GoGitTimeout int `env:"GOGIT_TIMEOUT_SECONDS" envDefault:"10" `
3132
}
3233

3334
func ParseConfiguration() (*Configuration, error) {

pkg/git/RepositoryManagerAnalytics.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func transform(src *object.Commit, tag *object.Tag) (dst *Commit) {
202202
func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(gitCtx GitContext, checkoutPath string, Old string, New string) (*GitChanges, error) {
203203
var err error
204204
start := time.Now()
205+
useGitCli := impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics
205206
defer func() {
206207
util.TriggerGitOperationMetrics("changesSinceByRepositoryForAnalytics", start, err)
207208
}()
@@ -214,7 +215,7 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
214215
oldHash := plumbing.NewHash(Old)
215216

216217
var fileStats FileStats
217-
if strings.Contains(checkoutPath, "/.git") || impl.configuration.UseGitCli {
218+
if strings.Contains(checkoutPath, "/.git") || useGitCli {
218219
oldHashString := oldHash.String()
219220
newHashString := newHash.String()
220221
fileStats, err = impl.gitManager.FetchDiffStatBetweenCommitsWithNumstat(gitCtx, oldHashString, newHashString, checkoutPath)
@@ -243,14 +244,17 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
243244
func (impl RepositoryManagerAnalyticsImpl) computeCommitDiff(gitCtx GitContext, checkoutPath string, oldHash plumbing.Hash, newHash plumbing.Hash, repository *GitRepository) ([]*Commit, error) {
244245
var commitsCli, commitsGoGit []*Commit
245246
var err error
246-
if impl.configuration.UseGitCli || impl.configuration.AnalyticsDebug {
247+
useGitCli := impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics
248+
if useGitCli || impl.configuration.AnalyticsDebug {
249+
impl.logger.Infow("Computing commit diff using cli ", "checkoutPath", checkoutPath)
247250
commitsCli, err = impl.gitManager.LogMergeBase(gitCtx, checkoutPath, oldHash.String(), newHash.String())
248251
if err != nil {
249252
impl.logger.Errorw("error in fetching commits for analytics through CLI: ", "err", err)
250253
return nil, err
251254
}
252255
}
253-
if !impl.configuration.UseGitCli || impl.configuration.AnalyticsDebug {
256+
if !useGitCli || impl.configuration.AnalyticsDebug {
257+
impl.logger.Infow("Computing commit diff using go-git ", "checkoutPath", checkoutPath)
254258
ctx, cancel := gitCtx.WithTimeout(impl.configuration.GoGitTimeout)
255259
defer cancel()
256260
commitsGoGit, err = RunWithTimeout(ctx, func() ([]*Commit, error) {
@@ -265,7 +269,7 @@ func (impl RepositoryManagerAnalyticsImpl) computeCommitDiff(gitCtx GitContext,
265269
impl.logOldestCommitComparison(commitsGoGit, commitsCli, checkoutPath, oldHash.String(), newHash.String())
266270
}
267271

268-
if !impl.configuration.UseGitCli {
272+
if !useGitCli {
269273
return commitsGoGit, nil
270274
}
271275
return commitsCli, nil

0 commit comments

Comments
 (0)