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

Validate trigger target on create/update #817

Merged
merged 17 commits into from Feb 6, 2023

Conversation

Dimedrolity
Copy link
Contributor

@Dimedrolity Dimedrolity commented Dec 16, 2022

There is a problem that client sides should call /trigger/check/ API for validation, but obviously it is not necessary. As a result we have invalid triggers in DB. The plan consists of next steps:

  1. Test current createTrigger and updateTrigger API.
  2. Add new version of createTrigger and updateTrigger API with validation and test it. New version should not affect prev version, It is important for backward compatibility, because Moira is follows API first approach.

Then in another PRs update client sides to use new version of APIs.

@Dimedrolity Dimedrolity self-assigned this Dec 16, 2022
@Dimedrolity Dimedrolity force-pushed the feature/trigger-validation-v2 branch 6 times, most recently from b9eff75 to 32ba248 Compare December 19, 2022 05:24
@Dimedrolity Dimedrolity marked this pull request as ready for review December 19, 2022 05:35
@Dimedrolity Dimedrolity requested a review from a team as a code owner December 19, 2022 05:35
@Dimedrolity Dimedrolity marked this pull request as draft December 26, 2022 08:08
@Dimedrolity
Copy link
Contributor Author

Converted to draft because need to add validation on updating existing trigger PUT trigger/<id>

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2022

Codecov Report

Merging #817 (10f6c6e) into master (759d706) will increase coverage by 0.18%.
The diff coverage is 66.66%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #817      +/-   ##
==========================================
+ Coverage   70.32%   70.51%   +0.18%     
==========================================
  Files         179      179              
  Lines        9695     9740      +45     
==========================================
+ Hits         6818     6868      +50     
+ Misses       2494     2484      -10     
- Partials      383      388       +5     
Impacted Files Coverage Δ
api/dto/triggers.go 61.02% <0.00%> (ø)
api/dto/target.go 88.46% <42.85%> (-11.54%) ⬇️
api/handler/trigger.go 33.87% <100.00%> (+24.78%) ⬆️
api/handler/triggers.go 32.33% <100.00%> (+11.53%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Dimedrolity Dimedrolity force-pushed the feature/trigger-validation-v2 branch 2 times, most recently from a1fa5be to 2879e69 Compare January 27, 2023 10:09
Also rename TriggerCheckResponse to TriggerCheckResult, because it is not http Response, it is content of http response.
…t it. New version can be used with query param. It should not affect prev version, it is important for backward compatibility, because Moira is follows API first approach.

Make ProblemOfTarget to use it in tests.
…t it. New version can be used with query param. It should not affect prev version, it is important for backward

 compatibility, because Moira is follows API first approach.
Maybe it is better to move this funcs to dto or controller pkgs.
@Dimedrolity Dimedrolity changed the title Make trigger validation necessary by default Validate trigger target on create/update Jan 30, 2023
@Dimedrolity Dimedrolity marked this pull request as ready for review February 1, 2023 08:32
api/handler/trigger_test.go Outdated Show resolved Hide resolved
@@ -100,17 +100,17 @@ var (
}
)

type problemOfTarget struct {
type ProblemOfTarget struct {
Copy link
Member

Choose a reason for hiding this comment

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

hmm, why become struct as public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This struct is used in tests when compare expected and actual

Copy link
Member

Choose a reason for hiding this comment

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

only for tests? I think better leave struct private to avoid unexpected usage and make constructor....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, only for tests, tests are important part, it uses pkg like a public API. I think constructor for problemOfTarget is not need, because there is no init logic, so now it is fine.

Can we estimate unexpected usage of public ProblemOfTarget, would it lead to some problems?

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 myself that public structs are evil, but ok, lets leave, and add godoc please)

api/dto/target.go Outdated Show resolved Hide resolved
api/dto/triggers.go Outdated Show resolved Hide resolved
api/handler/trigger.go Outdated Show resolved Hide resolved
api/dto/target.go Outdated Show resolved Hide resolved
Copy link
Member

@Tetrergeru Tetrergeru left a comment

Choose a reason for hiding this comment

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

Left some suggestions

kissken
kissken previously approved these changes Feb 3, 2023
Tetrergeru
Tetrergeru previously approved these changes Feb 3, 2023
There was wrong content-type for response, it was 'text/plain'. Now it is JSON. Use render pkg functions to set StatusCode and JSON payload. It is because `responseWriter.Result()` use `snapHeader` field, which is 'snapshot of HeaderMap at first Write', so write operations to response need to use via render pkg functions, not manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants