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: new experience to get coverage report #1785

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

AkashKumar7902
Copy link
Member

@AkashKumar7902 AkashKumar7902 commented Apr 6, 2024

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:

  • golang
  • node
  • python
  • java

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 updated screenshot

Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@AkashKumar7902 AkashKumar7902 marked this pull request as draft April 6, 2024 13:32
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>
@AkashKumar7902 AkashKumar7902 changed the title feat: add coverage data for go in report feat: add coverage data in report Apr 7, 2024
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@AkashKumar7902 AkashKumar7902 marked this pull request as ready for review April 10, 2024 19:22
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
AkashKumar7902 and others added 11 commits April 15, 2024 13:27
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>
@AkashKumar7902 AkashKumar7902 changed the title feat: add coverage data in report feat: new experience to get coverage report May 15, 2024
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>
AkashKumar7902 and others added 4 commits May 20, 2024 15:41
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a 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.

@@ -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")
Copy link
Member

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.

Copy link
Member Author

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 ?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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 Show resolved Hide resolved
cli/provider/cmd.go Outdated Show resolved Hide resolved
cli/provider/cmd.go Outdated Show resolved Hide resolved
if cmd.Name() == "record" {
c.cfg.Test.SkipCoverage = true
}
if c.cfg.Test.Language == "python" && !c.cfg.Test.SkipCoverage {
Copy link
Member

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.

Copy link
Member Author

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 Show resolved Hide resolved
@@ -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) {
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -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" {
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 this done twice..?

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 add clean, append and testset envs irrespective to languages.

Copy link
Member Author

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

Copy link
Member Author

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 ?

Copy link
Member

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.

Copy link
Member Author

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 Show resolved Hide resolved
"go.keploy.io/server/v2/pkg/models"
)

func CalGoCoverage() (models.TestCoverage, error) {
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@charankamarapu
Copy link
Member

charankamarapu commented May 20, 2024

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>
Copy link
Member

@charankamarapu charankamarapu left a 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 == "" {
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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

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)
Copy link
Member

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 {
Copy link
Member

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

}
}

jacocoPath := ""
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 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 {
Copy link
Member

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

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 believe the code part referenced here is doing the same

Copy link
Member

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.

}

jacocoPath := ""
if r.config.Test.Language == models.Java && !r.config.Test.SkipCoverage {
Copy link
Member

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

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 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)

Copy link
Member

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 {
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 do this after all test-sets are done running at the end.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

ok

@@ -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 {
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 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:]...)
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: Add code coverage data to keploy test report
2 participants