-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adaptation enhancements for various features in v3
- Loading branch information
Showing
24 changed files
with
872 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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>health-query-plugin</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.zipkin</groupId> | ||
<artifactId>zipkin-server-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
...erver/health-query-plugin/src/main/java/zipkin/server/query/health/HealthQueryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2015-2023 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 zipkin.server.query.health; | ||
|
||
import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
|
||
public class HealthQueryConfig extends ModuleConfig { | ||
} |
30 changes: 30 additions & 0 deletions
30
...erver/health-query-plugin/src/main/java/zipkin/server/query/health/HealthQueryModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2015-2023 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 zipkin.server.query.health; | ||
|
||
import org.apache.skywalking.oap.server.library.module.ModuleDefine; | ||
|
||
public class HealthQueryModule extends ModuleDefine { | ||
public static final String NAME = "query-health"; | ||
|
||
public HealthQueryModule() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public Class[] services() { | ||
return new Class[0]; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ver/health-query-plugin/src/main/java/zipkin/server/query/health/HealthQueryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2015-2023 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 zipkin.server.query.health; | ||
|
||
import com.linecorp.armeria.common.HttpMethod; | ||
import org.apache.skywalking.oap.server.core.CoreModule; | ||
import org.apache.skywalking.oap.server.core.server.HTTPHandlerRegister; | ||
import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
import org.apache.skywalking.oap.server.library.module.ModuleDefine; | ||
import org.apache.skywalking.oap.server.library.module.ModuleProvider; | ||
import org.apache.skywalking.oap.server.library.module.ModuleStartException; | ||
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; | ||
|
||
import java.util.Collections; | ||
|
||
public class HealthQueryProvider extends ModuleProvider { | ||
@Override | ||
public String name() { | ||
return "zipkin"; | ||
} | ||
|
||
@Override | ||
public Class<? extends ModuleDefine> module() { | ||
return HealthQueryModule.class; | ||
} | ||
|
||
@Override | ||
public ConfigCreator<? extends ModuleConfig> newConfigCreator() { | ||
return new ConfigCreator<HealthQueryConfig>() { | ||
@Override | ||
public Class<HealthQueryConfig> type() { | ||
return HealthQueryConfig.class; | ||
} | ||
|
||
@Override | ||
public void onInitialized(HealthQueryConfig initialized) { | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void prepare() throws ServiceNotProvidedException, ModuleStartException { | ||
} | ||
|
||
@Override | ||
public void start() throws ServiceNotProvidedException, ModuleStartException { | ||
getManager().find(CoreModule.NAME).provider() | ||
.getService(HTTPHandlerRegister.class).addHandler( | ||
new ZipkinHealthController(getManager()), | ||
Collections.singletonList(HttpMethod.GET) | ||
); | ||
} | ||
|
||
@Override | ||
public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException { | ||
} | ||
|
||
@Override | ||
public String[] requiredModules() { | ||
return new String[0]; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
zipkin-server/health-query-plugin/src/main/java/zipkin/server/query/health/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2015-2019 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 zipkin.server.query.health; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.util.DefaultIndenter; | ||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* Utilities for working with JSON. | ||
*/ | ||
public final class JsonUtil { | ||
|
||
static final JsonFactory JSON_FACTORY = new JsonFactory(); | ||
static final DefaultPrettyPrinter.Indenter TWOSPACES_LF_INDENTER = | ||
new DefaultIndenter(" ", "\n"); | ||
|
||
/** | ||
* Creates a new {@link JsonGenerator} with pretty-printing enabled forcing {@code '\n'} | ||
* between lines, as opposed to Jackson's default which uses the system line separator. | ||
*/ | ||
public static JsonGenerator createGenerator(Writer writer) throws IOException { | ||
JsonGenerator generator = JSON_FACTORY.createGenerator(writer); | ||
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter(); | ||
prettyPrinter.indentArraysWith(TWOSPACES_LF_INDENTER); | ||
prettyPrinter.indentObjectsWith(TWOSPACES_LF_INDENTER); | ||
generator.setPrettyPrinter(prettyPrinter); | ||
return generator; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
.../health-query-plugin/src/main/java/zipkin/server/query/health/ZipkinHealthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2015-2023 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 zipkin.server.query.health; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.MediaType; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
import com.linecorp.armeria.server.annotation.Get; | ||
import io.vavr.collection.Stream; | ||
import org.apache.skywalking.oap.server.library.module.ModuleManager; | ||
import org.apache.skywalking.oap.server.library.module.ModuleServiceHolder; | ||
import org.apache.skywalking.oap.server.telemetry.TelemetryModule; | ||
import org.apache.skywalking.oap.server.telemetry.api.MetricFamily; | ||
import org.apache.skywalking.oap.server.telemetry.api.MetricsCollector; | ||
import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ZipkinHealthController { | ||
static final String STATUS_UP = "UP", STATUS_DOWN = "DOWN"; | ||
|
||
final MetricsCollector collector; | ||
final private MetricsCreator metricsCreator; | ||
|
||
public static final MediaType MEDIA_TYPE_ACTUATOR = | ||
MediaType.parse("application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"); | ||
|
||
public ZipkinHealthController(ModuleManager moduleManager) { | ||
ModuleServiceHolder telemetry = moduleManager.find(TelemetryModule.NAME).provider(); | ||
metricsCreator = telemetry.getService(MetricsCreator.class); | ||
collector = telemetry.getService(MetricsCollector.class); | ||
} | ||
|
||
@Get("/actuator/health") | ||
public HttpResponse getActuatorHealth(ServiceRequestContext ctx) { | ||
return newHealthResponse(MEDIA_TYPE_ACTUATOR); | ||
} | ||
|
||
@Get("/health") | ||
public HttpResponse getHealth(ServiceRequestContext ctx) { | ||
return newHealthResponse(MediaType.JSON_UTF_8); | ||
} | ||
|
||
HttpResponse newHealthResponse(MediaType mediaType) { | ||
final Map<MetricFamily.Sample, String> componentsHealth = Stream.ofAll(collector.collect()) | ||
.flatMap(metricFamily -> metricFamily.samples) | ||
.filter(sample -> metricsCreator.isHealthCheckerMetrics(sample.name)) | ||
.collect(Collectors.toMap(t -> t, t -> t.value > 0 ? STATUS_DOWN : STATUS_UP, (a, b) -> b)); | ||
|
||
String overallStatus = STATUS_UP; | ||
for (String health : componentsHealth.values()) { | ||
if (STATUS_DOWN.equals(health)) { | ||
overallStatus = STATUS_DOWN; | ||
break; | ||
} | ||
} | ||
|
||
final String healthJson; | ||
try { | ||
healthJson = writeJson(overallStatus, componentsHealth); | ||
} catch (IOException e) { | ||
// Can't have an exception writing to a string. | ||
throw new Error(e); | ||
} | ||
return newHealthResponse(overallStatus, mediaType, healthJson); | ||
} | ||
|
||
static HttpResponse newHealthResponse(String status, MediaType mediaType, String healthJson) { | ||
HttpStatus code = status.equals(STATUS_UP) ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE; | ||
return HttpResponse.of(code, mediaType, healthJson); | ||
} | ||
|
||
static String writeJson(String overallStatus, Map<MetricFamily.Sample, String> healths) throws IOException { | ||
StringWriter writer = new StringWriter(); | ||
try (JsonGenerator generator = JsonUtil.createGenerator(writer)) { | ||
generator.writeStartObject(); | ||
generator.writeStringField("status", overallStatus); | ||
generator.writeObjectFieldStart("zipkin"); | ||
generator.writeStringField("status", overallStatus); | ||
generator.writeObjectFieldStart("details"); | ||
|
||
for (Map.Entry<MetricFamily.Sample, String> health : healths.entrySet()) { | ||
generator.writeObjectFieldStart(health.getKey().name); | ||
generator.writeStringField("status", health.getValue()); | ||
generator.writeEndObject(); // .zipkin.details.healthName | ||
} | ||
|
||
generator.writeEndObject(); // .zipkin.details | ||
generator.writeEndObject(); // .zipkin | ||
generator.writeEndObject(); // . | ||
} | ||
return writer.toString(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# 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. | ||
# | ||
# | ||
|
||
zipkin.server.query.health.HealthQueryModule |
19 changes: 19 additions & 0 deletions
19
...esources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# 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. | ||
# | ||
# | ||
|
||
zipkin.server.query.health.HealthQueryProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>http-query-plugin</artifactId> | ||
<name>Zipkin HTTP Query</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>zipkin-query-plugin</artifactId> | ||
<version>${skywalking.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Oops, something went wrong.