I am using Spring cloud Zipkin to trace calls with sample percentage 0.4. I am not using any persistent storage like MySQL or Cassandra. Could you please let me know how to set data retention period in Zipkin server e.g. I want to check only 6 hours/1 day data.
Or if I can set max span count
With Spring boot Dalston.SR3 (which uses open zipkin 1.28) you can achieve this by setting property zipkin.storage.mem.max-spans=xxx This will limit the number of spans and discard old ones.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR3</spring-cloud.version>
</properties>
Related
I can connect to the embedded h2 database, but am confused about the correct syntax for connecting to a mysql database named 'test1'. For example, I would like to know what to substitute in the pom.xml, web.xml and persistence.xml files instead of the h2 terminology.
I'm using mysql 5.7.27, with mysql-connector-java-8.0.27.jar in my src/main/resources/META-INF/lib folder. My url is jdbc:mysql://localhost:3306/test1
pom.xml - what to use for groupId and artifactId
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2></artifactId>
<version>1.4.200</version>
</dependency>
web.xml - what to use for name and class
<data-source>
<name>java:global/DataSourceName>
<class-name>org.h2.jdbcx.JdbcDataSource</class-name>
<url>jdbc:h2:mem;DB_CLOSE_DELAY=-1</url>
</data-source>
persistence.xml - does this need to change
<persistence-unit name="PersistenceUnitName"
transaction-type="JTA">
<jta-data-source>java:global/DataSourceName</jta-data-source>
<properties>
<property
name="javax.persistence.schema-generation.database.action"
value="none" />
</properties>
</persistence.unit>
</persistence>
follow this Guide to configure all things you need to connect to MySQL or MariaDB.Use the bellow configuration for MySQL.
- in step (1) use The right classname of MySQl DataSource as bellow:
datasource-classname="com.mysql.cj.jdbc.MysqlDataSource"
Ref: MySQL Doc - Configuration Properties
- In step (3) Add this in POM.XML:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>x.y.z</version>
</dependency>
Ref: MySQL Doc - Installing MySQL Connector/J Using Maven
I have been at this all day and not getting it to work after trying so many combinations. At the end of the day, I am looking for an explicit list of steps to get JSON logging from Karaf. I have even gone through the Maven Karaf plugin source code trying to sort this out, though perhaps I didn't look far enough.
I am using Karaf 4.2.6. I am attempting to build a Karaf deployment using the karaf-maven-plugin, version 4.2.6.
If I change my layout.type for various appenders to JsonLayout, I get a stacktrace saying it can't load the JSON layout because I am missing a class. java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider.
I looked at the jar org.ops4j.pax.logging/pax-logging-log4j2/1.10.2 and found I needed 3 Jackson jars, Core v2.8.7, Annotations v2.8.0, and Databind v2.8.7.
I have been trying to get these files in etc/startup.properties with either the start level of 5 or the start level of 8 so that they are ready for org.ops4j.pax.logging/pax-logging-log4j2/1.10.2 when it starts. I made sure they were in the system folder in the correct place. Most of the time, if I did get them into etc/startup.properties, they had a start level of 30. I placed them in a feature with the correct start levels, but they were either started well after whatever used startup.properties or just never showed up. I tried many possibly combinations, startupBundles, startupFeatures, bootFeatures, but nothing got it in startup.properties. I could not figure out how the contents of startup.properties got generated. Sometimes the features I wanted for my application wouldn't even start because something about the configuration got blocked on setting up the logging if I just placed references to those jars in startup.properties, for example
mvn\:com.fasterxml.jackson.core/jackson-core/2.8.7 = 5
Below is my pom.xml with somethings from previous attempts commented out:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<my_version>0.0.0</my_version>
<myapp_common_version>0.0.0</myapp_common_version>
</properties>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-karaf</artifactId>
<version>${my_version}</version>
<packaging>karaf-assembly</packaging>
<name>myapp-karaf</name>
<description>myapp-karaf details</description>
<repositories>
<!-- Apache ServiceMix repository (for region) -->
<repository>
<id>apache.servicemix.m2</id>
<name>Apache ServiceMix M2 repository</name>
<url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- OPS4J SNAPSHOT repository -->
<repository>
<id>ops4j.sonatype.snapshots.deploy</id>
<name>OPS4J snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/ops4j-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- Apache SNAPSHOT -->
<repository>
<id>apache.snapshots.deploy</id>
<name>Apache snapshot repository</name>
<url>https://repository.apache.org/content/groups/snapshots-group</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.2.6</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>spring</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-common-feature</artifactId>
<version>${myapp_common_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-feature</artifactId>
<!-- Annoyingly this cannot come from an environment variable -->
<version>${my_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${env.MYAPP_SOURCE_HOME}/myapp-common/server/karaf/assembly</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/filtered-resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.2.6</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>process-resources</id>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<startupBundles> <!--
<bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.8.0</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.8.7</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.8.7</bundle> -->
</startupBundles>
<installedFeatures>
</installedFeatures>
<startupFeatures>
<feature>com.me.myapp/${my_version}</feature>
</startupFeatures>
<bootFeatures>
<feature>com.me.myapp.logging.provider/${myapp_common_version}</feature>
<!-- standard distribution -->
<!-- <feature>standard</feature> -->
<!-- minimal distribution -->
<!--<feature>minimal</feature>-->
<feature>jaas</feature>
<feature>shell</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>wrap</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
</bootFeatures>
<javase>1.8</javase>
</configuration>
</plugin>
</plugins>
</build>
</project>
com.me.myapp.logging.provider contains the Jackson jars with the proper start level.
I am running my containers in Kubernetes and want standard log collection in Kubernetes to work. I am using using an extra plugin on the logs collector to at least separate things somewhat into a JSON format, but it is error prone and I'd rather just start with JSON formatted logs rather than processing later downstream so I can separate components of the log, such as person who did the operation, at the time of logging.
I have searched on Stack Overflow, have Googled, and found hints, but no explicit steps that lead to a solution. I realize there is not an explicit listing of files here, but, as I said, I went through many combinations. Any help would be MUCH appreciated. I will also post on the Karaf user group.
OK, after several days, I figured out everything that needed to be done. Thank you #GrzegorzGrzybek for the help.
I needed the following lines
mvn\:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4 = 8
mvn\:com.fasterxml.jackson.core/jackson-core/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-annotations/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-databind/2.9.10 = 8
added to my etc/startup.properties. If I just edited the file to add them, and made sure I had the files in the system repository, it would not work. No idea, some entry was not being made somewhere else in the etc configs so either the container wouldn't start, or some feature sets were being started up before the wrap handler was installed, so the whole container would grind to a halt.
I tried lots of combinations, but finally found how to get things into etc/startup.properties. I placed the bundles I wanted into their own feature with the start level I wanted them to have.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="myapp-common-container-feature">
<feature name="com.me.myapp.logging.provider" version="0.12.0" description="MyApp Logging Provider">
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.10</bundle>
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-core/2.9.10</bundle>
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-databind/2.9.10</bundle>
<bundle start-level="8">mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4</bundle>
</feature>
</features>
Notice the start-level attribute.
Then, in my assembly POM, I put the following dependency:
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-common-container-feature</artifactId>
<version>0.12.0</version>
<classifier>features</classifier>
<type>xml</type>
<scope>compile</scope>
</dependency>
The important line here is <scope>compile</scope>. Features in the compile scope will be placed in startup.properties if placed in <startupFeatures /> in the configuration for the Karaf Maven Plugin.
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<startupFeatures>
<feature>com.me.myapp.logging.provider/0.12.0</feature>
</startupFeatures>
Now the container starts up with JSON logging.
On my side, I followed Keith's answer but this was not sufficient as I had already another older version of Jackson in the OSGI container.
Here is what I did:
Added the log4j2 extra with the three Jackson libs (version 1.11.13 of Pax-Logging + jackson version 2.12.4) in the startup.properties:
mvn\:com.fasterxml.jackson.core/jackson-annotations/2.12.4 = 6
mvn\:com.fasterxml.jackson.core/jackson-core/2.12.4 = 6
mvn\:com.fasterxml.jackson.core/jackson-databind/2.12.4 = 6
mvn\:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.13 = 6
mvn\:org.ops4j.pax.logging/pax-logging-api/1.11.13 = 8
mvn\:org.ops4j.pax.logging/pax-logging-log4j2/1.11.13 = 8
And in the overrides.properties:
mvn:com.fasterxml.jackson.core/jackson-core/2.12.4;range="[2,3)"
mvn:com.fasterxml.jackson.core/jackson-databind/2.12.4;range="[2,3)"
mvn:com.fasterxml.jackson.core/jackson-annotations/2.12.4;range="[2,3)"
and only after this I was able to see my Json log properly formatted (with JsonLayout deprecated way).
I also tried the new way by trying to deploy bundle log4j-layout-template-json but it seems this lib is wrongly released (host fragment is referring to itself).
I put these jars in system repository, installed using wraper and restarted karaf. It's worked for me:
bundle:install 'wrap:mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-core/2.9.10'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.10'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-databind/2.9.10'
Is it possible to change the order of test execution based on #Tag? I want to have all the tests marked with #Tag("fast") executed before #Tag("slow").
Im interested in solutions for IntelliJ IDEA and Maven. Both do not care about the order in which the tags are configured.
My config for Maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration>
<properties>
<includeTags>fast,slow</includeTags>
</properties>
</configuration>
</plugin>
I guess my best bet is to run the suites separately.
JUnit Jupiter only makes a single pass over the test classes and executes all tests whose tag is active, so it does not order. For a tool to order tests by tags, it would have to run JUnit several times, once for each tag, but no tool does that out of the box.
In IntelliJ you can run all tests with a specific tag (earch for "#Tag"), so you could generate several such configuration. In Maven you could give Surefire and Failsafe different tags to execute, although that would only buy you two executions instead of one.
I'm struggling getting the F8 CD-Pipeline to work on OpenShift. I use a Jenkinsfile downloaded from the F8 Jenkinsfile Library for Maven builds with steps "CanaryReleaseAndStage". The stage deploy step there looks like the following:
stage('Rollout Staging') {
kubernetesApply(environment: envStage)
}
I looked up the implementation of kubernetesApply() from the Kubernetes Pipeline Plugin. If no file parameter is present in the call (like here) it applies the Kubernetes/OpenShift resources defined in file "target/classes/META-INF/fabric8/openshift.yml", which is generated upon build.
In this file (which is also uploaded as artifact to the nexus, so I can easily fetch it) there are three resources defined:
A Service
A Deployment config, containing a Docker image reference (without tag), also containing a ConfigChange trigger listening for an ImageStreamTag 'my-project:latest'
A Route
... but no ImageStream. However on the build log I see that an image stream definition apparently got generated on a different file:
[INFO] F8: Found tag on ImageStream my-project tag: sha256:c15b56841387a7e0aea960020ccf2efb48f21bd4d12d826e2cd04a94f4d9d748
[INFO] F8: ImageStream my-project written to /home/jenkins/workspace/my-project-dir/target/my-project-is.yml
But I'm afraid that one never gets applied to Kubernetes. Hence there is no image stream in the staging project.
In this configuration the staging deployment cannot even deploy the pod. If I add an image stream manually to the staging project it deploys but is never updated when new builds occur.
I've updated to the newest fabric/jenkins image 2.2.331, but it also does not seem to work here.
My pom.xml (parts essential for f8 building):
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>myproject/artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<fabric8.mode>openshift</fabric8.mode>
<fabric8.build.strategy>docker</fabric8.build.strategy>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.2.28</version>
<configuration>
<images>
<image>
<name>fabric8/my-project</name>
<build>
<dockerFileDir>${project.basedir}/src</dockerFileDir>
<dockerFile>Dockerfile</dockerFile>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So I'd like to know:
How is the CD pipeline supposed to work regarding updates to the staging deployments here?
Why is this image stream definition created if it is not applied. Am I missing some configuration here maybe.
Thanks for any insight!
Any chance of seeing your pom.xml and full build? It sounds like you are using fabric8-maven-plugin right? Its doing a S2I binary build and generating an image stream? It just sounds like somethings going wrong and the generated image stream isn't being included in your target/classes/META-INF/fabric8/openshift.yml maybe?
I wonder if something is going wrong in the order of your maven goals or something (e.g. typically fabric8:resource is first, then fabric8:build which then adds the ImageStream into the generated YAML files)
We develop multiple branches of a project concurrently. Each developer has multiple working copies, each working copy uses its own DB schema. (There will typically be a working copy per branch, but sometimes even more than one working copy per branch.) We need to let Maven know the DB credentials (for the db-migration plugin, for unit tests, for the dev instance of the servlet).
We can't put the credentials in the pom.xml because each developer might use different DB schema names. We can't put the credentials in settings.xml because each developer uses more than one schema.
Where do we put the credentials?
For example, http://code.google.com/p/c5-db-migration/ describes that the DB credentials need to be present in pom.xml but I would like to externalize them out to a file that's not under revision control.
You could put them into a properties file inside the project directory but which is excluded from source control.
With Maven it's possible to read properties from an external file by using a <build><filters><filter> element as instructed here.
Read following answers:
How to read an external properties file in Maven
Reading properties file from Maven POM file
Read a file into a Maven property
or just:
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
</execution>
<configuration>
<files>
<file>dev.properties</file> <======== IT IS!!!!!
</files>
</configuration>
</executions>
</plugin>
</plugins>
</build>
</project>