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

Annotation is present on method if {there is another annotation|method signature pattern} #28

Closed
2 tasks
dgroup opened this issue Jan 22, 2022 · 3 comments · Fixed by #53
Closed
2 tasks
Assignees
Milestone

Comments

@dgroup
Copy link
Owner

dgroup commented Jan 22, 2022

Overview

Each application should provide metrics for future application monitoring, especially if its expose API endpoints.

The rule

If we expose a particular REST endpoint, this endpoint should be monitored as well, therefore, each method with @Get, @Post, etc. annotations should have annotation @Timed with metric reference.

@Timed is just an example, in the future we'll configure several REST frameworks with different standards for monitoring (e.g micrometer, etc.).

Ruleset(s)

  • arch4u-micrometer-ruleset.xml (with monitoring related test cases e.g. micrometer @Timed annotation)
  • arch4u-template-ruleset.xml (with non-monitoring related test cases e.g. any other annotation like @Override)

Test case 1 [positive/right]: Expected annotation is present on the method that has another annotation

@RestController
public class MyTypicalRestController {
   
   @Timed                                          
   @GetMapping("/get")                 // ok, @Timed is present for all methods with annotation @GET
   public .. get(BigInteger id) {
      ..
   }

   @GetMapping("/getXXX")              // violation, no annotation @Timed found
   public .. getXXX(BigInteger id) {
      ..
   }
}

Test case 2 [positive/right]: Expected annotation is present on the method that has some signature like public Order getXXXX

@RestController
public class MyTypicalRestController {
   
   @Timed                                          
   @GetMapping("/get")                 // ok, @Timed is present for all methods with annotation @GET
   public .. get(BigInteger id) {
      ..
   }

   @GetMapping("/getXXX")              // violation, no annotation @Timed found for method `public Order getXXXX`
   public .. getXXX(BigInteger id) {
      ..
   }
}
@dgroup dgroup added this to the 0.1.0 milestone Jan 22, 2022
@dykov
Copy link
Collaborator

dykov commented Jan 22, 2022

@dgroup please provide some examples with right/wrong cases

@dykov
Copy link
Collaborator

dykov commented Jan 31, 2022

@dgroup , please describe the second example. why the method with this signature should have @Timed annotation?
in this case, it will be better to split the rule into 2 separate rules - it will be easier to specify property values for each rule separately

in my opinion, methods should have such annotation if the class has @RestController annotation

@dgroup dgroup linked a pull request Feb 2, 2022 that will close this issue
@dgroup
Copy link
Owner Author

dgroup commented Feb 2, 2022

@dykov not all methods from @RestController will have @Get or @Post annotations, thus it's better to inspect each method separately.

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

Successfully merging a pull request may close this issue.

2 participants