generator-jhipster: Tomcat: Broken Metrics page in 5.8.1
Overview of the issue
Metrics page display nothing.
Motivation for or Use Case
Because it can be interesting to have metrics.
Reproduce the error
generate the app, change nothing. Launch it by eclipse or just in a tomcat http://localhost:8080/#/admin/jhi-metrics
We see a stack in console: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.HashMap[“cache”]->java.util.HashMap[“null”]) at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:294) at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:102) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:272) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:180) at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) … at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.HashMap[“cache”]->java.util.HashMap[“null”]) at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:285) at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1251) … at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913) at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:285) … 101 common frames omitted
Related issues
No see, it’s since jhipster migrate to micrometer
Suggest a Fix
the metric tomcat.cache.hit have no key because it have no tag name but have a name
So i suggest to change
JHipsterMetricsEndpoint.cacheMetrics() from:
String name = counter.getId().getTag("name");
to
String name = counter.getId().getTag("name");
if(name ==null) {
name = counter.getId().getName(); //maybe we can substring before the first dot found
}
JHipster Version(s)
5.8.1
JHipster configuration
See above
JHipster Version(s)
reqhub@0.0.0 H:\git\mcp\com.trululu.mcp.requirement.product.server\plugins\com.trululu.mcp.server\com.trululu.metax.requirement.server.webapp
`-- generator-jhipster@5.8.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.trululu.metax.requirement.server.webapp",
"nativeLanguage": "en"
},
"jhipsterVersion": "5.8.1",
"applicationType": "monolith",
"baseName": "reqhub",
"packageName": "com.trululu.metax.requirement.server.webapp",
"packageFolder": "com/trululu/metax/requirement/server/webapp",
"serverPort": "8080",
"authenticationType": "session",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mariadb",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
"clientFramework": "angularX",
"useSass": false,
"clientPackageManager": "npm",
"testFrameworks": ["gatling", "protractor"],
"jhiPrefix": "jhi",
"otherModules": [],
"enableTranslation": true,
"nativeLanguage": "en",
"languages": ["en"],
"entitySuffix": "",
"dtoSuffix": "DTO"
}
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
Environment and Tools
java version “1.8.0_181” Java™ SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot™ 64-Bit Server VM (build 25.181-b13, mixed mode)
git version 2.19.0.windows.1
node: v8.12.0
npm: 6.7.0
yeoman: 2.0.5
INFO! Congratulations, JHipster execution is complete!
Entity configuration(s) entityName.json files generated in the .jhipster directory
no entity
Browsers and Operating System
- Checking this box is mandatory (this is just to show you read everything)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27 (23 by maintainers)
I think it was just included in the 6.0.0 version, unfortunately, but the fix provided by @Dufgui should work
Cf my previous comment