Refactor docker compose so default launches everything

This commit is contained in:
Dave Syer
2015-12-15 09:44:11 +00:00
parent 327bb46e90
commit 28dbb0cd14
16 changed files with 250 additions and 61 deletions

14
pom.xml
View File

@@ -169,6 +169,16 @@
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-java-server</artifactId>
<version>${zipkin-java.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-java-jdbc</artifactId>
<version>${zipkin-java.version}</version>
</dependency>
<!-- Spock -->
<dependency>
<groupId>org.spockframework</groupId>
@@ -186,13 +196,12 @@
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>test</scope>
<!-- not test because we need it in stream -->
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
@@ -230,6 +239,7 @@
<spring-cloud-netflix.version>1.1.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<aspectj.version>1.8.4</aspectj.version>
<spock.version>1.0-groovy-2.4</spock.version>
<zipkin-java.version>0.1.1</zipkin-java.version>
</properties>
<profiles>

View File

@@ -21,6 +21,7 @@
<module>spring-cloud-sleuth-sample-messaging</module>
<module>spring-cloud-sleuth-sample-ribbon</module>
<module>spring-cloud-sleuth-sample-zipkin</module>
<module>spring-cloud-sleuth-sample-zipkin-stream</module>
</modules>
</project>

View File

@@ -0,0 +1,12 @@
FROM springio/java8
RUN chmod 777 -R /tmp
VOLUME /tmp
VOLUME /app
EXPOSE 9411 8000
RUN groupadd -g 1000 spring
RUN useradd -u 1000 -g 1000 -ms /bin/bash spring
VOLUME /home/spring
ENV HOME /home/spring
USER spring
WORKDIR /app/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-zipkin-stream
CMD ["../../mvnw", "spring-boot:run"]

View File

@@ -0,0 +1,39 @@
# Running a Zipkin Query Server
There are 4 parts to Zipkin: the instrumented client apps, the web UI, the backend database and the query server. The database for this implementation is MySQL.
## Zipkin Services
Run this app using the docker-compose provided.
```
$ docker-compose build zipkin
$ docker-compose up
...
```
and test it
```
$ curl localhost:9411/api/v1/services
["zipkin-query"]
```
The app might fail to start if mysql is not available when it needs it. If that happens you can just start it separately: just keep running `docker-compose up` until it works.
## Instrumenting Apps
Depend on [Spring Cloud Sleuth Stream](https://github.com/spring-cloud-spring-cloud-sleuth) and the rabbit binder (`spring-cloud-starter-stream-rabbit`).
Once the apps start publishing spans they will appear in the span store as well.
## Running in an IDE
You can run this app in an IDE and still use docker-compose to create the middleware:
```
$ docker-compose up rabbitmq mysql
```
The web UI cannot access the docker host though, so you have to run that separately, or just test against the query server directly on port 9411.

View File

@@ -1,5 +1,22 @@
mysql:
image: mysql
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
rabbitmq:
image: rabbitmq:management
expose:
- 5672
ports:
- 5672:5672
- 15672:15672
zipkin:
image: springio/spring-cloud-sleuth-zipkin-stream
build: .
volumes:
- ../..:/app
- ~:/home/spring
environment:
- MYSQL_HOST=mysql
- RABBIT_HOST=rabbitmq

View File

@@ -0,0 +1,89 @@
<?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>
<artifactId>spring-cloud-sleuth-sample-zipkin-stream</artifactId>
<packaging>jar</packaging>
<name>spring-cloud-sleuth-sample-zipkin-stream</name>
<description>Spring Boot Zipkin Server</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<properties>
<docker.image.prefix>springio</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<zipkin-java.version>0.1.0</zipkin-java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jmx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-local</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,15 @@
package example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;
@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinStreamServerApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(ZipkinStreamServerApplication.class, args);
}
}

View File

@@ -0,0 +1,31 @@
package example;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import example.ZipkinStreamServerApplication;
import io.zipkin.SpanStore;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ZipkinStreamServerApplication.class)
@IntegrationTest({ "server.port=0", "spring.datasource.initialize=true" })
@ActiveProfiles("test")
public class ZipkinServerApplicationTests {
@Autowired
private SpanStore store;
@Test
public void contextLoads() {
int count = this.store.getServiceNames().size();
assertEquals(0, count);
}
}

View File

@@ -0,0 +1,5 @@
drop table zipkin_spans;
drop table zipkin_annotations;
drop table zipkin_binary_annotations;
drop table zipkin_dependencies;
drop table zipkin_dependency_links;

View File

@@ -10,21 +10,27 @@ Depend on [Spring Cloud Sleuth Stream](https://github.com/spring-cloud-spring-cl
## Query Server
Code is [here](https://github.com/spring-cloud-spring-cloud-sleuth/spring-cloud-sleuth-zipkin-stream).
Depend on `spring-cloud-sleuth-zipkin-stream` and enable the server:
Bind to MySQL and the same Stream service that you did in the apps (rabbit, redis, kafka). Set `spring.datasource.initialize=true` the first time you start to initialize the database. Alternatively, curl it:
```java
@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinStreamServerApplication {
```
$ curl zipkin-server.cfapps.io/env -d endpoints.restart.enabled=true
$ curl zipkin-server.cfapps.io/env -d spring.datasource.initialize=true
$ curl zipkin-server.cfapps.io/restart -d {}
public static void main(String[] args) throws Exception {
SpringApplication.run(ZipkinStreamServerApplication.class, args);
}
}
```
Uses the `zipkin-server` jar from the [OSS](https://github.com/openzipkin/zipkin-java) as well as `spring-cloud-sleuth-stream`.
Bind to MySQL and the same Stream service that you did in the apps (rabbit, redis, kafka). Set `spring.datasource.initialize=true` the first time you start to initialize the database.
Uses the `zipkin-server` library from the [OSS](https://github.com/openzipkin/zipkin-java) as well as `spring-cloud-sleuth-stream`.
> NOTE: running in the "test" profile you don't need MySQL (the span store is in memory). You could even run in PWS without MySQL.
## Web UI
## Web UI in Cloud Foundry
Get the jar from the [OSS](https://github.com/openzipkin/zipkin) and push it:

View File

@@ -1,14 +0,0 @@
mysql:
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
volumes:
- "./conf.d:/etc/mysql/conf.d:ro"
rabbitmq:
image: rabbitmq:management
ports:
- 5672:5672
- 15672:15672

View File

@@ -19,7 +19,6 @@
<docker.image.prefix>springio</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<zipkin-java.version>0.1.0</zipkin-java.version>
</properties>
<dependencies>
@@ -28,11 +27,6 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<artifactId>objenesis</artifactId>
<groupId>org.objenesis</groupId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@@ -66,12 +60,10 @@
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-java-server</artifactId>
<version>${zipkin-java.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-java-jdbc</artifactId>
<version>${zipkin-java.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
@@ -117,13 +109,6 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>

View File

@@ -1,6 +0,0 @@
FROM frolvlad/alpine-oraclejdk8
VOLUME /tmp
ADD @project.artifactId@-@project.version@-exec.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 9411
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

View File

@@ -1,15 +0,0 @@
package org.springframework.cloud.sleuth.zipkin.stream;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinStreamServerApplication {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(ZipkinStreamServerApplication.class)
.properties("spring.config.name=zipkin-server").run(args);
}
}

View File

@@ -5,8 +5,11 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.sleuth.zipkin.stream.ZipkinServerApplicationTests.ZipkinStreamServerApplication;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -27,4 +30,15 @@ public class ZipkinServerApplicationTests {
assertEquals(0, count);
}
@SpringBootApplication
@EnableZipkinStreamServer
public static class ZipkinStreamServerApplication {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(ZipkinStreamServerApplication.class)
.profiles("test").properties("spring.datasource.initialize=true")
.run(args);
}
}
}