diff --git a/docker-compose.yml b/docker-compose.yml index 71f08c71bcc..7d2531355da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,9 +22,10 @@ zipkin-java-server: - 9410:9410 - 9411:9411 web: - image: quay.io/openzipkin/zipkin-web:1.6.0 + image: quay.io/openzipkin/zipkin-web:1.9.0 links: - zipkin-java-server:query + - zipkin-java-server:collector ports: - 8080:8080 - 9990:9990 diff --git a/maven/maven-wrapper.properties b/maven/maven-wrapper.properties index 54b75000bf1..0212e469700 100644 --- a/maven/maven-wrapper.properties +++ b/maven/maven-wrapper.properties @@ -1,3 +1,3 @@ #Maven download properties -#Tue Sep 01 07:17:40 PDT 2015 +#Tue Sep 22 22:17:47 PDT 2015 distributionUrl=https\://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip diff --git a/pom.xml b/pom.xml index acf7160b82c..1bcf8826953 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ zipkin-java-scribe zipkin-java-dependencies zipkin-java-server + zipkin-java-jdbc @@ -43,6 +44,10 @@ 4.12 3.1.0 + + 1.9.0 + 2.2.5 + 3.3.3 0.0.4 @@ -51,6 +56,10 @@ 2.4 2.10.3 2.11 + 2.6 + 2.5.2 + 1.6.6 + 1.6 Zipkin Java @@ -107,6 +116,13 @@ ${project.version} + + ${project.groupId} + zipkin-java-query + ${project.version} + tests + + ${project.groupId} zipkin-java-scribe @@ -119,6 +135,12 @@ ${project.version} + + ${project.groupId} + zipkin-java-jdbc + ${project.version} + + com.facebook.swift swift-annotations @@ -164,6 +186,50 @@ assertj-core ${assertj.version} + + + + io.zipkin + zipkin-common + ${zipkin-scala.version} + + + org.apache.thrift + libthrift + + + + + + io.zipkin + zipkin-scrooge + ${zipkin-scala.version} + + + org.apache.thrift + libthrift + + + + + + io.zipkin + zipkin-common + ${zipkin-scala.version} + test + + + org.apache.thrift + libthrift + + + + + + org.scalatest + scalatest_2.10 + ${scalatest.version} + @@ -206,6 +272,11 @@ maven-shade-plugin ${maven-shade-plugin.version} + + + maven-jar-plugin + ${maven-jar-plugin.version} + @@ -253,7 +324,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.6 + ${nexus-staging-maven-plugin.version} true ossrh @@ -263,9 +334,8 @@ - org.apache.maven.plugins maven-release-plugin - 2.5 + ${maven-release-plugin.version} true false @@ -317,7 +387,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + ${maven-gpg-plugin.version} sign-artifacts @@ -328,7 +398,6 @@ - diff --git a/zipkin-java-core/src/main/java/io/zipkin/BinaryAnnotation.java b/zipkin-java-core/src/main/java/io/zipkin/BinaryAnnotation.java index eb85bc475cf..06f170c79ef 100644 --- a/zipkin-java-core/src/main/java/io/zipkin/BinaryAnnotation.java +++ b/zipkin-java-core/src/main/java/io/zipkin/BinaryAnnotation.java @@ -39,6 +39,28 @@ public enum Type { public int value() { return value; } + + /** Returns {@link Type#BYTES} if unknown. */ + public static Type fromValue(int value) { + switch (value) { + case 0: + return BOOL; + case 1: + return BYTES; + case 2: + return I16; + case 3: + return I32; + case 4: + return I64; + case 5: + return DOUBLE; + case 6: + return STRING; + default: + return BYTES; + } + } } public static Builder builder() { diff --git a/zipkin-java-jdbc/README.md b/zipkin-java-jdbc/README.md new file mode 100644 index 00000000000..04f74fc6261 --- /dev/null +++ b/zipkin-java-jdbc/README.md @@ -0,0 +1,21 @@ +# zipkin-java-jdbc + +## Applying the schema + +```bash +# Barracuda supports compression (In AWS RDS, this must be assigned in a parameter group) +$ mysql -uroot -e "SET GLOBAL innodb_file_format=Barracuda" +# This command should work even in RDS, and return "Barracuda" +$ mysql -uroot -e "show global variables like 'innodb_file_format'" + +# install the schema and indexes +$ mysql -uroot -e "create database if not exists zipkin" +$ mysql -uroot -Dzipkin < zipkin-java-jdbc/src/main/resources/mysql.sql +``` + +## Generating the schema types + +```bash +$ rm -rf zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/ +$ ./mvnw -pl zipkin-java-jdbc clean org.jooq:jooq-codegen-maven:generate com.mycila:license-maven-plugin:format +``` diff --git a/zipkin-java-jdbc/pom.xml b/zipkin-java-jdbc/pom.xml new file mode 100644 index 00000000000..47fbae343c7 --- /dev/null +++ b/zipkin-java-jdbc/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + + io.zipkin + zipkin-java + 0.1.0-SNAPSHOT + + + zipkin-java-jdbc + Zipkin Java JDBC Model + Zipkin Java JDBC Model + + + 3.6.3 + 5.1.36 + + + + + ${project.groupId} + zipkin-java-query + + + ${project.groupId} + zipkin-java-dependencies + + + org.jooq + jooq + ${jooq.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + + + + + + org.jooq + jooq-codegen-maven + ${jooq.version} + + + + generate + + + + + + org.jooq + jooq + ${jooq.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + + + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/zipkin + root + + + + + false + false + false + false> + + + org.jooq.util.mysql.MySQLDatabase + .* + + zipkin + + + io.zipkin.jdbc.internal.generated + src/main/java + + + + + + + + diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/JDBCZipkinQuery.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/JDBCZipkinQuery.java new file mode 100644 index 00000000000..549752ce3ec --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/JDBCZipkinQuery.java @@ -0,0 +1,309 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package io.zipkin.jdbc; + +import com.google.auto.value.AutoValue; +import io.zipkin.Annotation; +import io.zipkin.BinaryAnnotation; +import io.zipkin.Constants; +import io.zipkin.Endpoint; +import io.zipkin.Span; +import io.zipkin.Trace; +import io.zipkin.internal.Nullable; +import io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations; +import io.zipkin.query.QueryException; +import io.zipkin.query.QueryRequest; +import io.zipkin.query.ZipkinQuery; +import java.nio.charset.Charset; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import javax.sql.DataSource; +import org.jooq.DSLContext; +import org.jooq.InsertSetMoreStep; +import org.jooq.Query; +import org.jooq.Record; +import org.jooq.SelectConditionStep; +import org.jooq.Table; +import org.jooq.impl.DSL; + +import static io.zipkin.BinaryAnnotation.Type.STRING; +import static io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations.ZIPKIN_ANNOTATIONS; +import static io.zipkin.jdbc.internal.generated.tables.ZipkinSpans.ZIPKIN_SPANS; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; +import static java.util.stream.Collectors.groupingBy; + +public final class JDBCZipkinQuery implements ZipkinQuery, Consumer> { + private static final Charset UTF_8 = Charset.forName("UTF-8"); + { + System.setProperty("org.jooq.no-logo", "true"); + } + + private final DataSource datasource; + + public JDBCZipkinQuery(DataSource datasource) { + this.datasource = datasource; + } + + void clear() throws SQLException { + try (Connection conn = datasource.getConnection()) { + DSL.using(conn).truncate(ZIPKIN_SPANS).execute(); + DSL.using(conn).truncate(ZIPKIN_ANNOTATIONS).execute(); + } + } + + @Override + public void accept(List spans) { + try (Connection conn = datasource.getConnection()) { + DSLContext create = DSL.using(conn); + + List inserts = new ArrayList<>(); + + for (Span span : spans) { + Long createdTs = span.annotations().stream() + .map(Annotation::timestamp) + .min(Comparator.naturalOrder()).orElse(null); + + inserts.add(create.insertInto(ZIPKIN_SPANS) + .set(ZIPKIN_SPANS.TRACE_ID, span.traceId()) + .set(ZIPKIN_SPANS.ID, span.id()) + .set(ZIPKIN_SPANS.NAME, span.name()) + .set(ZIPKIN_SPANS.PARENT_ID, span.parentId()) + .set(ZIPKIN_SPANS.DEBUG, span.debug()) + .set(ZIPKIN_SPANS.FIRST_TIMESTAMP, createdTs) + .onDuplicateKeyIgnore() + ); + + for (Annotation annotation : span.annotations()) { + InsertSetMoreStep insert = create.insertInto(ZIPKIN_ANNOTATIONS) + .set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId()) + .set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id()) + .set(ZIPKIN_ANNOTATIONS.KEY, annotation.value()) + .set(ZIPKIN_ANNOTATIONS.TYPE, -1) + .set(ZIPKIN_ANNOTATIONS.TIMESTAMP, annotation.timestamp()); + if (annotation.host() != null) { + insert.set(ZIPKIN_ANNOTATIONS.HOST_IPV4, annotation.host().ipv4()); + insert.set(ZIPKIN_ANNOTATIONS.HOST_PORT, annotation.host().port()); + insert.set(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME, annotation.host().serviceName()); + } + inserts.add(insert.onDuplicateKeyIgnore()); + } + + for (BinaryAnnotation annotation : span.binaryAnnotations()) { + InsertSetMoreStep insert = create.insertInto(ZIPKIN_ANNOTATIONS) + .set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId()) + .set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id()) + .set(ZIPKIN_ANNOTATIONS.KEY, annotation.key()) + .set(ZIPKIN_ANNOTATIONS.VALUE, annotation.value()) + .set(ZIPKIN_ANNOTATIONS.TYPE, annotation.type().value()) + .set(ZIPKIN_ANNOTATIONS.TIMESTAMP, createdTs); + if (annotation.host() != null) { + insert.set(ZIPKIN_ANNOTATIONS.HOST_IPV4, annotation.host().ipv4()); + insert.set(ZIPKIN_ANNOTATIONS.HOST_PORT, annotation.host().port()); + insert.set(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME, annotation.host().serviceName()); + } + inserts.add(insert.onDuplicateKeyIgnore()); + } + } + create.batch(inserts).execute(); + } catch (SQLException e) { + throw new RuntimeException(e); // TODO + } + } + + @Override public List getTraces(QueryRequest request) throws QueryException { + return getTraces(request, null, request.adjustClockSkew()); + } + + private List getTraces(@Nullable QueryRequest request, @Nullable List traceIds, + boolean adjustClockSkew) { + final Map> spansWithoutAnnotations; + final Map> dbAnnotations; + try (Connection conn = datasource.getConnection()) { + + final SelectConditionStep dsl; + if (request == null) { + dsl = DSL.using(conn).selectFrom(ZIPKIN_SPANS).where(ZIPKIN_SPANS.TRACE_ID.in(traceIds)); + } else { + dsl = toSelectCondition(DSL.using(conn), request); + } + spansWithoutAnnotations = dsl + .orderBy(ZIPKIN_SPANS.FIRST_TIMESTAMP.asc()) + .fetchGroups(ZIPKIN_SPANS.TRACE_ID, r -> Span.builder() + .traceId(r.getValue(ZIPKIN_ANNOTATIONS.TRACE_ID)) + .name(r.getValue(ZIPKIN_SPANS.NAME)) + .id(r.getValue(ZIPKIN_SPANS.ID)) + .parentId(r.getValue(ZIPKIN_SPANS.PARENT_ID)) + .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) + .annotations(emptyList()) + .binaryAnnotations(emptyList()) + .build()); + + dbAnnotations = DSL.using(conn) + .selectFrom(ZIPKIN_ANNOTATIONS) + .where(ZIPKIN_ANNOTATIONS.TRACE_ID.in(spansWithoutAnnotations.keySet())) + .orderBy(ZIPKIN_ANNOTATIONS.TIMESTAMP.asc()) + .fetch() + .stream() + .collect(groupingBy(a -> SpanKey.create( + a.getValue(ZIPKIN_ANNOTATIONS.TRACE_ID), + a.getValue(ZIPKIN_ANNOTATIONS.SPAN_ID) + ))); + } catch (SQLException e) { + throw new QueryException("Error querying for " + request + ": " + e.getMessage()); + } + + List result = new ArrayList<>(spansWithoutAnnotations.keySet().size()); + for (List spans : spansWithoutAnnotations.values()) { + List trace = new ArrayList<>(spans.size()); + for (Span s : spans) { + Span.Builder span = Span.builder(s); + SpanKey key = SpanKey.create(s.traceId(), s.id()); + + if (dbAnnotations.containsKey(key)) { + List annotations = new ArrayList<>(); + List binaryAnnotations = new ArrayList<>(); + for (Record a : dbAnnotations.get(key)) { + Endpoint host = host(a); + int type = a.getValue(ZIPKIN_ANNOTATIONS.TYPE); + if (type == -1) { + annotations.add(Annotation.builder() + .value(a.getValue(ZIPKIN_ANNOTATIONS.KEY)) + .timestamp(a.getValue(ZIPKIN_ANNOTATIONS.TIMESTAMP)) + .host(host) + .build() + ); + } else { + binaryAnnotations.add(BinaryAnnotation.builder() + .key(a.getValue(ZIPKIN_ANNOTATIONS.KEY)) + .value(a.getValue(ZIPKIN_ANNOTATIONS.VALUE)) + .type(BinaryAnnotation.Type.fromValue(type)) + .host(host) + .build()); + } + } + span.annotations(annotations); + span.binaryAnnotations(binaryAnnotations); + } + trace.add(span.build()); + } + result.add(Trace.create(trace)); + } + return result; + } + + @Override + public List getTracesByIds(List traceIds, boolean adjustClockSkew) + throws QueryException { + return traceIds.isEmpty() ? emptyList() : getTraces(null, traceIds, adjustClockSkew); + } + + @Override + public Set getServiceNames() throws QueryException { + try (Connection conn = datasource.getConnection()) { + return DSL.using(conn) + .selectDistinct(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME) + .from(ZIPKIN_ANNOTATIONS) + .where(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME.isNotNull()) + .fetchSet(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME); + } catch (SQLException e) { + throw new QueryException("Error querying for " + e + ": " + e.getMessage()); + } + } + + @Override + public Set getSpanNames(String serviceName) throws QueryException { + if (serviceName == null) return emptySet(); + try (Connection conn = datasource.getConnection()) { + return DSL.using(conn) + .selectDistinct(ZIPKIN_SPANS.NAME) + .from(ZIPKIN_SPANS) + .join(ZIPKIN_ANNOTATIONS) + .on(ZIPKIN_SPANS.TRACE_ID.eq(ZIPKIN_ANNOTATIONS.TRACE_ID)) + .and(ZIPKIN_SPANS.ID.eq(ZIPKIN_ANNOTATIONS.SPAN_ID)) + .where(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME.eq(serviceName)) + .fetchSet(ZIPKIN_SPANS.NAME); + } catch (SQLException e) { + throw new QueryException("Error querying for " + serviceName + ": " + e.getMessage()); + } + } + + @AutoValue + static abstract class SpanKey { + + abstract long traceId(); + + abstract long spanId(); + + static SpanKey create(long traceId, long spanId) { + return new AutoValue_JDBCZipkinQuery_SpanKey(traceId, spanId); + } + } + + static Endpoint host(Record a) { + String serviceName = a.getValue(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME); + return serviceName != null ? Endpoint.builder() + .ipv4(a.getValue(ZIPKIN_ANNOTATIONS.HOST_IPV4)) + .port(a.getValue(ZIPKIN_ANNOTATIONS.HOST_PORT)) + .serviceName(serviceName).build() : null; + } + + static SelectConditionStep toSelectCondition(DSLContext context, QueryRequest request) { + long endTs = (request.endTs() > 0 && request.endTs() != Long.MAX_VALUE) ? request.endTs() + : System.currentTimeMillis() / 1000; + + Map binaryAnnotations = + request.binaryAnnotations() != null ? request.binaryAnnotations() : Collections.emptyMap(); + + Table table = ZIPKIN_SPANS.join(ZIPKIN_ANNOTATIONS) + .on(ZIPKIN_SPANS.TRACE_ID.eq(ZIPKIN_ANNOTATIONS.TRACE_ID)) + .and(ZIPKIN_SPANS.ID.eq(ZIPKIN_ANNOTATIONS.SPAN_ID)); + + for (String key : binaryAnnotations.keySet()) { + ZipkinAnnotations joinTable = ZIPKIN_ANNOTATIONS.as(key); + table = table.join(joinTable) + .on(ZIPKIN_SPANS.TRACE_ID.eq(joinTable.TRACE_ID)) + .and(ZIPKIN_SPANS.ID.eq(joinTable.SPAN_ID)) + .and(joinTable.TYPE.eq(STRING.value())) + .and(joinTable.KEY.eq(key)); + } + + SelectConditionStep dsl = context.select(ZIPKIN_SPANS.fields()).from(table) + .where(ZIPKIN_ANNOTATIONS.HOST_SERVICE_NAME.eq(request.serviceName())) + .and(ZIPKIN_SPANS.FIRST_TIMESTAMP.lessThan(endTs)); + + if (request.spanName() != null) { + dsl.and(ZIPKIN_SPANS.NAME.eq(request.spanName())); + } + + if (request.annotations() != null && !request.annotations().isEmpty()) { + List filtered = new ArrayList<>(request.annotations()); + filtered.removeAll(Constants.CORE_ANNOTATIONS); // don't return core annotations + dsl = dsl.and(ZIPKIN_ANNOTATIONS.KEY.in(filtered)).and(ZIPKIN_ANNOTATIONS.TYPE.eq(-1)); + } + + for (Map.Entry entry : binaryAnnotations.entrySet()) { + dsl = dsl.and(ZIPKIN_ANNOTATIONS.as(entry.getKey()).VALUE + .eq(entry.getValue().getBytes(UTF_8))); + } + return dsl; + } +} \ No newline at end of file diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Tables.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Tables.java new file mode 100644 index 00000000000..2ecd830764b --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Tables.java @@ -0,0 +1,60 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated; + + +import io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations; +import io.zipkin.jdbc.internal.generated.tables.ZipkinDependencies; +import io.zipkin.jdbc.internal.generated.tables.ZipkinDependencyLinks; +import io.zipkin.jdbc.internal.generated.tables.ZipkinSpans; + +import javax.annotation.Generated; + + +/** + * Convenience access to all tables in zipkin + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Tables { + + /** + * The table zipkin.zipkin_annotations + */ + public static final ZipkinAnnotations ZIPKIN_ANNOTATIONS = io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations.ZIPKIN_ANNOTATIONS; + + /** + * The table zipkin.zipkin_dependencies + */ + public static final ZipkinDependencies ZIPKIN_DEPENDENCIES = io.zipkin.jdbc.internal.generated.tables.ZipkinDependencies.ZIPKIN_DEPENDENCIES; + + /** + * The table zipkin.zipkin_dependency_links + */ + public static final ZipkinDependencyLinks ZIPKIN_DEPENDENCY_LINKS = io.zipkin.jdbc.internal.generated.tables.ZipkinDependencyLinks.ZIPKIN_DEPENDENCY_LINKS; + + /** + * The table zipkin.zipkin_spans + */ + public static final ZipkinSpans ZIPKIN_SPANS = io.zipkin.jdbc.internal.generated.tables.ZipkinSpans.ZIPKIN_SPANS; +} diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Zipkin.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Zipkin.java new file mode 100644 index 00000000000..60ee5c0de22 --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/Zipkin.java @@ -0,0 +1,76 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated; + + +import io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations; +import io.zipkin.jdbc.internal.generated.tables.ZipkinDependencies; +import io.zipkin.jdbc.internal.generated.tables.ZipkinDependencyLinks; +import io.zipkin.jdbc.internal.generated.tables.ZipkinSpans; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Table; +import org.jooq.impl.SchemaImpl; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Zipkin extends SchemaImpl { + + private static final long serialVersionUID = -993092949; + + /** + * The reference instance of zipkin + */ + public static final Zipkin ZIPKIN = new Zipkin(); + + /** + * No further instances allowed + */ + private Zipkin() { + super("zipkin"); + } + + @Override + public final List> getTables() { + List result = new ArrayList(); + result.addAll(getTables0()); + return result; + } + + private final List> getTables0() { + return Arrays.>asList( + ZipkinAnnotations.ZIPKIN_ANNOTATIONS, + ZipkinDependencies.ZIPKIN_DEPENDENCIES, + ZipkinDependencyLinks.ZIPKIN_DEPENDENCY_LINKS, + ZipkinSpans.ZIPKIN_SPANS); + } +} diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinAnnotations.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinAnnotations.java new file mode 100644 index 00000000000..e82d10aed9c --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinAnnotations.java @@ -0,0 +1,140 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated.tables; + + +import io.zipkin.jdbc.internal.generated.Zipkin; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class ZipkinAnnotations extends TableImpl { + + private static final long serialVersionUID = -1070710326; + + /** + * The reference instance of zipkin.zipkin_annotations + */ + public static final ZipkinAnnotations ZIPKIN_ANNOTATIONS = new ZipkinAnnotations(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return Record.class; + } + + /** + * The column zipkin.zipkin_annotations.trace_id. coincides with zipkin_spans.trace_id + */ + public final TableField TRACE_ID = createField("trace_id", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, "coincides with zipkin_spans.trace_id"); + + /** + * The column zipkin.zipkin_annotations.span_id. coincides with zipkin_spans.span_id + */ + public final TableField SPAN_ID = createField("span_id", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, "coincides with zipkin_spans.span_id"); + + /** + * The column zipkin.zipkin_annotations.key. BinaryAnnotation.key() or Annotation.value() if a_type == -1 + */ + public final TableField KEY = createField("key", org.jooq.impl.SQLDataType.VARCHAR.length(255).nullable(false), this, "BinaryAnnotation.key() or Annotation.value() if a_type == -1"); + + /** + * The column zipkin.zipkin_annotations.value. BinaryAnnotation.value(), which must be smaller than 64KB + */ + public final TableField VALUE = createField("value", org.jooq.impl.SQLDataType.BLOB, this, "BinaryAnnotation.value(), which must be smaller than 64KB"); + + /** + * The column zipkin.zipkin_annotations.type. BinaryAnnotation.type() or -1 if Annotation + */ + public final TableField TYPE = createField("type", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "BinaryAnnotation.type() or -1 if Annotation"); + + /** + * The column zipkin.zipkin_annotations.timestamp. Used to implement TTL; Annotation.timestamp() or zipkin_spans.timestamp_micros + */ + public final TableField TIMESTAMP = createField("timestamp", org.jooq.impl.SQLDataType.BIGINT, this, "Used to implement TTL; Annotation.timestamp() or zipkin_spans.timestamp_micros"); + + /** + * The column zipkin.zipkin_annotations.host_ipv4. Null when Binary/Annotation.host() is null + */ + public final TableField HOST_IPV4 = createField("host_ipv4", org.jooq.impl.SQLDataType.INTEGER, this, "Null when Binary/Annotation.host() is null"); + + /** + * The column zipkin.zipkin_annotations.host_port. Null when Binary/Annotation.host() is null + */ + public final TableField HOST_PORT = createField("host_port", org.jooq.impl.SQLDataType.SMALLINT, this, "Null when Binary/Annotation.host() is null"); + + /** + * The column zipkin.zipkin_annotations.host_service_name. Null when Binary/Annotation.host() is null + */ + public final TableField HOST_SERVICE_NAME = createField("host_service_name", org.jooq.impl.SQLDataType.VARCHAR.length(255), this, "Null when Binary/Annotation.host() is null"); + + /** + * Create a zipkin.zipkin_annotations table reference + */ + public ZipkinAnnotations() { + this("zipkin_annotations", null); + } + + /** + * Create an aliased zipkin.zipkin_annotations table reference + */ + public ZipkinAnnotations(String alias) { + this(alias, ZIPKIN_ANNOTATIONS); + } + + private ZipkinAnnotations(String alias, Table aliased) { + this(alias, aliased, null); + } + + private ZipkinAnnotations(String alias, Table aliased, Field[] parameters) { + super(alias, Zipkin.ZIPKIN, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public ZipkinAnnotations as(String alias) { + return new ZipkinAnnotations(alias, this); + } + + /** + * Rename this table + */ + public ZipkinAnnotations rename(String name) { + return new ZipkinAnnotations(name, null); + } +} diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencies.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencies.java new file mode 100644 index 00000000000..be88e5f0849 --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencies.java @@ -0,0 +1,110 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated.tables; + + +import io.zipkin.jdbc.internal.generated.Zipkin; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class ZipkinDependencies extends TableImpl { + + private static final long serialVersionUID = -1158801801; + + /** + * The reference instance of zipkin.zipkin_dependencies + */ + public static final ZipkinDependencies ZIPKIN_DEPENDENCIES = new ZipkinDependencies(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return Record.class; + } + + /** + * The column zipkin.zipkin_dependencies.dlid. + */ + public final TableField DLID = createField("dlid", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependencies.start_ts. + */ + public final TableField START_TS = createField("start_ts", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependencies.end_ts. + */ + public final TableField END_TS = createField("end_ts", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * Create a zipkin.zipkin_dependencies table reference + */ + public ZipkinDependencies() { + this("zipkin_dependencies", null); + } + + /** + * Create an aliased zipkin.zipkin_dependencies table reference + */ + public ZipkinDependencies(String alias) { + this(alias, ZIPKIN_DEPENDENCIES); + } + + private ZipkinDependencies(String alias, Table aliased) { + this(alias, aliased, null); + } + + private ZipkinDependencies(String alias, Table aliased, Field[] parameters) { + super(alias, Zipkin.ZIPKIN, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public ZipkinDependencies as(String alias) { + return new ZipkinDependencies(alias, this); + } + + /** + * Rename this table + */ + public ZipkinDependencies rename(String name) { + return new ZipkinDependencies(name, null); + } +} diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencyLinks.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencyLinks.java new file mode 100644 index 00000000000..8ec9a5c167f --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinDependencyLinks.java @@ -0,0 +1,135 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated.tables; + + +import io.zipkin.jdbc.internal.generated.Zipkin; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class ZipkinDependencyLinks extends TableImpl { + + private static final long serialVersionUID = -2120591302; + + /** + * The reference instance of zipkin.zipkin_dependency_links + */ + public static final ZipkinDependencyLinks ZIPKIN_DEPENDENCY_LINKS = new ZipkinDependencyLinks(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return Record.class; + } + + /** + * The column zipkin.zipkin_dependency_links.dlid. + */ + public final TableField DLID = createField("dlid", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.parent. + */ + public final TableField PARENT = createField("parent", org.jooq.impl.SQLDataType.VARCHAR.length(255).nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.child. + */ + public final TableField CHILD = createField("child", org.jooq.impl.SQLDataType.VARCHAR.length(255).nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.m0. + */ + public final TableField M0 = createField("m0", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.m1. + */ + public final TableField M1 = createField("m1", org.jooq.impl.SQLDataType.DOUBLE.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.m2. + */ + public final TableField M2 = createField("m2", org.jooq.impl.SQLDataType.DOUBLE.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.m3. + */ + public final TableField M3 = createField("m3", org.jooq.impl.SQLDataType.DOUBLE.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_dependency_links.m4. + */ + public final TableField M4 = createField("m4", org.jooq.impl.SQLDataType.DOUBLE.nullable(false), this, ""); + + /** + * Create a zipkin.zipkin_dependency_links table reference + */ + public ZipkinDependencyLinks() { + this("zipkin_dependency_links", null); + } + + /** + * Create an aliased zipkin.zipkin_dependency_links table reference + */ + public ZipkinDependencyLinks(String alias) { + this(alias, ZIPKIN_DEPENDENCY_LINKS); + } + + private ZipkinDependencyLinks(String alias, Table aliased) { + this(alias, aliased, null); + } + + private ZipkinDependencyLinks(String alias, Table aliased, Field[] parameters) { + super(alias, Zipkin.ZIPKIN, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public ZipkinDependencyLinks as(String alias) { + return new ZipkinDependencyLinks(alias, this); + } + + /** + * Rename this table + */ + public ZipkinDependencyLinks rename(String name) { + return new ZipkinDependencyLinks(name, null); + } +} diff --git a/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinSpans.java b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinSpans.java new file mode 100644 index 00000000000..3d5678e2cdf --- /dev/null +++ b/zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/internal/generated/tables/ZipkinSpans.java @@ -0,0 +1,125 @@ +/** + * Copyright 2015 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +/** + * This class is generated by jOOQ + */ +package io.zipkin.jdbc.internal.generated.tables; + + +import io.zipkin.jdbc.internal.generated.Zipkin; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.6.3" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class ZipkinSpans extends TableImpl { + + private static final long serialVersionUID = -286727833; + + /** + * The reference instance of zipkin.zipkin_spans + */ + public static final ZipkinSpans ZIPKIN_SPANS = new ZipkinSpans(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return Record.class; + } + + /** + * The column zipkin.zipkin_spans.trace_id. + */ + public final TableField TRACE_ID = createField("trace_id", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_spans.id. + */ + public final TableField ID = createField("id", org.jooq.impl.SQLDataType.BIGINT.nullable(false), this, ""); + + /** + * The column zipkin.zipkin_spans.name. + */ + public final TableField NAME = createField("name", org.jooq.impl.SQLDataType.VARCHAR.length(255).nullable(false), this, ""); + + /** + * The column zipkin.zipkin_spans.parent_id. + */ + public final TableField PARENT_ID = createField("parent_id", org.jooq.impl.SQLDataType.BIGINT, this, ""); + + /** + * The column zipkin.zipkin_spans.debug. + */ + public final TableField DEBUG = createField("debug", org.jooq.impl.SQLDataType.BIT, this, ""); + + /** + * The column zipkin.zipkin_spans.first_timestamp. Used to implement TTL; First Annotation.timestamp() or null + */ + public final TableField FIRST_TIMESTAMP = createField("first_timestamp", org.jooq.impl.SQLDataType.BIGINT, this, "Used to implement TTL; First Annotation.timestamp() or null"); + + /** + * Create a zipkin.zipkin_spans table reference + */ + public ZipkinSpans() { + this("zipkin_spans", null); + } + + /** + * Create an aliased zipkin.zipkin_spans table reference + */ + public ZipkinSpans(String alias) { + this(alias, ZIPKIN_SPANS); + } + + private ZipkinSpans(String alias, Table aliased) { + this(alias, aliased, null); + } + + private ZipkinSpans(String alias, Table aliased, Field[] parameters) { + super(alias, Zipkin.ZIPKIN, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public ZipkinSpans as(String alias) { + return new ZipkinSpans(alias, this); + } + + /** + * Rename this table + */ + public ZipkinSpans rename(String name) { + return new ZipkinSpans(name, null); + } +} diff --git a/zipkin-java-jdbc/src/main/resources/mysql.sql b/zipkin-java-jdbc/src/main/resources/mysql.sql new file mode 100644 index 00000000000..acd1ebb1876 --- /dev/null +++ b/zipkin-java-jdbc/src/main/resources/mysql.sql @@ -0,0 +1,52 @@ +CREATE TABLE IF NOT EXISTS zipkin_spans ( + `trace_id` BIGINT NOT NULL, + `id` BIGINT NOT NULL, + `name` VARCHAR(255) NOT NULL, + `parent_id` BIGINT, + `debug` BIT(1), + `first_timestamp` BIGINT COMMENT 'Used to implement TTL; First Annotation.timestamp() or null' +) ENGINE=InnoDB ROW_FORMAT=COMPRESSED; + +ALTER TABLE zipkin_spans ADD KEY(`trace_id`, `id`) COMMENT 'ignore insert on duplicate'; +ALTER TABLE zipkin_spans ADD INDEX(`trace_id`, `id`) COMMENT 'for joining with zipkin_annotations'; +ALTER TABLE zipkin_spans ADD INDEX(`trace_id`) COMMENT 'for getTracesByIds'; +ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames'; +ALTER TABLE zipkin_spans ADD INDEX(`first_timestamp`) COMMENT 'for getTraces ordering'; + +CREATE TABLE IF NOT EXISTS zipkin_annotations ( + `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id', + `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.span_id', + `key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key() or Annotation.value() if a_type == -1', + `value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB', + `type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation', + `timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp() or zipkin_spans.timestamp_micros', + `host_ipv4` INT COMMENT 'Null when Binary/Annotation.host() is null', + `host_port` SMALLINT COMMENT 'Null when Binary/Annotation.host() is null', + `host_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.host() is null' +) ENGINE=InnoDB ROW_FORMAT=COMPRESSED; + +ALTER TABLE zipkin_annotations ADD KEY(`trace_id`, `span_id`, `key`) COMMENT 'Ignore insert on duplicate'; +ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans'; +ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`) COMMENT 'for getTraces/ByIds'; +ALTER TABLE zipkin_annotations ADD INDEX(`host_service_name`) COMMENT 'for getTraces and getServiceNames'; +ALTER TABLE zipkin_annotations ADD INDEX(`type`) COMMENT 'for getTraces'; +ALTER TABLE zipkin_annotations ADD INDEX(`key`) COMMENT 'for getTraces'; +ALTER TABLE zipkin_annotations ADD INDEX(`host_ipv4`) COMMENT 'for getTraces ordering'; + +CREATE TABLE IF NOT EXISTS zipkin_dependencies ( + dlid BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + start_ts BIGINT NOT NULL, + end_ts BIGINT NOT NULL +) ENGINE=InnoDB; /* Not compressed as all numbers */ + +CREATE TABLE IF NOT EXISTS zipkin_dependency_links ( + dlid BIGINT NOT NULL, + parent VARCHAR(255) NOT NULL, + child VARCHAR(255) NOT NULL, + m0 BIGINT NOT NULL, + m1 DOUBLE PRECISION NOT NULL, + m2 DOUBLE PRECISION NOT NULL, + m3 DOUBLE PRECISION NOT NULL, + m4 DOUBLE PRECISION NOT NULL +) ENGINE=InnoDB ROW_FORMAT=COMPRESSED; + diff --git a/zipkin-java-query/pom.xml b/zipkin-java-query/pom.xml index b207667cea2..b7cbbad3ffa 100644 --- a/zipkin-java-query/pom.xml +++ b/zipkin-java-query/pom.xml @@ -29,12 +29,6 @@ Zipkin Java Query Zipkin Java Query - - - 1.9.0 - 2.2.5 - - ${project.groupId} @@ -56,48 +50,41 @@ io.zipkin zipkin-common - ${zipkin-scala.version} + test test - - - org.apache.thrift - libthrift - - io.zipkin zipkin-scrooge - ${zipkin-scala.version} test - - - org.apache.thrift - libthrift - - io.zipkin zipkin-common - ${zipkin-scala.version} - test test - - - org.apache.thrift - libthrift - - org.scalatest scalatest_2.10 - ${scalatest.version} test + + + + + maven-jar-plugin + + + + test-jar + + + + + + diff --git a/zipkin-java-server/Dockerfile b/zipkin-java-server/Dockerfile index db72678abb8..811c78c29a1 100644 --- a/zipkin-java-server/Dockerfile +++ b/zipkin-java-server/Dockerfile @@ -12,7 +12,7 @@ # the License. # -FROM quay.io/openzipkin/zipkin-base:base-1.6.0 +FROM quay.io/openzipkin/zipkin-base:base-1.9.0 MAINTAINER OpenZipkin "http://zipkin.io/" diff --git a/zipkin-java-server/dependency-reduced-pom.xml b/zipkin-java-server/dependency-reduced-pom.xml index d633ae4da49..6011500a6a5 100644 --- a/zipkin-java-server/dependency-reduced-pom.xml +++ b/zipkin-java-server/dependency-reduced-pom.xml @@ -75,7 +75,11 @@ + 1.7.12 + 2.4.2 1.4.1 + 5.1.36 + 2.1.1 diff --git a/zipkin-java-server/pom.xml b/zipkin-java-server/pom.xml index 43610cf24bb..387313383a5 100644 --- a/zipkin-java-server/pom.xml +++ b/zipkin-java-server/pom.xml @@ -30,6 +30,11 @@ Zipkin Server + 5.1.36 + 1.7.12 + + 2.4.2 + 2.1.1 1.4.1 @@ -44,6 +49,11 @@ zipkin-java-scribe + + ${project.groupId} + zipkin-java-jdbc + + ${project.groupId} swift-codec @@ -53,6 +63,25 @@ com.facebook.swift swift-service + + + org.slf4j + slf4j-simple + ${slf4j.version} + + + + + org.apache.commons + commons-pool2 + ${commons-pool2.version} + + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + diff --git a/zipkin-java-server/src/main/java/io/zipkin/ZipkinServer.java b/zipkin-java-server/src/main/java/io/zipkin/ZipkinServer.java index 678b9abc5ad..ea3bfc9dfee 100644 --- a/zipkin-java-server/src/main/java/io/zipkin/ZipkinServer.java +++ b/zipkin-java-server/src/main/java/io/zipkin/ZipkinServer.java @@ -18,40 +18,41 @@ import com.facebook.swift.service.ThriftServer; import com.facebook.swift.service.ThriftServerConfig; import com.facebook.swift.service.ThriftServiceProcessor; +import io.zipkin.jdbc.JDBCZipkinQuery; import io.zipkin.query.InMemoryZipkinQuery; +import io.zipkin.query.ZipkinQuery; import io.zipkin.scribe.ScribeSpanConsumer; import java.io.Closeable; import java.io.IOException; import java.net.ServerSocket; +import java.util.List; +import java.util.function.Consumer; +import org.apache.commons.dbcp2.BasicDataSource; import static java.util.Collections.emptyList; -public final class ZipkinServer implements Closeable { +public final class ZipkinServer>> implements Closeable { private final int scribePort; private final int queryPort; + private final T spanStore; - public ZipkinServer() { - this(0, 0); - } - - private ZipkinServer(int scribePort, int queryPort) { + private ZipkinServer(int scribePort, int queryPort, T spanStore) { this.scribePort = scribePort; this.queryPort = queryPort; + this.spanStore = spanStore; } - InMemoryZipkinQuery mem = new InMemoryZipkinQuery(); - private ThriftServer scribe; private ThriftServer query; public void start() throws IOException { - ScribeSpanConsumer scribe = new ScribeSpanConsumer(mem::accept); + ScribeSpanConsumer scribe = new ScribeSpanConsumer(spanStore); if (scribePort == queryPort) { - this.scribe = query = startServices(scribePort, scribe, mem); + this.scribe = query = startServices(scribePort, scribe, spanStore); } else { this.scribe = startServices(scribePort, scribe); - this.query = startServices(queryPort, mem); + this.query = startServices(queryPort, spanStore); } } @@ -76,9 +77,34 @@ private static ThriftServer startServices(int port, Object... services) throws I } public static void main(String[] args) throws IOException, InterruptedException { - try (ZipkinServer rule = new ZipkinServer(9410, 9411)) { - rule.start(); + + int collectorPort = envOr("COLLECTOR_PORT", 9410); + int queryPort = envOr("QUERY_PORT", 9411); + + final ZipkinServer server; + if (System.getenv("MYSQL_HOST") != null) { + String mysqlHost = System.getenv("MYSQL_HOST"); + int mysqlPort = envOr("MYSQL_TCP_PORT", 3306); + String mysqlUser = envOr("MYSQL_USER", ""); + String mysqlPass = envOr("MYSQL_PASS", ""); + + String url = String.format("jdbc:mysql://%s:%s/zipkin?user=%s&password=%s&autoReconnect=true", + mysqlHost, mysqlPort, mysqlUser, mysqlPass); + + // TODO: replace with HikariDataSource when 2.4.2 is out + BasicDataSource datasource = new org.apache.commons.dbcp2.BasicDataSource(); + datasource.setDriverClassName("com.mysql.jdbc.Driver"); + datasource.setUrl(url); + datasource.setMaxTotal(10); + server = new ZipkinServer<>(collectorPort, queryPort, new JDBCZipkinQuery(datasource)); + } else { + server = new ZipkinServer<>(collectorPort, queryPort, new InMemoryZipkinQuery()); + } + try { + server.start(); Thread.currentThread().join(); + } finally { + server.close(); } } @@ -86,4 +112,12 @@ public static void main(String[] args) throws IOException, InterruptedException public void close() { stop(); } + + private static int envOr(String key, int fallback) { + return System.getenv(key) != null ? Integer.parseInt(System.getenv(key)) : fallback; + } + + private static String envOr(String key, String fallback) { + return System.getenv(key) != null ? System.getenv(key) : fallback; + } }