-
-
Notifications
You must be signed in to change notification settings - Fork 376
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: new experience to get coverage report #1785
base: main
Are you sure you want to change the base?
feat: new experience to get coverage report #1785
Conversation
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
…nge NYC_CLEAN to CLEAN Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
…nction Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
bb312ab
to
450052a
Compare
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
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.
Please address the comments, I haven't yet reviewed complete logic but these are the initial comments.
cli/provider/cmd.go
Outdated
@@ -214,12 +214,12 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command) error { | |||
cmd.Flags().Uint64("apiTimeout", c.cfg.Test.APITimeout, "User provided timeout for calling its application") | |||
cmd.Flags().String("mongoPassword", c.cfg.Test.MongoPassword, "Authentication password for mocking MongoDB conn") | |||
cmd.Flags().String("coverageReportPath", c.cfg.Test.CoverageReportPath, "Write a go coverage profile to the file in the given directory.") | |||
cmd.Flags().StringP("language", "l", c.cfg.Test.Language, "application programming language") | |||
cmd.Flags().StringP("language", "l", c.cfg.Test.Language, "Application programming language") |
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.
attaching to enum, I mean only few values should be allowed like GO, PYTHON etc and provide example in the comment.
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.
https://github.com/thediveo/enumflag
should I use this library for enum ?
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.
see how others do it in the case of cobra tool.
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.
may be something like allowed values may be list of string.
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.
Like any of these languages should be allowed if user provides other value. It should prompt that only these values will be allowed
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.
done!
cli/provider/cmd.go
Outdated
if cmd.Name() == "record" { | ||
c.cfg.Test.SkipCoverage = true | ||
} | ||
if c.cfg.Test.Language == "python" && !c.cfg.Test.SkipCoverage { |
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.
use switch condition rather than if statements. define language as an enum if needed.
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.
done!
pkg/graph/schema.resolvers.go
Outdated
@@ -128,7 +128,7 @@ func (r *queryResolver) TestSetStatus(ctx context.Context, testRunID string, tes | |||
} | |||
|
|||
// StopApp is the resolver for the stopApp field. | |||
func (r *mutationResolver) StopApp(_ context.Context, appId int) (bool, error) { | |||
func (r *mutationResolver) StopApp(ctx context.Context, appId int) (bool, error) { |
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.
remove graphql support as it is not used
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.
should I remove the entire pkg/graph folder ?
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.
yes
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.
done
pkg/service/replay/replay.go
Outdated
@@ -118,16 +125,47 @@ func (r *Replayer) Start(ctx context.Context) error { | |||
return fmt.Errorf(stopReason) | |||
} | |||
|
|||
if !r.config.Test.SkipCoverage && r.config.Test.Language == "typescript" { |
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.
why is this done twice..?
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.
You can add clean, append and testset envs irrespective to languages.
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.
this is because first clean must be set to true to clean up previous coverage data and then after first test-set has completed execution clean would be set to false
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.
A quick solution would be to not append --clean=${CLEAN} in cli/provider/cmd.go and append it in replay.go when we are setting clean env to false(like --clean=false, no need to set env also), but it won't work because command gets saved to app struct through NewApp func invocation. should I implement an updateCmd function in app.go to clean up this code from replay.go ?
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.
No what I am telling is this condition r.config.Test.Language == "typescript"
is not required. You can just do it by default without condition, even the test-set name env.
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.
done!
pkg/service/tools/coverage.go
Outdated
"go.keploy.io/server/v2/pkg/models" | ||
) | ||
|
||
func CalGoCoverage() (models.TestCoverage, error) { |
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.
why are these in tools service.?
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.
coverage calculation by analyzing the raw coverage files may be viewed as a tool, thats why I put it here, do you want to move it to a different place ?
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.
move it into utils in test service
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.
done!
Please resolve the pipeline failure too. |
> move coverage.go from tools to service/replay pkg > define enum for language flag > refactored code Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
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.
Please address the comments
language, executable := utils.DetectLanguage(logger, conf.Command) | ||
// if language is not provided through flag/config and language detected is not unknown | ||
// then set the language to detected language | ||
if conf.Test.Language == "" { |
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.
I think if language is specified we need to find executable according to the language again is what I feel. Lets take the case of node. If I specified language as python and command I gave is npm, then you will consider executable as npm and change it to cover right. Try clean this approach a bit and try all possible things and also if something is missing log a warn message.
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.
does this language detected through keploy should be given more preference over user passed language
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.
no Want I mean is if language given and language parsed is not same we should give an error
cli/provider/cmd.go
Outdated
logger.Warn("coverage tool not found. please install coverage tool using 'pip install coverage'") | ||
} else { | ||
utils.CreatePyCoverageConfig(logger) | ||
conf.Command = strings.Replace(conf.Command, executable, "coverage run $APPEND --data-file=.coverage.keploy", 1) |
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.
don't replace it with conf.command may be create another element conf.coverageCommand and then use it. Because we will or may log the command in the test service then We dont want to show this new command. We need to show the old command.
cli/test.go
Outdated
|
||
cmdType := utils.FindDockerCmd(cfg.Command) | ||
if cmdType == utils.Native && cfg.Test.GoCoverage { | ||
if cmdType == utils.Native && !cfg.Test.SkipCoverage { |
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.
why do we need this GOCOVERDIR here..? cant we do this in preprocessing..?
pkg/service/replay/replay.go
Outdated
} | ||
} | ||
|
||
jacocoPath := "" |
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.
you can do this in preprocess right..?
@@ -117,17 +117,47 @@ func (r *Replayer) Start(ctx context.Context) error { | |||
} | |||
return fmt.Errorf(stopReason) | |||
} | |||
if !r.config.Test.SkipCoverage { |
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.
if there is an error in the preprocessing or detecting language just make skipCoverage = true
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.
I believe the code part referenced here is doing the same
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.
yeah I was just reminding to do it everywhere even in preprocess function.
pkg/service/replay/replay.go
Outdated
} | ||
|
||
jacocoPath := "" | ||
if r.config.Test.Language == models.Java && !r.config.Test.SkipCoverage { |
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.
we should do this only if the jacoco jar is not present in the path we set or the path which user has specified right..?
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.
if we want jacoco commands to be ran directly not with mvn, we must use jacoco cli, jacoco cli can't be downloaded through regular dependencies in pom.xml (as its not a dependency, but rather a package)
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.
oh ok I thought it was jacoco agent jar
} | ||
} | ||
} | ||
if !r.config.Test.SkipCoverage && r.config.Test.Language == models.Java { |
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.
we can do this after all test-sets are done running at the end.
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.
currently its at the end of test set iteration for loop so all the tests are ran, before merge and report commands are run.
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.
ok
pkg/service/replay/replay.go
Outdated
@@ -634,7 +694,7 @@ func (r *Replayer) printSummary(ctx context.Context, testRunResult bool) { | |||
} | |||
r.logger.Info("test run completed", zap.Bool("passed overall", testRunResult)) | |||
|
|||
if utils.CmdType(r.config.CommandType) == utils.Native && r.config.Test.GoCoverage { | |||
if utils.CmdType(r.config.CommandType) == utils.Native && !r.config.Test.SkipCoverage && r.config.Test.Language == models.Go { |
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.
we can remove this as we are already storing the coverage in report.
// Specify the output file | ||
args = append(args, "--destfile", "target/keploy-e2e.exec") | ||
|
||
cmd := exec.CommandContext(ctx, args[0], args[1:]...) |
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.
make sure we dont show these logs to user, because all we want for them to see is application and keploy logs may be print them as debug logs
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.
should I change all current error logs introduced in this PR which are related to coverage thing to Warn ?
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.
yes and the success logs should not be shown like if you are mergin the jacoco exec files I dont want user to see the logs because they are irrelevant to the user.
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.
Should I print a warn statement saying to check debug logs if skipcoverage is set to true by keploy?
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.
No if there is an error in any coverage related thing log that as warn and if there is any logs from the commands you are running like jaoco merge or report dont show the logs to user log them as debug thats it
> change error logs of coverage related tasks to warn, and error logs of coverage tool to debug > refactor > don't change command instead created a new field in config struct named CoverageCommand in which command prepended with coverage tool is put > log error if language detected doesn't match with language provided Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Related Issue
Closes: #1735
Describe the changes you've made
Add coverage data to test report
coverage data will be appended for applications written in:
Type of change
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:
Screenshots (if any)