Skip to content

Conversation

@nakabonne
Copy link
Member

@nakabonne nakabonne commented Nov 10, 2021

What this PR does / why we need it:
This PR adds a new Piped component that primarily watches two types of Applications that is:

  • already registered
  • unregistered

For the first one (already registered):

  • Piped sends only configs that have been changed since then
  • Contol-plane updates Applications stored in Datastore

For the second one (unregistered):

  • Piped sends all the latest configs every time whatever the repo is changed or not. The reason is the cache in control-plane is likely to be removed, and configs in Git is also likely to be removed
  • Control-plane caches them for suggesting when you attempt to add a new Application

Once this gets merged, I will drill into the detailed implementation.

Which issue(s) this PR fixes:

Fixes #2755
Ref #2772
Ref #2750

Does this PR introduce a user-facing change?:

NONE

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.08%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.PutUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

Comment on lines 123 to 134
func (r *Reporter) checkApps(ctx context.Context) (err error) {
if len(r.gitRepos) == 0 {
r.logger.Info("no repositories were configured for this piped")
return
}

var (
unusedApps = make([]*pipedservice.ApplicationConfiguration, 0)
appsToBeUpdated = make([]*pipedservice.ApplicationConfiguration, 0)
appsMap = r.listApplications()
)
for repoID, repo := range r.gitRepos {
Copy link
Member

Choose a reason for hiding this comment

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

We can break this function to be simpler ones. For example

func scan(cox context.Context) error 
  for _, repo := range r.gitRepos {
     // 1. Fetch to update the local data of each repo to ensure they are up-to-date.
     // 2. Continue if there was no newly added commits.
     // 3. shouldScanRepos = append(shouldScanRepos, repo)
  }

  for _, repo := range shouldScanRepos {
     if err := scanRepo(cox context.Context, repo, previousHash, currentHash); err == nil {
        // mark the new hash to the map
     }
  }
}

func scanRepo(ctx context.Context, repo Repo, previousHash, currentHash string) error {
   ...
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Obviously more readable than before

Copy link
Member Author

Choose a reason for hiding this comment

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

But to be honest, since we need to send all unregisteredApps each time, we have to scan all repositories anyway.

Copy link
Member Author

@nakabonne nakabonne Nov 11, 2021

Choose a reason for hiding this comment

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

Piped sends all the latest configs every time whatever the repo is changed or not. The reason is the cache in control-plane is likely to be removed, and configs in Git is also likely to be removed

As mentioned in the PR description, I'm looking to letting Piped send all the latest configs every time whatever the repo is changed or not. The reasons are:

  • Even if there are no new commits to the repository, but the Control-plane cache may have already been removed.
  • If you send only the configuration to be updated, you can't address the case that the file itself is deleted from the repo.

What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

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

I get your points.

Checking by the diff still be valid in those cases. Scanning the full repository can be done for only the first time and then just the diff from the second time. Of course, we should send the full list of "un-registered" ones and the changed "registered" ones to the control-plane.

About the deleted files I think we can ignore them since app deletion only be allowed from web.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you mean to separate updating the repository from reading the files. Cool, I have no objection.

About the deleted files I think we can ignore them since app deletion only be allowed from web.

Sorry for confusing you. I was afraid that even though the files of unregistered applications were deleted, they were still in the cache and would be suggested when registering an application.

Copy link
Member

Choose a reason for hiding this comment

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

I was afraid that even though the files of unregistered applications were deleted, they were still in the cache and would be suggested when registering an application.

After having the list of changed files, we still have to read their content to get app_name, kind... So we can know that case at parsing time to handle as normal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, my words were possibly not enough. I was talking about unregistered applications.
Could you tell me about your thoughts on always sending ALL unregistered apps each time?

Copy link
Member

Choose a reason for hiding this comment

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

Could you tell me about your thoughts on always sending ALL unregistered apps each time?

Yes, I think that is ok, we have to send the full list of unregistered apps because they are saved in the cache.
We are on the same page about that topic.

Comment on lines 164 to 168
for _, app := range apps {
gitPath := app.GetGitPath()
_ = filepath.Join(repo.GetPath(), gitPath.Path, gitPath.ConfigFilename)
// TODO: Collect applications that need to be updated
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of iterate apps to check like this, we can use git diff previousHash currentHash --name-only to have a list of changed files. And then find the updated ones and un-registered ones based on that list.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to parse and inspect the application configs was changed to avoid unneeded communication. But yours seems to be enough.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.08%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

Comment on lines 123 to 134
func (r *Reporter) checkApps(ctx context.Context) (err error) {
if len(r.gitRepos) == 0 {
r.logger.Info("no repositories were configured for this piped")
return
}

var (
unusedApps = make([]*pipedservice.ApplicationConfiguration, 0)
appsToBeUpdated = make([]*pipedservice.ApplicationConfiguration, 0)
appsMap = r.listApplications()
)
for repoID, repo := range r.gitRepos {
Copy link
Member

Choose a reason for hiding this comment

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

I get your points.

Checking by the diff still be valid in those cases. Scanning the full repository can be done for only the first time and then just the diff from the second time. Of course, we should send the full list of "un-registered" ones and the changed "registered" ones to the control-plane.

About the deleted files I think we can ignore them since app deletion only be allowed from web.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.08%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

}

// BuildGitPathID builds a unique path between repositories.
func BuildGitPathID(repoID, path, configFileName string) string {
Copy link
Member Author

Choose a reason for hiding this comment

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

I just want to look into if the application is registered, using GitPath. I'm still wondering if we can do that in other ways.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.08%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/common.go BuildGitPathID -- 0.00% +0.00%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

@nakabonne
Copy link
Member Author

@nghialv I am very grateful for your careful confirmation. Based on your suggestion, I replaced the part that used to be the TODO comment with the implementation that actually updates it.

It's not exactly what you suggested, but I would say it's more readable than before. Please take a look at it when you have time.

@nghialv
Copy link
Member

nghialv commented Nov 11, 2021

It's not exactly what you suggested, but I would say it's more readable than before. Please take a look at it when you have time.

Sure. Let me check it.


type GenericDeploymentSpec struct {
Name string `json:"name"`
EnvID string `json:"env_id"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
EnvID string `json:"env_id"`
EnvID string `json:"envId"`

Copy link
Member

Choose a reason for hiding this comment

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

Btw, isn't the name better than the id?

Copy link
Member Author

@nakabonne nakabonne Nov 12, 2021

Choose a reason for hiding this comment

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

I was worried about the uniqueness of env_name but let's leave it to the user to maintain the uniqueness.

It's obvious that the application name shouldn't be unique, but ideally the env name should be unique because Environment is a project-wide concept.
To do that with a document-oriented database, we need to prepare some kind of extra table with the name like envname to ensure uniqueness.

But we're planning to migrate Env to Labels in the future, again, for now let's leave it to the user to maintain the uniqueness.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we proceed with the Name as non-unique, we will have to add a not neat method to environmentstore. I'd like to hear your opinion on uniqueness before implementing it.

@nghialv
Copy link
Member

nghialv commented Nov 11, 2021

Nice. It became more readable.
I have just left some nits but I am still reviewing this pull request.
And let me rewrite my suggestion this evening.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.08%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/common.go BuildGitPathID -- 0.00% +0.00%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

Comment on lines 321 to 330
func shouldSkip(repoID, cfgFilePath string, registeredAppPaths map[string]struct{}, wantRegistered bool) bool {
if !strings.HasSuffix(cfgFilePath, model.DefaultDeploymentConfigFileExtension) {
return true
}
gitPathKey := makeGitPathKey(repoID, cfgFilePath)
if _, registered := registeredAppPaths[gitPathKey]; registered != wantRegistered {
return true
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

How about removing this function and using its code directly?
Because handling for both "registered" and "unregistered" cases makes it harder to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. It should not be made common.

apps = append(apps, as...)
}
if len(apps) == 0 {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Do you think that we should send this empty list to the control plane to delete the cache?

Copy link
Member

Choose a reason for hiding this comment

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

Or we can have a simple mark in this Reporter to avoid sending continuous this kind of request.

Copy link
Member Author

Choose a reason for hiding this comment

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

To avoid sending meaningless requests simply, I applied this way. Cache in Control-plane gets periodically removed, so I thought it's fine. But it's worth considering.

@nakabonne
Copy link
Member Author

@nghialv Revised!

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.16%. This pull request increases coverage by 0.05%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/apistore/environmentstore/store.go Store.GetByName -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go fileSystem.Open -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go NewReporter -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.Run -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAppConfigs -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateRegisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findRegisteredApps -- 90.00% +90.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateUnregisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findUnregisteredApps -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAllFiles -- 91.30% +91.30%
pkg/app/piped/appconfigreporter/appconfigreporter.go makeGitPathKey -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.readApplicationInfo -- 76.92% +76.92%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/config.go Config.UnmarshalJSON 83.33% 91.67% +8.33%
pkg/config/config.go Config.GetGenericDeployment 0.00% 28.57% +28.57%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/config/config.go DecodeYAML 72.73% 81.82% +9.09%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

Copy link
Member

@nghialv nghialv left a comment

Choose a reason for hiding this comment

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

Finished my review. Just some nits. 👍

logger *zap.Logger

// Whether it already swept all unregistered apps from control-plane.
// Not goroutine safe.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this kind of comment since we are not spawning any new goroutines in this package?

Copy link
Member Author

@nakabonne nakabonne Nov 18, 2021

Choose a reason for hiding this comment

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

I just left these comments for when we need to spawn multiple goroutines for performance improvement in the future because file reading is embarrassingly parallel. But if you think about it, they aren't used for that reading part. It's completely YAGNI👍

Comment on lines 310 to 312
if !strings.HasSuffix(cfgRelPath, model.DefaultDeploymentConfigFileExtension) {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: We can move this to before line 305 and use path to check the extension. It will reduce a lot of unnecessary filepath.Rel calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch

@nakabonne
Copy link
Member Author

@nghialv Fixed

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.16%. This pull request increases coverage by 0.05%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/apistore/environmentstore/store.go Store.GetByName -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go fileSystem.Open -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go NewReporter -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.Run -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAppConfigs -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateRegisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findRegisteredApps -- 90.00% +90.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateUnregisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findUnregisteredApps -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAllFiles -- 91.30% +91.30%
pkg/app/piped/appconfigreporter/appconfigreporter.go makeGitPathKey -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.readApplicationInfo -- 76.92% +76.92%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/config/config.go Config.UnmarshalJSON 83.33% 91.67% +8.33%
pkg/config/config.go DecodeYAML 72.73% 81.82% +9.09%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/config.go Config.GetGenericDeployment 0.00% 28.57% +28.57%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

@nghialv
Copy link
Member

nghialv commented Nov 18, 2021

Looks good! Go ahead.
/lgtm

@pipecd-bot pipecd-bot removed the lgtm label Nov 19, 2021
@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. Update the given application configurations

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/api/grpcapi/piped_api.go#L937-L940

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

2. Make the unused application configurations cache up-to-date

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/api/grpcapi/piped_api.go#L942-L945

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

3. Implement environmentstore.GetByName

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/piped/apistore/environmentstore/store.go#L104-L107

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

4. Return an error if any one of required field of Application is empty

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/piped/appconfigreporter/appconfigreporter.go#L360-L363

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

5. Convert Kind string into dedicated type

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/piped/appconfigreporter/appconfigreporter.go#L363-L366

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

6. Consider changing the default application config name

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/model/application.go#L24-L27

This was created by todo plugin since "TODO:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

7. Think about sync interval of app config reporter

https://github.com/pipe-cd/pipe/blob/5ec2cbbcbfd8d3fb6e1fa8a4cfa5cb81cc298ceb/pkg/app/piped/appconfigreporter/appconfigreporter.go#L117-L120

This was created by todo plugin since "FIXME:" was found in 5ec2cbb when #2772 was merged. cc: @nakabonne.

@nakabonne
Copy link
Member Author

I just added a TODO comment

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.16%. This pull request increases coverage by 0.05%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.UpdateApplicationConfigurations -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ReportUnregisteredApplicationConfigurations -- 0.00% +0.00%
pkg/app/piped/apistore/environmentstore/store.go Store.GetByName -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go fileSystem.Open -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go NewReporter -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.Run -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAppConfigs -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateRegisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findRegisteredApps -- 90.00% +90.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.updateUnregisteredApps -- 0.00% +0.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.findUnregisteredApps -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.scanAllFiles -- 91.30% +91.30%
pkg/app/piped/appconfigreporter/appconfigreporter.go makeGitPathKey -- 100.00% +100.00%
pkg/app/piped/appconfigreporter/appconfigreporter.go Reporter.readApplicationInfo -- 76.92% +76.92%
pkg/app/piped/cloudprovider/terraform/terraform.go WithAdditionalEnvs -- 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.shouldTriggerOnCommit -- 0.00% +0.00%
pkg/model/application.go Application.ContainLabels -- 77.78% +77.78%
pkg/model/deployment.go Deployment.ContainLabels -- 77.78% +77.78%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%
pkg/app/piped/trigger/determiner.go Determiner.ShouldTrigger 0.00% 0.00% +0.00%
pkg/config/config.go DecodeYAML 72.73% 81.82% +9.09%
pkg/config/deployment.go PipelineStage.UnmarshalJSON 34.15% 40.24% +6.10%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/launcher/cmd/launcher/binary.go command.GracefulStop 66.67% 100.00% +33.33%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Version 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.SelectWorkspace 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/config/config.go Config.UnmarshalJSON 83.33% 91.67% +8.33%
pkg/config/config.go Config.GetGenericDeployment 0.00% 28.57% +28.57%
pkg/app/api/grpcapi/web_api.go WebAPI.UpdateApplication 0.00% 0.00% +0.00%
pkg/model/application.go Application.ContainTags 88.89% -- -88.89%
pkg/model/deployment.go Deployment.ContainTags 88.89% -- -88.89%

@khanhtc1202
Copy link
Member

Way to go 🚀
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

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.

Add an rpc to update application info based on one defined in the application config

5 participants