Skip to content

Commit

Permalink
Add Zipkin UI to webapp (apache#10167)
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 authored Dec 17, 2022
1 parent 0c08a65 commit 4ee8389
Show file tree
Hide file tree
Showing 17 changed files with 2,934 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ oap-server/oal-grammar/**/gen/

# This serves as a template but will ONLY be updated when building a source release tar,
# so we don't track future updates of this file.
oap-server/server-starter/src/main/resources/version.properties
oap-server/server-starter/src/main/resources/version.properties
5 changes: 5 additions & 0 deletions apm-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<dependency>
<groupId>io.zipkin</groupId>
<artifactId>zipkin-lens</artifactId>
</dependency>

<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@

import static org.yaml.snakeyaml.env.EnvScalarConstructor.ENV_FORMAT;
import static org.yaml.snakeyaml.env.EnvScalarConstructor.ENV_TAG;

import java.util.Collections;

import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.env.EnvScalarConstructor;

import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.server.HttpService;
import com.linecorp.armeria.server.Server;
Expand Down Expand Up @@ -55,12 +52,25 @@ public static void main(String[] args) throws Exception {
HttpFile
.of(ApplicationStartUp.class.getClassLoader(), "/public/index.html")
.asService();
final HttpService zipkinIndexPage =
HttpFile
.of(ApplicationStartUp.class.getClassLoader(), "/zipkin-lens/index.html")
.asService();

final ZipkinProxyService zipkin = new ZipkinProxyService(configuration.zipkinServices());

Server
.builder()
.port(port, SessionProtocol.HTTP)
.service("/graphql", new OapProxyService(oapServices))
.service("/internal/l7check", HealthCheckService.of())
.service("/zipkin/config.json", zipkin)
.serviceUnder("/zipkin/api", zipkin)
.serviceUnder("/zipkin",
FileService.of(
ApplicationStartUp.class.getClassLoader(),
"/zipkin-lens")
.orElse(zipkinIndexPage))
.serviceUnder("/",
FileService.of(
ApplicationStartUp.class.getClassLoader(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class Configuration {
private String serverPort;
private String oapServices;
private String zipkinServices;

public int port() {
return serverPort == null || serverPort.trim().length() == 0
Expand All @@ -44,4 +45,11 @@ public String[] oapServices() {
}
return oapServices.split(",");
}

public String[] zipkinServices() {
if (zipkinServices == null || zipkinServices.trim().length() == 0) {
throw new IllegalArgumentException("zipkinServices cannot be null or empty");
}
return zipkinServices.split(",");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.skywalking.oap.server.webapp;

import static java.util.stream.Collectors.toList;
import java.net.URI;
import java.util.List;
import java.util.stream.Stream;
import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.client.endpoint.EndpointGroup;
import com.linecorp.armeria.client.endpoint.EndpointSelectionStrategy;
import com.linecorp.armeria.client.logging.LoggingClient;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.server.AbstractHttpService;
import com.linecorp.armeria.server.ServiceRequestContext;
import lombok.SneakyThrows;

public final class ZipkinProxyService extends AbstractHttpService {
private final WebClient loadBalancingClient;

public ZipkinProxyService(String[] zipkinServices) throws Exception {
final List<Endpoint> endpoints =
Stream
.of(zipkinServices)
.map(URI::create)
.map(URI::getAuthority)
.map(Endpoint::parse)
.collect(toList());
loadBalancingClient = newLoadBalancingClient(
EndpointGroup.of(
EndpointSelectionStrategy.roundRobin(),
endpoints));
}

@SneakyThrows
private static WebClient newLoadBalancingClient(EndpointGroup zipkinGroup) {
return WebClient
.builder(SessionProtocol.HTTP, zipkinGroup)
.decorator(LoggingClient.newDecorator())
.build();
}

@Override
protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) throws Exception {
return loadBalancingClient.execute(req);
}
}
2 changes: 2 additions & 0 deletions apm-webapp/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ serverPort: ${SW_SERVER_PORT:-8080}

# Comma seperated list of OAP addresses.
oapServices: ${SW_OAP_ADDRESS:-http://localhost:12800}

zipkinServices: ${SW_ZIPKIN_ADDRESS:-http://localhost:9412}
4 changes: 4 additions & 0 deletions dist-material/release-docs/LICENSE
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ The text of each license is the standard Apache 2.0 license.
https://mvnrepository.com/artifact/io.vavr/vavr/0.10.3 Apache-2.0
https://mvnrepository.com/artifact/io.vavr/vavr-match/0.10.3 Apache-2.0
https://mvnrepository.com/artifact/io.zipkin.zipkin2/zipkin/2.23.16 Apache-2.0
https://mvnrepository.com/artifact/io.zipkin/zipkin-lens/2.23.16 Apache-2.0
https://mvnrepository.com/artifact/javax.inject/javax.inject/1 Apache-2.0
https://mvnrepository.com/artifact/joda-time/joda-time/2.10.5 Apache-2.0
https://mvnrepository.com/artifact/net.jodah/failsafe/2.3.4 Apache-2.0
Expand Down Expand Up @@ -637,3 +638,6 @@ The text of each license is also included in licenses/LICENSE-[project].txt.

https://mvnrepository.com/artifact/org.reactivestreams/reactive-streams/1.0.4 https://spdx.org/licenses/MIT-0.html

=======================================================================
The zipkin-lens.jar dependency has more front-end dependencies in it and the front-end dependencies' licenses
are listed in zipkin-LICENSE.
3 changes: 3 additions & 0 deletions dist-material/release-docs/LICENSE.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ The text of each license is also included in licenses/LICENSE-[project].txt.
{{- end }}
{{- end }}
{{ end }}
=======================================================================
The zipkin-lens.jar dependency has more front-end dependencies in it and the front-end dependencies' licenses
are listed in zipkin-LICENSE.
Loading

0 comments on commit 4ee8389

Please sign in to comment.