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

Added a timer goroutine to run for a specific duration and upon expir… #1519

Merged
merged 9 commits into from
Feb 15, 2024

Conversation

heyyakash
Copy link
Contributor

…ation sends an os.Interrupt signal which shuts down the recorder and exits the program

Related Issue

Closes: #1434

Describe the changes you've made

  • Added a timer (-t) flag (eg. -t 50s) to record cmd which takes the input for the time for which the user wants the recorder to run and defaults to 0 if none is provided.
  • Added a timer goroutine in captureTraffic() in record.go file that initiates the timer just before user application is launched and once the timer is up sends os.Interrupt signal to stopper channel to gracefully stop the recorder.
  • If the value of timer is 0 (default value) the timer won't run and the recorder can run as long as user wants.

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.
NA

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
Screenshot from 2024-02-03 00-44-32 Screenshot from 2024-02-03 00-45-22

…ation sends an os.Interrupt signal which shuts down the recorder and exits the program

Signed-off-by: heyyakash <akashsharma2002@gmail.com>
@heyyakash
Copy link
Contributor Author

@PranshuSrivastava had to force push to match my local branch to original branch and that led to closing of previous pr. Can you review this one instead

cmd/record.go Outdated
@@ -42,7 +42,7 @@ func readRecordConfig(configPath string) (*models.Record, error) {

var filters = models.TestFilter{}

func (t *Record) GetRecordConfig(path *string, proxyPort *uint32, appCmd *string, appContainer, networkName *string, Delay *uint64, buildDelay *time.Duration, passThroughPorts *[]uint, passThrough *[]models.Filters, configPath string) error {
func (t *Record) GetRecordConfig(path *string, proxyPort *uint32, appCmd *string, appContainer, networkName *string, Delay *uint64, buildDelay *time.Duration, passThroughPorts *[]uint, passThrough *[]models.Filters, configPath string, keployRecorderStopTimer *time.Duration) error {
Copy link
Member

Choose a reason for hiding this comment

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

This name is too long. Just keep it something simple like "recordTimer"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

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

recordCmd.Flags().StringP("command", "c", "", "Command to start the user application")

recordCmd.Flags().DurationP("keployRecorderStopTimer", "t", 0, "Command to initiate a timer that automatically stops the Keploy recorder after a specified duration of time")
Copy link
Member

Choose a reason for hiding this comment

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

Make this also into something briefer like "timer to stop keploy record after the required time".

@heyyakash
Copy link
Contributor Author

@PranshuSrivastava I've made the changes, please check

Copy link
Member

@PranshuSrivastava PranshuSrivastava left a comment

Choose a reason for hiding this comment

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

I've tested your changes, they work as intended, just make the following changes.

timer := time.After(recordTimer)
select {
case <-timer:
r.Logger.Warn("Time up! Stopping the timer")
Copy link
Member

Choose a reason for hiding this comment

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

we are stopping keploy not the timer.

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

recordCmd.Flags().StringP("command", "c", "", "Command to start the user application")

recordCmd.Flags().DurationP("recordTimer", "t", 0, "Timer to stop keploy recorder after a specified time")
Copy link
Member

Choose a reason for hiding this comment

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

why is the shorthand of the flag -t? That can confuse the user, either start the name with t or change the shorthand to the first alphabet of the full flag name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heyy! so i removed the shorthand entirely and kept it as --recordTimer , keeping the shorthand as -r would lead to ambiguity, So please check

Signed-off-by: heyyakash <akashsharma2002@gmail.com>
@heyyakash
Copy link
Contributor Author

@PranshuSrivastava can you please review the new changes?

@@ -308,7 +308,7 @@ func (r *Record) GetCmd() *cobra.Command {

recordCmd.Flags().StringP("command", "c", "", "Command to start the user application")

recordCmd.Flags().DurationP("recordTimer", "t", 0, "Timer to stop keploy recorder after a specified time")
recordCmd.Flags().Duration("recordTimer", 0, "Timer to stop keploy recorder after a specified time")
Copy link
Member

Choose a reason for hiding this comment

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

Why have you removed the code for reading this flag?

Copy link
Contributor Author

@heyyakash heyyakash Feb 11, 2024

Choose a reason for hiding this comment

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

heyy! so i removed the shorthand entirely and kept it as --recordTimer , keeping the shorthand as -r would lead to ambiguity,

Copy link
Member

@PranshuSrivastava PranshuSrivastava left a comment

Choose a reason for hiding this comment

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

LGTM

@heyyakash
Copy link
Contributor Author

@PranshuSrivastava can you merge then?

@PranshuSrivastava PranshuSrivastava merged commit 80d9f7f into keploy:main Feb 15, 2024
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 15, 2024
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.

Add a timer to the keploy recorder
2 participants