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

Fixed Summary Generated Events #3730

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ameetpal
Copy link
Contributor

@ameetpal ameetpal commented May 2, 2024

What?

This PR fixes the shortcomings of TestSummaryGenerated Event :- #3682

Why?

The previously added TestSummaryGenerated had data in the form of a map with keys of type string and values of type io.Reader, however, the stream had already been read by stdout. Additionally, the data was formatted for console output, which was not consistent with what was expected by the handleSummary function of the test. Therefore, I returned the exact summary passed into the function and sent it as an event.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

@ameetpal ameetpal requested a review from a team as a code owner May 2, 2024 12:44
@ameetpal ameetpal requested review from codebien and olegbespalov and removed request for a team May 2, 2024 12:44
olegbespalov
olegbespalov previously approved these changes May 3, 2024
Copy link
Collaborator

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

LGTM

@codebien and maybe @grafana/k6-core we might consider adding this into upcoming release

@olegbespalov
Copy link
Collaborator

Hey @ameetpal. After an internal discussion, we decided to revert to the original changes to reduce it from the scope of the upcoming release #3736 (since they will change). In the next v0.51, we could continue working on that PR. In any case, thank you for your contributions!

@olegbespalov olegbespalov self-requested a review May 9, 2024 13:49
@olegbespalov
Copy link
Collaborator

Hey @ameetpal

We did release the k6 v0.51. Could you please rebase this PR using the latest master branch? Also, out of curiosity, this version of the changes satisfies your needs, right?

@olegbespalov olegbespalov added the awaiting user waiting for user to respond label May 15, 2024
@ameetpal
Copy link
Contributor Author

ameetpal commented May 16, 2024

Hey @olegbespalov , i have updated the branch, some random tests are failing, but are not related to my changes
Yes these changes are correct

olegbespalov
olegbespalov previously approved these changes May 21, 2024
Copy link
Collaborator

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 Thanks for the contribution!

@olegbespalov olegbespalov added this to the v0.52.0 milestone May 21, 2024
@olegbespalov olegbespalov removed the awaiting user waiting for user to respond label May 21, 2024
@ameetpal
Copy link
Contributor Author

@codebien can you please provide your review

@olegbespalov olegbespalov linked an issue May 21, 2024 that may be closed by this pull request
Copy link
Collaborator

@codebien codebien left a comment

Choose a reason for hiding this comment

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

As we are changing one of the most important interfaces of the tool, we should add:

  1. At least a test in js/summary_test.go testing the returned map
  2. Document the new add returned type on the HandleSummary method clarifying the keys and values to expect.
@ameetpal
Copy link
Contributor Author

@codebien I have added a test for jsSummary.
Also i have documented HandleSummary function but i have not added detailed keys and values as it may change based on a test and also boader key can change in future in runner function which will result in stale comment.
If you still want, i can add comment to current keys that are being returned.

@olegbespalov
Copy link
Collaborator

@ameetpal, out of curiosity, do the changes from this PR cover your case from #3732? I mean, have you tested everything assembled? I'm asking since we'd like to be sure that this PR serves the real needs

@codebien
Copy link
Collaborator

codebien commented May 28, 2024

@ameetpal to exapand a bit @olegbespalov's request. Can you also clarify if this pull request is going to solve #3732 for you?

Can you also explain a bit more about how you intend to use it, please? So, in the case we decide to document this feature, we could use your use case as an example in the documentation. Or, we can have it here just as historical information in case someone in the future needs to investigate more on why we decided to introduce this event.

@ameetpal
Copy link
Contributor Author

Hey @olegbespalov , @codebien , as of now i will consume this event in the new extension that i am working on. I was thinking of some way to include extension without explicitly importing this in test script but since this is not an option now, we will ask user to import our extension in the test script. I have tested this in local, and that is why i have raised this PR, since i was getting empty data in extension from the changes in my previous PR. Currently this is the only feasible method we find to solve our problem.

@ameetpal
Copy link
Contributor Author

Also, if we are able to use this successfuly, in future we might flow out other events like TestStarted. For auditing purposes.

require.NotNil(t, result["rawdata.json"])
newRawData, err := io.ReadAll(result["rawdata.json"])
require.NoError(t, err)
assert.JSONEq(t, string(newRawData), string(jsonString))
Copy link
Collaborator

@codebien codebien May 31, 2024

Choose a reason for hiding this comment

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

Hi @ameetpal,
thanks again for your contribution! 🙇

As you are asserting here, they are mostly the same. So, what is the reason for having them in different variables? Can you explain better it, please?

Ideally, we should try to not change the Runner interface, because it is an abstraction and it is a very central component.

If the current map[string]io.Reader is not the ideal type and we need to change it, we can create a function in js package that accepts this type and returns the type you need. Or, probably, even better to do it directly where we are generating the event so in cmd package.

Copy link
Contributor Author

@ameetpal ameetpal Jun 3, 2024

Choose a reason for hiding this comment

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

@codebien
Both are same in test as i want to get the data supplied to handleSummary function in test script file.

map[string]io.Reader, contains stdout related data which can only be read once. Also we can use this read also, but we need to write a converter function that will return the json data from which it was created.

If you want i can look into that approach also

@ameetpal
Copy link
Contributor Author

ameetpal commented Jun 5, 2024

@codebien any updates here ?

@codebien
Copy link
Collaborator

codebien commented Jun 6, 2024

Hi @ameetpal,
I and @olegbespalov met and synced on this pull request.

The current approach doesn't seem to be ideal, because it creates a dependency with an internal API. The current submitted changes rely upon a map[] structure designed internally to the js package. It mostly prepares the structure to serialize the Summary as a JSON. It is used from --summary-export feature, which is already a deprecated part of k6 that we might change in the future.

Instead, a more solid option could be to export lib.Summary type as Data field for the event emitted. In that way, you can create directly in your extension the best structure for your use case. lib.Summary is the type currently passed through HandleSummary and it is already under a shared package (lib).

k6/cmd/run.go

Line 195 in f57dc2f

summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, &lib.Summary{

Does this proposal still solve your problem?

@joanlopez
Copy link
Contributor

Moving to https://github.com/grafana/k6/milestone/42 since there's no news since a while.

@joanlopez joanlopez modified the milestones: v0.52.0, v0.53.0 Jun 17, 2024
@codebien
Copy link
Collaborator

Hey @ameetpal, do you have any news on the suggested approach, and would it work for you?

@ameetpal
Copy link
Contributor Author

Hey @codebien , approch seems good, i hot busy with some other task, will push changes in 2 or 3 days

@ameetpal
Copy link
Contributor Author

ameetpal commented Jul 4, 2024

Hey @codebien, i have incorporated the comment, please review the PR

@codebien codebien self-requested a review July 10, 2024 07:01
if hsErr == nil {
hsErr = handleSummaryResult(c.gs.FS, c.gs.Stdout, c.gs.Stderr, summaryResult)
waitForSummaryGeneratedEvent := emitEvent(&event.Event{
Type: event.TestSummaryGenerated,
Data: summary,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be better to copy ObservedMetrics and RootGroup instead of directly passing them. They are pointers and they might generate data races if there is a read/write across extensions and/or from k6core.

Comment on lines +104 to +106
func (s *Summary) String() string {
return "&{Summary:map[...]...}"
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess when we agree on the generation part then we should update this with some additional information. We might have Summary{Metrics: number, RootGroup: name/(or nil), and the other fields}.

@codebien
Copy link
Collaborator

Hey @ameetpal,
We have discussed it internally and unfortunately, we decided to not encourage you to continue the development, because we might not be able to merge soon the pull request.

As the previous comments demonstrate, there is uncertainty and unknown around this part of the code. The feature requires detailed discussions and knowledge of the k6 codebase.
It has implications across the entire tool including risks, and on the other hand, it has no direct benefit for k6 users.
Furthermore, the k6 end of test summary will be under refactoring in the upcoming releases, and there are high chance that we might end up breaking change this API. As well as the anticipated experimental Event’s API.

Those reasons convinced us that we shouldn’t pursue the current proposal, because it might slow down future development and generate unexpected events.

The correct way for you to extend this functionality is by having a custom output extension to implement your custom summary and related process.

I apologize if we weren't able to communicate this at the beginning, but I hope you can understand that it required research and discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants