-
Notifications
You must be signed in to change notification settings - Fork 27
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
Diagnostics for invalid annotation parameter values #77
Comments
Here is some info to help with implementing this issue: Here is the current class we use to validate MicroProfile Fault Tolerance annotations: https://github.com/eclipse/lsp4mp/blob/master/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/faulttolerance/java/MicroProfileFaultToleranceDiagnosticsParticipant.java Here is a utils library that we have for helping work with annotations in JDT: https://github.com/eclipse/lsp4mp/blob/master/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/utils/AnnotationUtils.java |
I'm generally ok, with adding the annotation support, but where I'd like to have some automation or generalization is in the validation of the parameters themselves. It seems overkill to have to hard-code specific parameter restrictions. Granted, we've done pretty much the same for #90 & likely for redhat-developer/quarkus-ls#378 I wonder if we could have some general definition file that specifies a format like :
or something similar that allows us to easily implement annotation validation for very basic parameter restrictions. |
I agree with you, we should give the capability to describes validation rules in a metadata file. I think JSON format could be nice because we use already JSON for static properties. I will work on that as soon as I will finish my tasks. |
Here a proposition for describing the validation rules in a JSON file format: [
{
"annotation": "org.eclipse.microprofile.faulttolerance.CircuitBreaker",
"rules": [
{
"attribute": "delay",
"ranges": ">=0"
},
{
"attribute": "requestVolumeThreshold",
"ranges": ">=1"
},
{
"attribute": "failureRatio",
"ranges": ">=0 and <=1"
},
{
"attribute": "successThreshold",
"ranges": ">=1"
}
]
}
] For ranges it requires to develop a parser to parse expression (by supporting basic syntax), but I find {
"attribute": "failureRatio",
"ranges": ">=0 and <=1"
} it's more readable than: {
"attribute": "failureRatio",
"ranges": {
"from" : {
"value": "0",
"inclusive": true
},
"to" : {
"value": "1",
"inclusive": true
}
}
} The second advantage to use expression is that we could manage another expression in the future (if we need) like @fbricon @rgrunber @AlexXuChen what do you think about that? |
For loading the rules file <extension point="org.eclipse.lsp4mp.jdt.core.annotationRules">
<!-- Annotation rules for MicroProfile Fault Tolerance annotations -->
<rule path="/annotation-validators/mp-faulttolerance-validator.json" />
</extension> |
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
After some experimentation, I think I will support this syntax: {
"attribute": "failureRatio",
"ranges": {
"from" : ">=0",
"to" : "<=1"
}
} If you have some suggestion, please tell me. Thanks! |
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
By continuing to develop this issue, I noticed that we visit the full AST for each diagnostic participant which I think which could be bad when we will add another diagnostic participant which will visist the AST. My idea is to have one ASTVisitor which visist the full AST and this visitor should manage the whole collect of diagnostics. I'm working on this idea and my idea isto provide the extension point
<extension point="org.eclipse.lsp4mp.jdt.core.javaASTValidators">
<!-- Java validation for the MicroProfile @ConfigProperty annotation -->
<validator annotation="org.eclipse.microprofile.config.inject.ConfigProperty"
class="org.eclipse.lsp4mp.jdt.internal.config.java.MicroProfileConfigASTValidator" />
</extension>
<extension point="org.eclipse.lsp4mp.jdt.core.javaASTValidators">
<!-- Java validation for the MicroProfile Fault Tolerance annotations -->
<validator annotation="org.eclipse.microprofile.faulttolerance.CircuitBreaker" >
<parameter name="delay">
<range from="<=0" />
</parameter>
<parameter name="requestVolumeThreshold">
<range from="<=1" />
</parameter>
<parameter name="failureRatio">
<range from="<=0" to=">=1" />
</parameter>
<parameter name="successThreshold">
<range from="<1" />
</parameter>
</validator>
</extension>
|
Sounds good. But I feel a bit cagey about using <=> symbols in the constraints. WDYT about using, for 0<x<=10, <from excludeValue='true'>0<from>
<to>10</to> , for >=1 <greaterThan>1</greaterThan> ...? |
Glad it pleases you.
I think it's very verbose compare to just writting: <range from="<=0" to=">=1" /> I find it's more natural to write those expression. @rgrunber what do you think? |
there's nothing natural in writing escaped XML ( |
I think Alternative range syntax which I have always liked is from OSGi. eg. |
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Indeed escape is awfull. I like osgi syntax. @fbricon do you like it? |
+1 |
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Ok now I'm using OSGI syntax which simplifies dragsticly the write of range: <extension point="org.eclipse.lsp4mp.jdt.core.javaASTValidators">
<!-- Java validation for the MicroProfile Fault Tolerance annotations -->
<annotationValidator annotation="org.eclipse.microprofile.faulttolerance.CircuitBreaker" >
<parameter name="delay" range="0" /> <!-- x >=0 -->
<parameter name="requestVolumeThreshold" range="1" /> <!-- x >=1 -->
<parameter name="failureRatio" range="[0,1]" /> <!-- 0 <= x <= 1 -->
<parameter name="successThreshold" range="1" /> <!-- x >=1 -->
</annotationValidator>
</extension> see Many tahnks @rgrunber for your great suggestion! |
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes eclipse#77 Signed-off-by: azerr <azerr@redhat.com>
Fixes #77 Signed-off-by: azerr <azerr@redhat.com>
I reopen this issue since I have just supported CircuitBreak rules. @AlexXuChen could you see other cases in https://github.com/eclipse/microprofile-fault-tolerance/tree/5adfe495f0ad1fe8f52a443781b7509b01a92f15/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/invalidParameters to support that:
|
I believe we can close this issue @angelozerr. Thoughts? |
yes sure, since your Retry PR has been merged. |
Several mp fault tolerance annotations will throw a
FaultToleranceDefinitionException
if configured incorrectly. While I noticed this for fault tolerance, probably would be good to design this in a way that could be re-used for other mp-specs annotations.A common scenario is parameters that have a min/max value
Ex. circuit breaker failure ratio must be between 0-1 https://github.com/eclipse/microprofile-fault-tolerance/blob/master/api/src/main/java/org/eclipse/microprofile/faulttolerance/CircuitBreaker.java#L149
or requestVolumeThreshold must be >= 1 https://github.com/eclipse/microprofile-fault-tolerance/blob/master/api/src/main/java/org/eclipse/microprofile/faulttolerance/CircuitBreaker.java#L136
Can look at the invalid parameters tests for the different cases annotations are invalid https://github.com/eclipse/microprofile-fault-tolerance/tree/5adfe495f0ad1fe8f52a443781b7509b01a92f15/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/invalidParameters
The text was updated successfully, but these errors were encountered: