How to set Kamon log reporter to redirect logs to a log file? - kamon

I have currently succeeded in setting up kamon log reporter by using the following configuration.
kamon{ modules { kamon-log-reporter.auto-start = yes } }
I am using the following version of kamon log reporter
<dependency>
<groupId>io.kamon</groupId>
<artifactId>kamon-log-reporter_2.12</artifactId>
<version>0.6.7</version>
</dependency>
How do i redirect the logs to a log file instead of writing them to System.out?

Related

openapi.yaml not generated successfully - Swagger Doc does not open for Windows machines

So I am working on a spring-mvc project, which suddenly started giving this issue when installed on Windows machines only. It's a thick client app.
When trying to access the swagger docs, following error comes :
The logs show following error in the stacktrace :
2022-04-20 04:15:44.821utc WARN Configuration,main:117 - couldn't read inflector config from resource stream
2022-04-20 04:15:44.821utc WARN Configuration,main:131 - couldn't read inflector config from system property
2022-04-20 04:15:44.853utc WARN OpenAPIV3Parser,main:91 - Exception while reading:
io.swagger.v3.parser.exception.ReadContentException: Unable to read location `openapi.yaml`
at io.swagger.v3.parser.OpenAPIV3Parser.readContentFromLocation(OpenAPIV3Parser.java:238) ~[swagger-parser-v3-2.0.27.jar:2.0.27]
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:87) ~[swagger-parser-v3-2.0.27.jar:2.0.27]
..
..
2022-04-19 17:19:16.980utc ERROR [swagger-inflector],http-nio-8080-exec-8:175 - Allocate exception for servlet [swagger-inflector]
*java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.OpenAPI.getComponents()" because "openAPI" is null
at io.swagger.oas.inflector.utils.ExtensionsUtil.removeExtensions(ExtensionsUtil.java:26) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.getExposedAPI(OpenAPIInflector.java:543) ~[swagger-inflector-2.0.6.jar:2.0.6]*
at io.swagger.oas.inflector.OpenAPIInflector.init(OpenAPIInflector.java:139) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.<init>(OpenAPIInflector.java:117) ~[swagger-inflector-2.0.6.jar:2.0.6]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at
OpenAPIInflector.getExposedAPI reads swaggerURL location from inflector.yaml file. For some reason on windows, configuration is not picking up openapi.yaml file or corresponding openapi.json file as shown in the screenshot. xxx-openapi.yaml is something defined inside inflector.yaml which in my understanding is being used to generate an openapi.yaml file. In MacOs/local setup I can see this file getting generated and the docs coming up fine.
Please help debug, what the potential cause could be. Permissions are fine on the system this tool is running for inflector.yaml inside classes folder?
here is how the inflector.yaml is defined.
swaggerUrl: xxx-openapi.yaml
xxx-openapi.yaml & inflector.yaml are present in
src/main/resources/
I am also wondering if windows OS is not able to read the files from this path properly. Bases on other posts I have already tried different URLs such as following but they did not work for me.
http://windows-machine-ip:8080/swagger-ui/
http://windows-machine-ip:8080/swagger-ui/index.html
http://windows-machine-ip:8080/v3/api-docs/swagger-ui.html
Note**
openapi: 3.0.0
Dependencies :
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-inflector</artifactId>
<version>2.0.6</version>
</dependency>
Please guide. I am new to this project as well as swagger on spring-mvc. I will be happy to read about stuff which can lead me to fix this. Not looking for a readymade solution but I have tried almost all relevant solutions across multiple forums and hence the post as I am still not able to find the root cause to this. Also I cannot change the existing implementations (like writing it all from scratch) hence I am here more to understand the root cause.
I'm just installing OpenAPI 3 on Spring Core 5.3.18 (Not Boot) projetc :
1/`<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>`
2/ Configurer :
#Configuration
#EnableOpenApi
public class SwaggerConfig {
private static final Logger log = LoggerFactory.getLogger(SwaggerConfig.class);
private static String line = "=".repeat(100);
#Bean
public Docket api(ServletContext servletContext) {
log.info(line);
log.info("Docket swagger called : {} , name :{} ", servletContext.getContextPath(), servletContext.getContext("/rs"));
log.info(line);
return new Docket(DocumentationType.OAS_30)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
;
}
3/ WebConfigurer :
`
#Configuration
#EnableWebMvc
public class WebConfigurer implements WebMvcConfigurer {
private static final Logger log = LoggerFactory.getLogger(WebConfigurer.class);
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}`
4/ URL of Swagger UI is :
[root path]/v3/api-docs for documentation
[root path]/swagger-ui/index.html
Hope that help ;-)

Issue when flink upload a job with stream sql query

I used the latest flink version(1.10.0) and sbt(1.3.7). I have this exception when upload a job with streaming sql query:
Caused by: java.lang.ClassCastException:
org.codehaus.janino.CompilerFactory cannot be cast to
org.codehaus.commons.compiler.ICompilerFactory
at org.codehaus.commons.compiler.CompilerFactoryFactory.getCompilerFactory(CompilerFactoryFactory.java:129)
at org.codehaus.commons.compiler.CompilerFactoryFactory.getDefaultCompilerFactory(CompilerFactoryFactory.java:79)
at org.apache.calcite.rel.metadata.JaninoRelMetadataProvider.compile(JaninoRelMetadataProvider.java:432)
When I running main class with sbt run it works perfectly. I made jar with the sbt assembly command and I have conflicts between libraries. For this reason add this in the build.sbt:
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
I read a similar case with hive connector https://issues.apache.org/jira/browse/FLINK-14849 and this is the answer:
After https://issues.apache.org/jira/browse/FLINK-13749 , flink-client will use default child-first resolve-order.
If user jar has some conflict dependents, there will be some problem.
My question is: How to resolve these conflicts? Any assembly merge strategy suggest for this case?
Help would be appreciated.
I faced the same issue and the following solution helped me get through :
assembly / assemblyMergeStrategy := {
case PathList("org", "codehaus", "janino", "CompilerFactory.class") => MergeStrategy.discard // discard
case x => MergeStrategy.first // first
}
Also, took help from the this link.
The above addition needs to be done in sbt.build file and make sure you're building using assembly command.
In case one is building using package-bin in case of legacy applications, follow this link.
Another solution includes checking the scope of the flink libraries. If by any chance you have accidentally pushed libraries that were earlier set to 'provided' with something like 'compile', do revert the changes and test.
Hope this helps.
I have same problem.
Maybe you have package your code with flink-table-planner_${scala.binary.version}, so you need to change your maven config with those settings:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner-blink_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
I had the same issue. My problem was, that I added the dependency
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
without the provided scope. Therefore, maven packaged it in my jar, which lead to the ClassCastException when trying to submit the job to my local flink cluster.

How to build runnable JAR using Javalite framework as standalone http?

As questioned, how to build runnable JAR using Javalite framework?
Javalite doesn't have known entry point / main class. I browse some of the examples but not found any clue.
This jar will run as stand-alone on server using java -jar command.
Below snippet of my plugin on pom.xml file
Packaging
<modelVersion>4.0.0</modelVersion>
<groupId>org.javalite</groupId>
<artifactId>activeweb-simple</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>ActiveWeb Example WebApp</name>
Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>com.company.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
And the Application.java,
public class Application {
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8081";
}
tomcat.setPort(Integer.valueOf(webPort));
StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
File additionWebInfClasses = new File("target/classes");
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
additionWebInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
}
Note : I'm currently using tomcat as embedded http-server to enable the JAR file run as stand-alone. But, Javalite ActiveWeb probably has a way for this.
You can build any number of different types of JavaLite projects, such as standalone that use some features: JavaLite HTTP, ActiveJDBC, JavaLite Async, etc. In addition, if you want to build a web application, you also will need ActiveWeb.
Here is a list of examples from the JavaLite repo:
ActiveJDBC:
https://github.com/javalite/standalone-example
https://github.com/javalite/simple-example
https://github.com/javalite/ant-example
https://github.com/javalite/activejdbc-gradle
https://github.com/javalite/multiple-db-example
ActiveWeb:
https://github.com/javalite/activeweb-simple
https://github.com/javalite/kitchensink
https://github.com/javalite/activeweb-secure
https://github.com/javalite/activeweb-bootstrap
https://github.com/javalite/activeweb-lessc
Every example app has a README file you can read to see what the example is for.
In order to start any project, just clone a repo, get it running then start modifying it to your liking.
Additionally, pay attention to the Releases page http://javalite.io/releases and keep your dependencies up to date.

GlassFish 4, Grizzly Framework 2.3.23: Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn

While starting GlassFish 4.1.1 server (Grizzly Framework 2.3.23), below warning message is displayed: Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn
Do Grizzly Framework 2.3.23 to be separately installed on the computer? (As per details: "Class=interface org.glassfish.grizzly.http.server.AddOn" it seems like grizzly http server is part of glassfish) If grizzly http server seperately not needed to be installed, then which instance it is trying to be initialized and failing.
Do GlassFish Plugin for Eclipse is to be added in Spring Tool Suite IDE?
GlassFish 4 server stop and start using command prompt tested:
glassfish4\bin>asadmin stop-domain
Command stop-domain executed successfully.
glassfish4\bin>asadmin start-domain
Waiting for domain1 to start ;
Successfully started the domain : domain1;
domain Location: glassfish4\glassfish\domains\domain1;
Log File: glassfish4\glassfish\domains\domain1\logs\server.log;
Admin Port: 4848;
Command start-domain executed successfully.
Still the warning exist as given above.
If Grizzly Framework is inbuilt in GlassFish 4 then, does Grizzly dependency inclusion in the project pom.xml needed explicitly as given below? (code is from: Grizzly)
<dependencies>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.3.22</version>
</dependency>
</dependencies>
I had the same problem, with Glassfish embedded 4.1.2. Please notice that you wrote only a part of the errore message, full error message is:
Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-1, realClassName=org.glassfish.grizzly.http2.Http2AddOn
So, Glassfish is trying to instantiate a class in package http2, however this package is not included in embedded Glassfish! There is no such folder in glassfish-embedded-all-4.1.2.jar.
I don't know if this was fixed in 5.0.
My solution for 4.1.2 is to add dependencies that include this package (well, this is exactly the solution you propose):
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http2</artifactId>
<version>2.3.28</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-npn-bootstrap</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>

Setting Logback Configuration file Programmatically

I'm using the sbt run command to run my project. My project uses the Logback logging mechanism and if I would like to enable logging, then I have to use the following command:
sbt -Dlogback.configurationFile=/path/to/log/file/app-logger.xml run
Is there a way that I could set this programmatically? I mean I would like to just say
sbt run
and it picks up automagically the app-logger.xml by itself via the application.
This is how I do it!
def loadLogger() = Option(System.getProperty("logback.configurationFile")) match {
case Some(logXml) =>
logger.info(s"using logger $logXml")
case None =>
val path = s"${System.getProperty("user.dir")}/conf/app-logger.xml"
System.setProperty("logback.configurationFile", path)
logger.info(s"using logger $path")
}

Resources