-
Notifications
You must be signed in to change notification settings - Fork 209
Improve insight collector #1340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following files are not gofmt-ed. By commenting pkg/app/ops/insightcollector/collector_test.go--- pkg/app/ops/insightcollector/collector_test.go.orig
+++ pkg/app/ops/insightcollector/collector_test.go
@@ -20,10 +20,12 @@
"testing"
"time"
- "github.com/pipe-cd/pipe/pkg/filestore/filestoretest"
"go.uber.org/zap"
+ "github.com/pipe-cd/pipe/pkg/filestore/filestoretest"
+
"github.com/golang/mock/gomock"
+
"github.com/pipe-cd/pipe/pkg/datastore"
"github.com/pipe-cd/pipe/pkg/datastore/datastoretest"
|
pipecd-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| i.logger.Error("failed to update application chunks", zap.Error(err)) | ||
| } | ||
| var returnErr error | ||
| for appId, ds := range appMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range var appId should be appID
| } | ||
| return nil | ||
| } | ||
| for proId, ds := range projectMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range var proId should be proID
| i.logger.Error("failed to update application chunks", zap.Error(err)) | ||
| } | ||
| var returnErr error | ||
| for appId, ds := range appMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range var appId should be appID
| maxCreatedAt = apps[len(apps)-1].CreatedAt | ||
| } | ||
| return nil | ||
| for proId, ds := range projectMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range var proId should be proID
| return err | ||
| } | ||
|
|
||
| dc, err := i.getDeploymentsWithCreatedAt(ctx, m.DeploymentCreatedAtMilestone, targetDate.Unix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ineffectual assignment to err
| continue | ||
| } | ||
| for _, k := range aggregateKinds { | ||
| dc, err := i.getDeploymentsWithCompletedAt(ctx, m.DeploymentCompletedAtMilestone, targetDate.Unix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ineffectual assignment to err
|
Code coverage for golang is
|
|
Code coverage for golang is
|
|
Code coverage for golang is
|
|
Code coverage for golang is
|
cmd/pipecd/ops.go
Outdated
| t.Logger.Info("application insight collector successfully finished", zap.Duration("duration", time.Since(start))) | ||
| retryAggregateWithCompletedAt := true | ||
| retryAggregateWithCreatedAt := true | ||
| for i := 0; i < cfg.InsightCollector.RetryTime; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are having a backoff package for this retrying purpose. So could you apply it to this?
https://github.com/pipe-cd/pipe/tree/master/pkg/backoff
https://github.com/pipe-cd/pipe/blob/master/pkg/backoff/backoff.go#L34
https://github.com/pipe-cd/pipe/blob/master/pkg/backoff/constant.go#L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks 👍
| // updated all project's insights completely | ||
| break | ||
| func (i *InsightCollector) AggregateWithCreatedAt(ctx context.Context) error { | ||
| currentTime := time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: now := time.Now()
| if len(projects) == 0 { | ||
| // updated all project's insights completely | ||
| break | ||
| func (i *InsightCollector) AggregateWithCreatedAt(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: processNewlyCreatedDeployments
| if len(apps) == 0 { | ||
| // updated all application's insights completely | ||
| break | ||
| func (i *InsightCollector) AggregateWithCompletedAt(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: processNewlyCompletedDeployments
| appMap, projectMap := i.groupingDeployments(dc) | ||
|
|
||
| var returnErr error | ||
| for appID, ds := range appMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for id, ds := range apps
| if err != nil { | ||
| return err | ||
| } | ||
| appMap, projectMap := i.groupingDeployments(dc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: apps, projects := i.groupDeployments(dc)
| } | ||
| appMap, projectMap := i.groupingDeployments(dc) | ||
|
|
||
| var returnErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: updateErr
| if returnErr == nil { | ||
| m.DeploymentCreatedAtMilestone = targetDate.Unix() | ||
| } | ||
| if err := i.insightstore.PutMilestone(ctx, m); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update the milestone when returnErr was not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly 👍
|
@sanposhiho Hi, thanks for your great work! |
|
Code coverage for golang is
|
|
@nghialv |
|
Yep, looks neat 👍 |
| Schedule string `json:"schedule"` | ||
| Schedule string `json:"schedule"` | ||
| RetryTime int `json:"retryTime"` | ||
| RetryIntervalHour int `json:"retryIntervalHour"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set the default value for these fields. Currently, they are zero it means no jobs will be executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍
cmd/pipecd/ops.go
Outdated
| var failed bool | ||
| start := time.Now() | ||
| if err = collector.ProcessNewlyCompletedDeployments(ctx); err != nil { | ||
| t.Logger.Error("failed to process the insight collector with completedAt", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: failed to process the newly completed deployments while accumulating insight data
cmd/pipecd/ops.go
Outdated
| t.Logger.Error("failed to process the insight collector with completedAt", zap.Error(err)) | ||
| failed = true | ||
| } else { | ||
| t.Logger.Info("processing the insight collector with completedAt successfully finished", zap.Duration("duration", time.Since(start))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: successfully processed the newly completed deployments while accumulating insight data
cmd/pipecd/ops.go
Outdated
|
|
||
| start = time.Now() | ||
| if err = collector.ProcessNewlyCreatedDeployments(ctx); err != nil { | ||
| t.Logger.Error("failed to process the insight collector with createdAt", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: failed to process the newly created deployments while accumulating insight data
cmd/pipecd/ops.go
Outdated
| t.Logger.Error("failed to process the insight collector with createdAt", zap.Error(err)) | ||
| failed = true | ||
| } else { | ||
| t.Logger.Info("processing the insight collector with createdAt successfully finished", zap.Duration("duration", time.Since(start))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: successfully processed the newly created deployments while accumulating insight data
cmd/pipecd/ops.go
Outdated
| for retry.WaitNext(ctx) { | ||
| var failed bool | ||
| start := time.Now() | ||
| if err = collector.ProcessNewlyCompletedDeployments(ctx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you skip calling this function when it was completed successfully while ProcessNewlyCreatedDeployments was failed? I know that the insight data will not be affected but we can save some unnecessary DB calls by skip calling this one.
|
|
||
| // getInsightDataForDeployFrequency accumulate insight data in target range for deploy frequency. | ||
| func (i *InsightCollector) getInsightDataForDeployFrequency( | ||
| func (i *InsightCollector) getDeploymentsWithCreatedAt( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: findDeploymentsCreatedInRange
| i.logger.Error("failed to get deployments", zap.Error(err)) | ||
| return &insight.ChangeFailureRate{}, time.Time{}, fmt.Errorf("failed to get deployments") | ||
| // groupingDeployments groups deoloyments by applicationID and projectID | ||
| func (i *InsightCollector) groupingDeployments(deployments []*model.Deployment) (map[string][]*model.Deployment, map[string][]*model.Deployment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: groupDeployments
| if err != nil { | ||
| i.logger.Error("failed to get deployments", zap.Error(err)) | ||
| return &insight.ChangeFailureRate{}, time.Time{}, fmt.Errorf("failed to get deployments") | ||
| // groupingDeployments groups deoloyments by applicationID and projectID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: deployments
| return &insight.ChangeFailureRate{}, time.Time{}, fmt.Errorf("failed to get deployments") | ||
| // groupingDeployments groups deoloyments by applicationID and projectID | ||
| func (i *InsightCollector) groupingDeployments(deployments []*model.Deployment) (map[string][]*model.Deployment, map[string][]*model.Deployment) { | ||
| appmap := map[string][]*model.Deployment{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: apps, projects
| ) | ||
|
|
||
| // extractDeployFrequency extracts deploy frequency from deployments with specified range | ||
| func (i *InsightCollector) extractDeployFrequency(deployments []*model.Deployment, from, to int64, targetTimestamp int64) (*insight.DeployFrequency, []*model.Deployment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be an independent function, doesn't need to belong to InsightCollector.
| } | ||
|
|
||
| // extractDeployFrequency extracts change failure rate from deployments with specified range | ||
| func (i *InsightCollector) extractChangeFailureRate(deployments []*model.Deployment, from, to int64, targetTimestamp int64) (*insight.ChangeFailureRate, []*model.Deployment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be an independent function, doesn't need to belong to InsightCollector.
|
@sanposhiho Thanks for your updates. Could you take a look at my recent reviews? |
|
Code coverage for golang is
|
|
@sanposhiho Many thanks for your efforts. |
What this PR does / why we need it:
Change the insight collector logic to reduce communication with datastore.
Which issue(s) this PR fixes:
Fixes #1314
Does this PR introduce a user-facing change?: