Skip to content

Conversation

@nakabonne
Copy link
Member

What this PR does / why we need it:
This PR adds an RPC to update registered enabled apps.
As discussed previously, it is based on the assumption that a single app config file will not be referenced by multiple enabled apps. This should be made explicit in the documentation. But well eventually this will be able to be validated when added.

One case where is likely happen is enabling a disabled app that refers the same app config file. Possibly this can be addressed by the validation.

Which issue(s) this PR fixes:

Fixes #2803

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.05%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations 0.00% 0.00% +0.00%

Comment on lines 966 to 1001
opts := datastore.ListOptions{
// NOTE: Assume that no more than one application is referring to a single configuration file.
Limit: 1,
Filters: []datastore.ListFilter{
{
Field: "ProjectId",
Operator: datastore.OperatorEqual,
Value: projectID,
},
{
Field: "PipedId",
Operator: datastore.OperatorEqual,
Value: pipedID,
},
{
Field: "GitPath.Repo.Id",
Operator: datastore.OperatorEqual,
Value: appInfo.RepoId,
},
{
Field: "GitPath.Path",
Operator: datastore.OperatorEqual,
Value: appInfo.Path,
},
{
Field: "GitPath.ConfigFilename",
Operator: datastore.OperatorEqual,
Value: appInfo.ConfigFilename,
},
{
Field: "Disabled",
Operator: datastore.OperatorEqual,
Value: false,
},
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application ID can be included in the request by Piped to avoid this listing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to uniquely identify the application based on the RepoID, Path, and ConfigFilename, get the id, and cache it on the Piped side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I think since this is for updating the existing applications then Piped already knew their ID before sending this UpdateApplicationConfigurations request.

https://github.com/pipe-cd/pipe/blob/master/pkg/app/piped/appconfigreporter/appconfigreporter.go#L146
https://github.com/pipe-cd/pipe/blob/master/pkg/app/piped/appconfigreporter/appconfigreporter.go#L197

So I meant that we can add an application_id field to this https://github.com/pipe-cd/pipe/blob/master/pkg/model/common.proto#L59-L65 model or the RPC request to avoid re-finding each one on the server to update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More specifically, we can update this map to be a map from GitPathKey to AppID (make(map[string]string, len(apps)))

https://github.com/pipe-cd/pipe/blob/ce3e2b322cb5caef628d7ae7188396eb961beb7a/pkg/app/piped/appconfigreporter/appconfigreporter.go#L147

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds nice. I originally applied in this way this because I was trying to allow multiple applications to refer to a single config file, but now that the premise has changed, it seems better to identify them by ID.

@pipecd-bot pipecd-bot added size/L and removed size/M labels Nov 24, 2021
@nakabonne
Copy link
Member Author

@nghialv I reimplemented based on your suggestion!

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.85%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations 0.00% 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findRegisteredApps 90.91% 83.33% -7.58%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findUnregisteredApps 85.71% 91.30% +5.59%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAllFiles 95.00% -- -95.00%

_, _, _, err := rpcauth.ExtractPipedToken(ctx)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have appInfo.Id, better to validate if the updating application belongs to the requested piped as other RPCs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied at d22b018

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Consider bulk-updating multiple apps

https://github.com/pipe-cd/pipe/blob/d22b018e3240d3c39afa1deaf32973199664b845/pkg/app/api/grpcapi/piped_api.go#L970-L973

This was created by todo plugin since "TODO:" was found in d22b018 when #2830 was merged. cc: @nakabonne.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.85%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations 0.00% 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findRegisteredApps 90.91% 83.33% -7.58%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findUnregisteredApps 85.71% 91.30% +5.59%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAllFiles 95.00% -- -95.00%

@khanhtc1202
Copy link
Member

/lgtm

Comment on lines +212 to +216
// Scan all files because it seems to be the first commit since Piped starts.
apps := make([]*model.ApplicationInfo, 0)
err := fs.WalkDir(r.fileSystem, repo.GetPath(), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to ask, do we have any reason to not use that scanAllFiles function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nghialv I feel you. Actually we can use the original scanAllFiles() removed just now. But we have to retrieve appID from registeredAppPaths only if called by findRegisteredApps. It is not a shared helper function anymore. It was not too huge function and originally it has been received shouldSkip which makes us confused.
So I settled on writing a bit overlapping logic directly into each function.

@ono-max
Copy link
Member

ono-max commented Nov 24, 2021

/lgtm

@nghialv
Copy link
Member

nghialv commented Nov 24, 2021

Nice.
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nghialv.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the given application configurations

6 participants