Skip to content

Commit

Permalink
Adaptation of Dependency Query Service in Server (#3576)
Browse files Browse the repository at this point in the history
* Support query dependency
  • Loading branch information
mrproliu authored Oct 25, 2023
1 parent e3fb5c6 commit f4d1a36
Show file tree
Hide file tree
Showing 27 changed files with 1,086 additions and 1 deletion.
5 changes: 5 additions & 0 deletions zipkin-server/http-query-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>zipkin-server-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-dependency</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class HTTPQueryConfig extends ModuleConfig {
private boolean uiEnable = true;
private String uiBasePath = "/zipkin";

private boolean dependencyEnabled = true;
private double dependencyLowErrorRate = 0.5; // 50% of calls in error turns line yellow
private double dependencyHighErrorRate = 0.75;// 75% of calls in error turns line red

public ZipkinQueryConfig toSkyWalkingConfig() {
final ZipkinQueryConfig result = new ZipkinQueryConfig();
result.setLookback(lookback);
Expand Down Expand Up @@ -188,4 +192,28 @@ public String getAllowedOrigins() {
public void setAllowedOrigins(String allowedOrigins) {
this.allowedOrigins = allowedOrigins;
}

public boolean getDependencyEnabled() {
return dependencyEnabled;
}

public void setDependencyEnabled(boolean dependencyEnabled) {
this.dependencyEnabled = dependencyEnabled;
}

public double getDependencyLowErrorRate() {
return dependencyLowErrorRate;
}

public void setDependencyLowErrorRate(double dependencyLowErrorRate) {
this.dependencyLowErrorRate = dependencyLowErrorRate;
}

public double getDependencyHighErrorRate() {
return dependencyHighErrorRate;
}

public void setDependencyHighErrorRate(double dependencyHighErrorRate) {
this.dependencyHighErrorRate = dependencyHighErrorRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,38 @@

package zipkin.server.query.http;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.linecorp.armeria.common.AggregatedHttpResponse;
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.common.ResponseHeaders;
import com.linecorp.armeria.server.annotation.Blocking;
import com.linecorp.armeria.server.annotation.Get;
import com.linecorp.armeria.server.annotation.Param;
import org.apache.skywalking.oap.query.zipkin.handler.ZipkinQueryHandler;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.IZipkinQueryDAO;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import org.apache.skywalking.oap.server.library.util.StringUtil;
import zipkin.server.dependency.IZipkinDependencyQueryDAO;
import zipkin.server.dependency.ZipkinDependencyModule;
import zipkin2.DependencyLink;
import zipkin2.Span;
import zipkin2.codec.DependencyLinkBytesEncoder;
import zipkin2.codec.SpanBytesEncoder;

import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -47,12 +58,41 @@ public class HTTPQueryHandler extends ZipkinQueryHandler {
private final ModuleManager moduleManager;

private IZipkinQueryDAO zipkinQueryDAO;
private IZipkinDependencyQueryDAO dependencyQueryDAO;
public HTTPQueryHandler(HTTPQueryConfig config, ModuleManager moduleManager) {
super(config.toSkyWalkingConfig(), moduleManager);
this.config = config;
this.moduleManager = moduleManager;
}

@Override
public AggregatedHttpResponse getUIConfig() throws IOException {
StringWriter writer = new StringWriter();
JsonGenerator generator = new JsonFactory().createGenerator(writer);
generator.writeStartObject();
generator.writeStringField("environment", config.getUiEnvironment());
generator.writeNumberField("queryLimit", config.getUiQueryLimit());
generator.writeNumberField("defaultLookback", config.getUiDefaultLookback());
generator.writeBooleanField("searchEnabled", config.getUiSearchEnabled());
generator.writeObjectFieldStart("dependency");
generator.writeBooleanField("enabled", config.getDependencyEnabled());
generator.writeNumberField("lowErrorRate", config.getDependencyLowErrorRate());
generator.writeNumberField("highErrorRate", config.getDependencyHighErrorRate());
generator.writeEndObject();
generator.writeEndObject();
generator.close();
return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, HttpData.ofUtf8(writer.toString()));
}

@Get("/api/v2/dependencies")
@Blocking
public AggregatedHttpResponse getDependencies(
@Param("endTs") long endTs,
@Param("lookback") Optional<Long> lookback) throws IOException {
final List<DependencyLink> dependencies = getDependencyQueryDAO().getDependencies(endTs, lookback.orElse(config.getLookback()));
return response(DependencyLinkBytesEncoder.JSON_V1.encodeList(dependencies));
}

@Override
public AggregatedHttpResponse getTraceById(String traceId) throws IOException {
if (StringUtil.isEmpty(traceId)) {
Expand Down Expand Up @@ -129,4 +169,11 @@ private IZipkinQueryDAO getZipkinQueryDAO() {
}
return zipkinQueryDAO;
}

public IZipkinDependencyQueryDAO getDependencyQueryDAO() {
if (dependencyQueryDAO == null) {
dependencyQueryDAO = moduleManager.find(ZipkinDependencyModule.NAME).provider().getService(IZipkinDependencyQueryDAO.class);
}
return dependencyQueryDAO;
}
}
2 changes: 2 additions & 0 deletions zipkin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<module>http-query-plugin</module>
<module>health-query-plugin</module>
<module>telemetry-zipkin</module>
<module>zipkin-dependency</module>
<module>zipkin-storage-ext</module>
</modules>

<dependencyManagement>
Expand Down
24 changes: 24 additions & 0 deletions zipkin-server/server-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@
<version>${skywalking.version}</version>
</dependency>

<!-- storage ext -->
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-dependency-storage-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-dependency-storage-elasticsearch</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-dependency-storage-banyandb</artifactId>
<version>${project.version}</version>
</dependency>

<!-- zipkin receiver -->
<dependency>
<groupId>io.zipkin</groupId>
Expand Down Expand Up @@ -112,6 +129,13 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- for mysql -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ core:
restAcceptQueueSize: ${ZIPKIN_REST_QUEUE_SIZE:0}
restMaxRequestHeaderSize: ${ZIPKIN_REST_MAX_REQUEST_HEADER_SIZE:8192}

storage:
storage: &storage
selector: ${ZIPKIN_STORAGE:h2}
elasticsearch:
namespace: ${ZIPKIN_NAMESPACE:""}
Expand Down Expand Up @@ -147,6 +147,8 @@ storage:
superDatasetSegmentIntervalDays: ${ZIPKIN_STORAGE_BANYANDB_SUPER_DATASET_SEGMENT_INTERVAL_DAYS:1} # Unit is day
specificGroupSettings: ${ZIPKIN_STORAGE_BANYANDB_SPECIFIC_GROUP_SETTINGS:""} # For example, {"group1": {"blockIntervalHours": 4, "segmentIntervalDays": 1}}

zipkin-dependency-storage-ext: *storage

receiver-zipkin-http:
selector: ${ZIPKIN_RECEIVER_ZIPKIN_HTTP:default}
default:
Expand Down Expand Up @@ -232,6 +234,9 @@ query-zipkin:
uiDefaultLookback: ${ZIPKIN_QUERY_UI_DEFAULT_LOOKBACK:900000}
uiEnable: ${ZIPKIN_QUERY_UI_ENABLE:true}
uiBasePath: ${ZIPKIN_QUERY_UI_BASE_PATH:/zipkin}
dependencyEnabled: ${ZIPKIN_QUERY_DEPENDENCY_ENABLED:true}
dependencyLowErrorRate: ${ZIPKIN_QUERY_DEPENDENCY_LOW_ERROR_RATE:0.5}
dependencyHighErrorRate: ${ZIPKIN_QUERY_DEPENDENCY_HIGH_ERROR_RATE:0.75}

query-health:
selector: ${ZIPKIN_QUERY_HEALTH:zipkin}
Expand Down
23 changes: 23 additions & 0 deletions zipkin-server/zipkin-dependency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>
<parent>
<artifactId>zipkin-server-parent</artifactId>
<groupId>io.zipkin</groupId>
<version>2.24.4-SNAPSHOT</version>
</parent>

<artifactId>zipkin-dependency</artifactId>
<name>Zipkin Dependency</name>

<dependencies>
<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-server-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit f4d1a36

Please sign in to comment.