In this tutorial, we’ll see how to import a demo in your favourite IDE, launch it and see results of modifications applied on rules.
We’ll be using the health insurance demo, but the import steps are the same for the other ones.
First, download the archive JAR file from our web site:
Then, extract the files and import them in Eclipse, by opening the “Import” dialog. Select “Existing Maven Projects”, then click “Next”:
Select the directory where you extracted the sources, all the maven modules are detected and will be imported:
After what you will see this in the Eclipse Project Explorer:
Please import the licence file, for instance in the common main resources:
The IDE will download the dependencies and compile everything for you. Just be careful if you are behind a proxy, you should configure Maven to use it.
When all is compiled, then start the app. For instance, I will start the batch test Spring Boot app:
Then you can follow the startup in the console. You should get something like this:
This log shows that first run builds the ruleset. Next logs will show that it’s found in cache and not rebuilt.
Then, open the following url in a browser: http://locahost:8080
The current ruleset configuration for the batch is loaded. Modify the config like shown above.
Save the config using the button on the top and then look the console: the new configuration is directly taken into account.
The 2nd and 6th prices have changed accordingly to the new rules configuration.
Finally, if you have launched the “Batch Test” module, you can have a look at the MRules JMX Beans and the MRules monitoring extension results.
First, to see the MBeans, open Java Mission Control (jmc), select your local JVM and open the MBeans Browser.
You should find the “com.massa.mrules” domain, containing one MBean for the ruleset used in the demo module :
Then, you to the metrics scraping page : http://locahost:8080/actuator/prometheus which should outputs metrics in Open Metrics format, as follows, amongst other stats generated by Spring and Micrometer :
# HELP mrules_compilations_last_date RuleSet last compilation date # TYPE mrules_compilations_last_date gauge mrules_compilations_last_date{name="2019 Health Pricing",type="RuleSet",} 1.600812930481E12 # HELP mrules_optimizations_last_date RuleSet last optimization date # TYPE mrules_optimizations_last_date gauge mrules_optimizations_last_date{name="2019 Health Pricing",type="RuleSet",} 1.600812930505E12 # HELP mrules_compilations_failures RuleSet compilation failures # TYPE mrules_compilations_failures gauge mrules_compilations_failures{name="2019 Health Pricing",type="RuleSet",} 0.0 # HELP mrules_optimizations_last_time RuleSet last optimization time # TYPE mrules_optimizations_last_time gauge mrules_optimizations_last_time{name="2019 Health Pricing",type="RuleSet",} 2.40872E7 # HELP mrules_optimizations RuleSet optimization total # TYPE mrules_optimizations gauge mrules_optimizations{name="2019 Health Pricing",type="RuleSet",} 2.0 # HELP mrules_optimizations_time RuleSet optimization total time # TYPE mrules_optimizations_time gauge mrules_optimizations_time{name="2019 Health Pricing",type="RuleSet",} 6.5387726E7 # HELP mrules_optimizations_last_failure_date RuleSet last failed optimization date # TYPE mrules_optimizations_last_failure_date gauge mrules_optimizations_last_failure_date{name="2019 Health Pricing",type="RuleSet",} -1.0 # HELP mrules_compilations_time RuleSet compilation total time # TYPE mrules_compilations_time gauge mrules_compilations_time{name="2019 Health Pricing",type="RuleSet",} 5.8944502E7 # HELP mrules_executions_time RuleSet execution total time # TYPE mrules_executions_time gauge mrules_executions_time{name="2019 Health Pricing",type="RuleSet",} 1.75738057E8 # HELP mrules_optimizations_failures RuleSet optimization failures # TYPE mrules_optimizations_failures gauge mrules_optimizations_failures{name="2019 Health Pricing",type="RuleSet",} 0.0 # HELP mrules_compilations RuleSet compilation total # TYPE mrules_compilations gauge mrules_compilations{name="2019 Health Pricing",type="RuleSet",} 2.0 # HELP mrules_executions_failures RuleSet execution failures # TYPE mrules_executions_failures gauge mrules_executions_failures{name="2019 Health Pricing",type="RuleSet",} 147.0 # HELP mrules_executions_last_time RuleSet last execution time # TYPE mrules_executions_last_time gauge mrules_executions_last_time{name="2019 Health Pricing",type="RuleSet",} 215058.0 # HELP mrules_executions_last_date RuleSet last execution date # TYPE mrules_executions_last_date gauge mrules_executions_last_date{name="2019 Health Pricing",type="RuleSet",} 1.600813545031E12 # HELP mrules_compilations_last_time RuleSet last compilation time # TYPE mrules_compilations_last_time gauge mrules_compilations_last_time{name="2019 Health Pricing",type="RuleSet",} 1.3258079E7 # HELP mrules_executions RuleSet execution total # TYPE mrules_executions gauge mrules_executions{name="2019 Health Pricing",type="RuleSet",} 441.0 # HELP mrules_executions_last_failure_date RuleSet last failed execution date # TYPE mrules_executions_last_failure_date gauge mrules_executions_last_failure_date{name="2019 Health Pricing",type="RuleSet",} 1.60081354503E12 # HELP mrules_compilations_last_failure_date RuleSet last failed compilation date # TYPE mrules_compilations_last_failure_date gauge mrules_compilations_last_failure_date{name="2019 Health Pricing",type="RuleSet",} -1.0
We chose here to demonstrate how easy it is to expose metrics on how MRules behaves in your app and the export them to Prometheus. But lots of other collectors are also supported!
Don’t hesitate to change the metrics configuration in the code of the demo and to directly visualize the effects of the modifications.