-
Notifications
You must be signed in to change notification settings - Fork 208
Create GetInsightData for deploy frequency #1188
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a34eb41
Create GetInsightData for deploy frequency
sanposhiho 79393b0
Add test for getInsightDataForDeployFrequency
sanposhiho 6d0a32a
Rename projectId to projectID
sanposhiho 4344548
Add assert in test for response
sanposhiho 54d2c7a
Add test to check error pattern
sanposhiho 6c1965f
Remove empty line
sanposhiho 8681e87
Fix to catch invalid step
sanposhiho 74cb3bd
Fix to use zap.NewNop()
sanposhiho efd3f84
Rename accumulateFrom to start
sanposhiho 79061bd
Fix to specify timezone UTC
sanposhiho 651c401
Fix to reset to zero in weekly and daily
sanposhiho 4939e23
Add pageSize opts
sanposhiho fbbd84c
Support only daily to prevent heavy loading
sanposhiho bb63a36
Remove unuse deps
sanposhiho 127d2a3
Add comment for support
sanposhiho 33abb45
Fix to specify page on ListDeployments option
sanposhiho e19da30
Go fmted
sanposhiho 98c92e7
Fix not to get all data with page
sanposhiho 06e9695
Remove empty line
sanposhiho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,12 @@ package grpcapi | |
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "reflect" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "go.uber.org/zap" | ||
|
|
||
|
||
| "github.com/golang/mock/gomock" | ||
| "github.com/stretchr/testify/assert" | ||
|
|
@@ -387,3 +391,193 @@ func TestValidatePipedBelongsToProject(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetInsightDataForDeployFrequency(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| PageSizeForListDeployments := 50 | ||
| tests := []struct { | ||
| name string | ||
| pipedID string | ||
| projectID string | ||
| pipedProjectCache cache.Cache | ||
| deploymentStore datastore.DeploymentStore | ||
| req *webservice.GetInsightDataRequest | ||
| res *webservice.GetInsightDataResponse | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "valid with InsightStep_DAILY", | ||
| pipedID: "pipedID", | ||
| projectID: "projectID", | ||
| deploymentStore: func() datastore.DeploymentStore { | ||
| target := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) | ||
| targetNextDate := target.AddDate(0, 0, 1) | ||
| s := datastoretest.NewMockDeploymentStore(ctrl) | ||
| s.EXPECT(). | ||
| ListDeployments(gomock.Any(), datastore.ListOptions{ | ||
| PageSize: PageSizeForListDeployments, | ||
| Page: 1, | ||
| Filters: []datastore.ListFilter{ | ||
| { | ||
| Field: "ProjectId", | ||
| Operator: "==", | ||
| Value: "projectID", | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: ">=", | ||
| Value: target.Unix(), | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: "<", | ||
| Value: targetNextDate.Unix(), | ||
| }, | ||
| { | ||
| Field: "ApplicationId", | ||
| Operator: "==", | ||
| Value: "ApplicationId", | ||
| }, | ||
| }, | ||
| }).Return([]*model.Deployment{ | ||
| { | ||
| Id: "id1", | ||
| }, | ||
| { | ||
| Id: "id2", | ||
| }, | ||
| }, nil) | ||
|
|
||
| target = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC) | ||
| targetNextDate = target.AddDate(0, 0, 1) | ||
| s.EXPECT(). | ||
| ListDeployments(gomock.Any(), datastore.ListOptions{ | ||
| PageSize: PageSizeForListDeployments, | ||
| Page: 1, | ||
| Filters: []datastore.ListFilter{ | ||
| { | ||
| Field: "ProjectId", | ||
| Operator: "==", | ||
| Value: "projectID", | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: ">=", | ||
| Value: target.Unix(), | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: "<", | ||
| Value: targetNextDate.Unix(), | ||
| }, | ||
| { | ||
| Field: "ApplicationId", | ||
| Operator: "==", | ||
| Value: "ApplicationId", | ||
| }, | ||
| }, | ||
| }).Return([]*model.Deployment{ | ||
| { | ||
| Id: "id1", | ||
| }, | ||
| { | ||
| Id: "id2", | ||
| }, | ||
| { | ||
| Id: "id3", | ||
| }, | ||
| }, nil) | ||
|
|
||
| return s | ||
| }(), | ||
| req: &webservice.GetInsightDataRequest{ | ||
| MetricsKind: model.InsightMetricsKind_DEPLOYMENT_FREQUENCY, | ||
| Step: model.InsightStep_DAILY, | ||
| RangeFrom: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), | ||
| DataPointCount: 2, | ||
| ApplicationId: "ApplicationId", | ||
| }, | ||
| res: &webservice.GetInsightDataResponse{ | ||
| UpdatedAt: time.Now().Unix(), | ||
| DataPoints: []*model.InsightDataPoint{ | ||
| { | ||
| Value: 2, | ||
| Timestamp: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), | ||
| }, | ||
| { | ||
| Value: 3, | ||
| Timestamp: time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC).Unix(), | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "return error when something wrong happen on ListDeployments", | ||
| pipedID: "pipedID", | ||
| projectID: "projectID", | ||
| deploymentStore: func() datastore.DeploymentStore { | ||
| target := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) | ||
| targetNextYear := target.AddDate(0, 0, 1) | ||
| s := datastoretest.NewMockDeploymentStore(ctrl) | ||
| s.EXPECT(). | ||
| ListDeployments(gomock.Any(), datastore.ListOptions{ | ||
| PageSize: PageSizeForListDeployments, | ||
| Page: 1, | ||
| Filters: []datastore.ListFilter{ | ||
| { | ||
| Field: "ProjectId", | ||
| Operator: "==", | ||
| Value: "projectID", | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: ">=", | ||
| Value: target.Unix(), | ||
| }, | ||
| { | ||
| Field: "CreatedAt", | ||
| Operator: "<", | ||
| Value: targetNextYear.Unix(), | ||
| }, | ||
| { | ||
| Field: "ApplicationId", | ||
| Operator: "==", | ||
| Value: "ApplicationId", | ||
| }, | ||
| }, | ||
| }).Return([]*model.Deployment{}, fmt.Errorf("something wrong happens in ListDeployments")) | ||
| return s | ||
| }(), | ||
| req: &webservice.GetInsightDataRequest{ | ||
| MetricsKind: model.InsightMetricsKind_DEPLOYMENT_FREQUENCY, | ||
| Step: model.InsightStep_DAILY, | ||
| RangeFrom: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), | ||
| DataPointCount: 2, | ||
| ApplicationId: "ApplicationId", | ||
| }, | ||
| res: nil, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| api := &WebAPI{ | ||
| pipedProjectCache: tt.pipedProjectCache, | ||
| deploymentStore: tt.deploymentStore, | ||
| logger: zap.NewNop(), | ||
| } | ||
| res, err := api.getInsightDataForDeployFrequency(ctx, tt.projectID, tt.req) | ||
| assert.Equal(t, tt.wantErr, err != nil) | ||
| if err == nil { | ||
| assert.Equal(t, tt.res.DataPoints, res.DataPoints) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
For
YEARLY, andMONTHLYwe will face a heavy load on our database.I know that this implementation is just the initial phase before applying the batch strategy in the
ops,But maybe we should limit the requestable range and step. For example, only
7 daysfor theDAILYis supported at this time.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.
Agree :)
So, in this time, support the condition only as your example(only 7 days for the DAILY is supported)