Skip to content
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

feat: make docker compose startup time configurable #1166

Merged
merged 17 commits into from
Dec 10, 2023

Conversation

IllTamer
Copy link
Contributor

@IllTamer IllTamer commented Dec 1, 2023

Related Issue

  • Info about Issue or bug

Closes: #1065

Describe the changes you've made

Make docker compose startup time configurable for record, test and serve

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Please let us know if any test cases are added

Please describe the tests(if any). Provide instructions how its affecting the coverage.

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

A clear and concise description of it.

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

Original Updated
original screenshot image

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Copy link

github-actions bot commented Dec 1, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you and congratulations 🎉 for opening your very first pull request in keploy

@IllTamer
Copy link
Contributor Author

IllTamer commented Dec 1, 2023

I have read the CLA Document and I hereby sign the CLA

Copy link

sweep-ai bot commented Dec 1, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

cmd/record.go Outdated
@@ -206,6 +221,8 @@ func (r *Record) GetCmd() *cobra.Command {

recordCmd.Flags().Uint64P("delay", "d", 5, "User provided time to run its application")

recordCmd.Flags().Uint64P("buildDelay", "", 30, "User provided time to wait docker container build")
Copy link
Contributor

@EraKin575 EraKin575 Dec 2, 2023

Choose a reason for hiding this comment

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

time would be a better datatype for inputting delay. Some docker builds can take minutes to startup. You can input it like that using Duration. Please make sure to change it everywhere. You can refer this: https://pkg.go.dev/time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, thanks. I will change it latter 😃

Copy link
Contributor Author

@IllTamer IllTamer Dec 2, 2023

Choose a reason for hiding this comment

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

time would be a better datatype for inputting delay. Some docker builds can take minutes to startup. You can input it like that using Duration. Please make sure to change it everywhere. You can refer this: https://pkg.go.dev/time

Hey @EraKin575 , I want to set the type of buildDelay to string, so that we can use time.ParseDuration to parse the build time input by the user, such as "30s", "5m". Do you think this is a better idea than changing the type of buildDelay from uint64 to duration ?

The string type is only used to process user input. After initialization, the buildDelay variable will use the time.Duration type to participate in parameter transfer, time judgment and recording configuration.

I made a mistake, in fact, Flags#GetDuration automatically parses the time expression entered by the user like 30s, I mistakenly thought that it only accepts numeric type input. The modification has been completed, thank you for your help !

Copy link
Contributor

Choose a reason for hiding this comment

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

You won't be able to configure time like '30m5s'. Even if you do, that would be unnecessary complexity into this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You won't be able to configure time like '30m5s'. Even if you do, that would be unnecessary complexity into this

That's right, I'll go ahead and set the buildDelay type to time.Duration and specify the parameter's default unit to be seconds. Then I'll modify the relevant directive help

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
@EraKin575
Copy link
Contributor

Please update the screenshot too

cmd/serve.go Outdated
@@ -66,6 +67,13 @@ func (s *Serve) GetCmd() *cobra.Command {
return
}

buildDelay, err := cmd.Flags().GetDuration("buildDelay")
Copy link
Member

Choose a reason for hiding this comment

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

Right now, buildDelay is only limited to record and test command, please make the required changes.

Copy link
Member

Choose a reason for hiding this comment

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

@IllTamer Can we also use minute time unit in this flag? If yes please add an example of that also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will complete and modify later

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
cmd/test.go Outdated
@@ -229,6 +239,15 @@ func (t *Test) GetCmd() *cobra.Command {
}
}

if buildDelay <= time.Duration(30)*time.Second {
Copy link
Member

Choose a reason for hiding this comment

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

The same if check should be in the record command as well. And don't mention the example usage of record in the test command. It should be in the record command.

cmd/test.go Outdated
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
if isDockerCmd {
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --buildDelay 1m\n`)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Only mention test command usage here. And the port forwarding in the docker command should have port -p 8080:8080, please fix this if any other place also has this incorrect port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion, what does 'Only mention test command usage here. ' mean , Shall I remove the warning message 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I didn't notice. You don't need to remove the command or any warning message. Just fix the port forwarding.

@@ -43,7 +43,7 @@ func NewServer(logger *zap.Logger) Server {
const defaultPort = 6789

// Serve is called by the serve command and is used to run a graphql server, to run tests separately via apis.
func (s *server) Serve(path string, proxyPort uint32, testReportPath string, Delay uint64, pid, port uint32, lang string, passThroughPorts []uint, apiTimeout uint64, appCmd string) {
func (s *server) Serve(path string, proxyPort uint32, testReportPath string, Delay uint64, BuildDelay time.Duration, pid, port uint32, lang string, passThroughPorts []uint, apiTimeout uint64, appCmd string) {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove buildDelay flag from serve command, Because right not serve command is not supported for docker env.

@@ -61,7 +62,7 @@ func (r *mutationResolver) RunTestSet(ctx context.Context, testSet string) (*mod
go func() {
defer utils.HandlePanic()
r.Logger.Debug("starting testrun...", zap.Any("testSet", testSet))
tester.RunTestSet(testSet, testCasePath, testReportPath, "", "", "", delay, pid, ys, loadedHooks, testReportFS, testRunChan, r.ApiTimeout, ctx, nil, serveTest)
tester.RunTestSet(testSet, testCasePath, testReportPath, "", "", "", delay, buildDelay, pid, ys, loadedHooks, testReportFS, testRunChan, r.ApiTimeout, ctx, nil, serveTest)
Copy link
Member

Choose a reason for hiding this comment

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

Just pass some default value for buildDelay. Anyway, it will not be used in case of serve command. Because if it is a serve command then we don't even start the application by ourselves.

@gouravkrosx
Copy link
Member

gouravkrosx commented Dec 5, 2023

@IllTamer Please address the updated comments & also please update the template of the config file as well.

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
cmd/serve.go Outdated
@@ -66,6 +65,11 @@ func (s *Serve) GetCmd() *cobra.Command {
return
}

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this code since there is no build-delay in the serve command. So no need to check for this error.

}

if buildDelay <= 30*time.Second {
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
Copy link
Member

Choose a reason for hiding this comment

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

This warning should be printed only when there is docker command because we don't need the build-delay flag in case of native integration.

@gouravkrosx
Copy link
Member

gouravkrosx commented Dec 6, 2023

@IllTamer Please address the updated comments & resolve the merger conflicts, the rest looks good. And can I use a value like 1m40s in the build-delay flag

@AkashKumar7902
Copy link
Member

Hey @IllTamer
Please make a commit to this PR 280

@Sonichigo
Copy link
Member

@IllTamer can you pease resolve the issues and update the PR!

@IllTamer
Copy link
Contributor Author

IllTamer commented Dec 8, 2023

@IllTamer can you pease resolve the issues and update the PR!

There are some things that are delaying me. I will update as soon as possible. : )

@IllTamer
Copy link
Contributor Author

IllTamer commented Dec 8, 2023

Please address the updated comments & resolve the merger conflicts, the rest looks good. And can I use a value like 1m40s in the build-delay flag

Yes, you can. It depends on the Flags#GetDuration function of the cobra library, and this method relies on the implementation of the pflag library, so you can enter parameters such as 1m20s or 1m61s

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
@IllTamer
Copy link
Contributor Author

IllTamer commented Dec 8, 2023

Hey @IllTamer Please make a commit to this PR 280

Sorry, but I'm not sure how to submit in your PR, it says I don't have permission. You can directly add a buildDelay: 30s after the record and test command configuration items delay to complete the update.

cmd/test.go Outdated

if isDockerCmd && buildDelay <= 30*time.Second {
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
if isDockerCmd {
Copy link
Member

Choose a reason for hiding this comment

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

No need to check for isDockerCmd again.

cmd/test.go Outdated
if isDockerCmd && buildDelay <= 30*time.Second {
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
if isDockerCmd {
fmt.Println("Example usage:\n", `keploy test -c "docker-compose up --build" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker-compose up --build" --buildDelay 1m\n`)
} else {
fmt.Println("Example usage:\n", cmd.Example)
Copy link
Member

Choose a reason for hiding this comment

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

Since this buildDelay flag is only in the case of the docker command, there is no need to add this example here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this buildDelay flag is only in the case of the docker command, there is no need to add this example here.

By default, do we assume that the docker environment is built when the user uses the record command? Do we consider the situation where the user needs to rebuild when running the test command? Then the buildDelay parameter still needs to be checked

Copy link
Member

Choose a reason for hiding this comment

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

@IllTamer Whenever there is a docker env the isDockerCmd is true since the keploy Dockerfile contains this as an environment variable. So if you've checked that it is dockerCmd & the buildDelay is <=30 then just show the warning as the usage rather than showing another example.

@gouravkrosx
Copy link
Member

@IllTamer Please resolve the merge conflicts and address the updated comments.

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
@gouravkrosx
Copy link
Member

@IllTamer Please resolve the merger conflicts.

cmd/record.go Outdated
@@ -172,6 +182,15 @@ func (r *Record) GetCmd() *cobra.Command {
// user provided the absolute path
}

if buildDelay <= 30*time.Second {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the other example here also. And have you tested your changes with the config file as well?

@gouravkrosx
Copy link
Member

@IllTamer The build is failing, please fix that.

Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Copy link
Member

@gouravkrosx gouravkrosx left a comment

Choose a reason for hiding this comment

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

🚀

@gouravkrosx gouravkrosx merged commit b623c2a into keploy:main Dec 10, 2023
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Make docker compose startup time configurable
5 participants