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

[cmd/telemetrygen] remove reliance on JSON unmarshalling for status code string #26985

Conversation

jmsnll
Copy link
Contributor

@jmsnll jmsnll commented Sep 18, 2023

Description:

Removes the use of JSON Unmarshalling when determining the provided trace status code.

The existing implementation allowed both status code and status strings to be set using the command line flag --status-code without issue however it's not obvious that the default command line value must be a JSON string as encountered in #25906

I've replaced the existing code with a switch-case statement which is more explicit. Additionally, the code now checks the lowercase version of the provided string, enabling support for mixed-case inputs such as --status-code unset and --status-code Unset flags.

I'm undecided if this is actually better or required since we now understand the original cause of the issue.

Example usage is now:

telemetrygen traces --otlp-insecure --traces 1 --status-code 0 # unset
telemetrygen traces --otlp-insecure --traces 1 --status-code 1 # error
telemetrygen traces --otlp-insecure --traces 1 --status-code 2 # ok 
telemetrygen traces --otlp-insecure --traces 1 --status-code unset
telemetrygen traces --otlp-insecure --traces 1 --status-code error
telemetrygen traces --otlp-insecure --traces 1 --status-code ok

Link to tracking Issue: Fixes #25906

Testing:

Added additional test cases and implemented sub-tests as the tests were quitting after the first falsified case.

Documentation: No updates to documentation.

…mmand

- strings were not valid JSON and would therefore cause the JSON Unmarshal to return an error
- each status code is now captured explicitly in a switch case statement
- mixed case is now supported when passing it as a string also
- `TestSpanStatuses` test was updated to run as sub-tests
@jmsnll jmsnll requested a review from a team September 18, 2023 19:09
@github-actions github-actions bot added the cmd/telemetrygen telemetrygen command label Sep 18, 2023
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks @jmsnll for fixing this 👍🏻

Copy link
Contributor

@fatsheep9146 fatsheep9146 left a comment

Choose a reason for hiding this comment

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

Thanks for contribution!
I think we'd better merge this after #26668 is merged, in order to double check is pr is valid.

@mx-psi mx-psi requested a review from fatsheep9146 September 25, 2023 15:26
@mx-psi
Copy link
Member

mx-psi commented Sep 25, 2023

I merged #26668, @fatsheep9146 can you take another look?

@fatsheep9146
Copy link
Contributor

fatsheep9146 commented Sep 25, 2023

I merged #26668, @fatsheep9146 can you take another look?

Thanks, I just merged the main to see if the check is passed @mx-psi

After all checks are passed, I will approve the pr.

@fatsheep9146 fatsheep9146 added the ready to merge Code review completed; ready to merge by maintainers label Sep 25, 2023
@fatsheep9146
Copy link
Contributor

I merged #26668, @fatsheep9146 can you take another look?

Thanks, I just merged the main to see if the check is passed @mx-psi

After all checks are passed, I will approve the pr.

All related checks are passed, I approved the pr @mx-psi

@codeboten codeboten merged commit 9898c2a into open-telemetry:main Sep 25, 2023
96 checks passed
@github-actions github-actions bot added this to the next release milestone Sep 25, 2023
jmsnll added a commit to jmsnll/opentelemetry-collector-contrib that referenced this pull request Nov 12, 2023
…ode string (open-telemetry#26985)

Removes the use of JSON Unmarshalling when determining the provided
trace status code.

The existing implementation allowed both status code and status strings
to be set using the command line flag `--status-code` without issue
however it's not obvious that the default command line value must be a
JSON string as encountered in open-telemetry#25906

I've replaced the existing code with a switch-case statement which is
more explicit. Additionally, the code now checks the lowercase version
of the provided string, enabling support for mixed-case inputs such as
`--status-code unset` and `--status-code Unset` flags.

I'm undecided if this is actually better or required since we now
understand the original cause of the issue.

Example usage is now:

```
telemetrygen traces --otlp-insecure --traces 1 --status-code 0 # unset
telemetrygen traces --otlp-insecure --traces 1 --status-code 1 # error
telemetrygen traces --otlp-insecure --traces 1 --status-code 2 # ok 
telemetrygen traces --otlp-insecure --traces 1 --status-code unset
telemetrygen traces --otlp-insecure --traces 1 --status-code error
telemetrygen traces --otlp-insecure --traces 1 --status-code ok
```

Fixes open-telemetry#25906

Added additional test cases and implemented sub-tests as the tests were
quitting after the first falsified case.

---------

Co-authored-by: Ziqi Zhao <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd/telemetrygen telemetrygen command ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cmd/telemetrygen] default value Unset of args status-code is illegal
5 participants