This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push: new 6e435d80b8 refactor: simplify the `Accept` http header process (#13275) 6e435d80b8 is described below commit 6e435d80b8811fbb03d2e14292ec8da106d3ab70 Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Thu May 29 18:14:25 2025 +0800 refactor: simplify the `Accept` http header process (#13275) --- docs/en/changes/changes.md | 1 + docs/en/status/query_cluster_nodes.md | 8 ++--- .../oap/server/core/CoreModuleProvider.java | 2 +- .../server/core/status/ServerStatusService.java | 34 ++++---------------- .../oap/server/core/storage/ttl/TTLDefinition.java | 9 ++---- .../oap/query/debug/ClusterStatusQueryHandler.java | 37 ++++++++++------------ .../oap/query/debug/DebuggingHTTPHandler.java | 16 +++++----- .../oap/query/debug/TTLConfigQueryHandler.java | 18 +++++------ .../tool/profile/core/MockCoreModuleProvider.java | 2 +- 9 files changed, 48 insertions(+), 79 deletions(-) diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index bb41650abf..01899d88a3 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -25,6 +25,7 @@ * Storage: separate `SpanAttachedEventRecord` for SkyWalking trace and Zipkin trace. * [Break Change]BanyanDB: Setup new Group policy. * Bump up commons-beanutils to 1.11.0. +* Refactor: simplify the `Accept` http header process. #### UI diff --git a/docs/en/status/query_cluster_nodes.md b/docs/en/status/query_cluster_nodes.md index 17ee51cc80..4e700f6e0d 100644 --- a/docs/en/status/query_cluster_nodes.md +++ b/docs/en/status/query_cluster_nodes.md @@ -18,17 +18,17 @@ This API is used to get the unified and effective TTL configurations. { "host": "10.0.12.23", "port": 11800, - "isSelf": true + "self": true }, { "host": "10.0.12.25", "port": 11800, - "isSelf": false + "self": false }, { "host": "10.0.12.37", "port": 11800, - "isSelf": false + "self": false } ] } @@ -36,4 +36,4 @@ This API is used to get the unified and effective TTL configurations. The `nodes` list all the nodes in the cluster. The size of the list should be exactly same as your cluster setup. The `host` and `port` are the address of the OAP node, which are used for OAP nodes communicating with each other. The -`isSelf` is a flag to indicate whether the node is the current node, others are remote nodes. +`self` is a flag to indicate whether the node is the current node, others are remote nodes. diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java index 026f872ba6..a9cc8901e1 100755 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java @@ -265,7 +265,7 @@ public class CoreModuleProvider extends ModuleProvider { httpServer.initialize(); this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig, this)); - this.registerServiceImplementation(ServerStatusService.class, new ServerStatusService(getManager(), moduleConfig)); + this.registerServiceImplementation(ServerStatusService.class, new ServerStatusService(getManager())); this.registerServiceImplementation(HierarchyDefinitionService.class, new HierarchyDefinitionService(moduleConfig)); hierarchyService = new HierarchyService(getManager(), moduleConfig); this.registerServiceImplementation(HierarchyService.class, hierarchyService); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/status/ServerStatusService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/status/ServerStatusService.java index 0a498877be..a5e238e654 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/status/ServerStatusService.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/status/ServerStatusService.java @@ -18,14 +18,11 @@ package org.apache.skywalking.oap.server.core.status; -import com.google.gson.Gson; -import io.vavr.Tuple2; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.skywalking.oap.server.core.CoreModuleConfig; import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration; import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.Service; @@ -43,7 +40,6 @@ import org.apache.skywalking.oap.server.telemetry.api.MetricsTag; @RequiredArgsConstructor public class ServerStatusService implements Service { private final ModuleManager manager; - private final CoreModuleConfig moduleConfig; @Getter private BootingStatus bootingStatus = new BootingStatus(); @Getter @@ -98,7 +94,7 @@ public class ServerStatusService implements Service { for (ApplicationConfiguration.ModuleConfiguration configuration : configurations) { final String moduleName = configuration.getModuleName(); if (configuration.getProviders().size() == 1) { - configList.add(moduleName + ".provider", configuration.getProviders().keySet().iterator().next()); + configList.put(moduleName + ".provider", configuration.getProviders().keySet().iterator().next()); } configuration.getProviders().forEach( (providerName, providerConfiguration) -> @@ -109,7 +105,7 @@ public class ServerStatusService implements Service { value = "******"; } } - configList.add(moduleName + "." + providerName + "." + key, value.toString()); + configList.put(moduleName + "." + providerName + "." + key, value.toString()); } ) ); @@ -117,33 +113,17 @@ public class ServerStatusService implements Service { return configList; } - public static class ConfigList { - private final static Gson GSON = new Gson(); - private List<Tuple2> configurations = new ArrayList<>(200); - - public void add(String key, String value) { - configurations.add(new Tuple2<>(key, value)); - } - + public static class ConfigList extends HashMap<String, String> { @Override public String toString() { StringBuilder configList = new StringBuilder(); - for (Tuple2 tuple : configurations) { - configList.append(tuple._1) + for (final var entry : this.entrySet()) { + configList.append(entry.getKey()) .append("=") - .append(tuple._2) + .append(entry.getValue()) .append("\n"); } return configList.toString(); } - - public String toJsonString() { - return GSON.toJson(configurations.stream() - .collect( - java.util.stream.Collectors.toMap( - tuple -> tuple._1.toString(), - tuple -> tuple._2.toString() - ))); - } } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/ttl/TTLDefinition.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/ttl/TTLDefinition.java index 55c9c5fe8f..05b8b417a4 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/ttl/TTLDefinition.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/ttl/TTLDefinition.java @@ -18,7 +18,6 @@ package org.apache.skywalking.oap.server.core.storage.ttl; -import com.google.gson.Gson; import lombok.Data; /** @@ -26,11 +25,11 @@ import lombok.Data; */ @Data public class TTLDefinition { - private final static Gson GSON = new Gson(); private final MetricsTTL metrics; private final RecordsTTL records; - public String generateTTLDefinition() { + @Override + public String toString() { StringBuilder ttlDefinition = new StringBuilder(); ttlDefinition.append("# Metrics TTL includes the definition of the TTL of the metrics-ish data in the storage,\n"); ttlDefinition.append("# e.g.\n"); @@ -67,8 +66,4 @@ public class TTLDefinition { ttlDefinition.append("records.browserErrorLog.cold=").append(records.getColdBrowserErrorLog()).append("\n"); return ttlDefinition.toString(); } - - public String generateTTLDefinitionAsJSONStr() { - return GSON.toJson(this); - } } diff --git a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/ClusterStatusQueryHandler.java b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/ClusterStatusQueryHandler.java index ca74ad1864..3beaa4a46b 100644 --- a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/ClusterStatusQueryHandler.java +++ b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/ClusterStatusQueryHandler.java @@ -18,16 +18,18 @@ package org.apache.skywalking.oap.query.debug; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import com.linecorp.armeria.common.HttpRequest; -import com.linecorp.armeria.common.HttpResponse; -import com.linecorp.armeria.common.MediaType; import com.linecorp.armeria.server.annotation.ExceptionHandler; import com.linecorp.armeria.server.annotation.Get; +import com.linecorp.armeria.server.annotation.ProducesJson; + import lombok.extern.slf4j.Slf4j; + +import java.util.Map; +import java.util.stream.Collectors; + import org.apache.skywalking.oap.server.core.CoreModule; -import org.apache.skywalking.oap.server.core.remote.client.Address; +import org.apache.skywalking.oap.server.core.remote.client.RemoteClient; import org.apache.skywalking.oap.server.core.remote.client.RemoteClientManager; import org.apache.skywalking.oap.server.library.module.ModuleManager; @@ -50,22 +52,15 @@ public class ClusterStatusQueryHandler { return remoteClientManager; } + @ProducesJson @Get("/status/cluster/nodes") - public HttpResponse buildClusterNodeList(HttpRequest request) { - JsonObject clusterInfo = new JsonObject(); - - JsonArray nodeList = new JsonArray(); - clusterInfo.add("nodes", nodeList); - getRemoteClientManager().getRemoteClient().stream().map(c -> { - final Address address = c.getAddress(); - JsonObject node = new JsonObject(); - node.addProperty("host", address.getHost()); - node.addProperty("port", address.getPort()); - node.addProperty("isSelf", address.isSelf()); - return node; - }).forEach(nodeList::add); - - return HttpResponse.of(MediaType.JSON_UTF_8, clusterInfo.toString()); + public Map<String, ?> buildClusterNodeList(HttpRequest request) { + return Map.of( + "nodes", + getRemoteClientManager().getRemoteClient() + .stream() + .map(RemoteClient::getAddress) + .collect(Collectors.toList()) + ); } - } diff --git a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java index fed57a625b..508cb73e46 100644 --- a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java +++ b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java @@ -26,12 +26,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.linecorp.armeria.common.AggregatedHttpResponse; -import com.linecorp.armeria.common.HttpHeaderNames; import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.server.annotation.Default; import com.linecorp.armeria.server.annotation.ExceptionHandler; import com.linecorp.armeria.server.annotation.Get; import com.linecorp.armeria.server.annotation.Param; +import com.linecorp.armeria.server.annotation.ProducesJson; +import com.linecorp.armeria.server.annotation.ProducesText; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -83,6 +85,7 @@ import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingSpan; import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTrace; import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext; import org.apache.skywalking.oap.server.core.status.ServerStatusService; +import org.apache.skywalking.oap.server.core.status.ServerStatusService.ConfigList; import org.apache.skywalking.oap.server.library.module.ModuleManager; import zipkin2.Span; @@ -110,14 +113,11 @@ public class DebuggingHTTPHandler { this.logQuery = new LogQuery(manager); } + @ProducesText + @ProducesJson @Get("/debugging/config/dump") - public String dumpConfigurations(HttpRequest request) { - final String acceptHeader = request.headers().get(HttpHeaderNames.ACCEPT); - if (acceptHeader != null && acceptHeader.toLowerCase().contains("application/json")) { - return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig()) - .toJsonString(); - } - return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig()).toString(); + public ConfigList dumpConfigurations(HttpRequest request) { + return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig()); } @SneakyThrows diff --git a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/TTLConfigQueryHandler.java b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/TTLConfigQueryHandler.java index 20d009e868..8a87a3e372 100644 --- a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/TTLConfigQueryHandler.java +++ b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/TTLConfigQueryHandler.java @@ -18,15 +18,15 @@ package org.apache.skywalking.oap.query.debug; -import com.linecorp.armeria.common.HttpHeaderNames; -import com.linecorp.armeria.common.HttpRequest; -import com.linecorp.armeria.common.HttpResponse; -import com.linecorp.armeria.common.MediaType; import com.linecorp.armeria.server.annotation.ExceptionHandler; import com.linecorp.armeria.server.annotation.Get; +import com.linecorp.armeria.server.annotation.ProducesJson; +import com.linecorp.armeria.server.annotation.ProducesText; + import lombok.extern.slf4j.Slf4j; import org.apache.skywalking.oap.server.core.CoreModule; import org.apache.skywalking.oap.server.core.query.TTLStatusQuery; +import org.apache.skywalking.oap.server.core.storage.ttl.TTLDefinition; import org.apache.skywalking.oap.server.library.module.ModuleManager; @Slf4j @@ -48,12 +48,10 @@ public class TTLConfigQueryHandler { return ttlStatusQuery; } + @ProducesText + @ProducesJson @Get("/status/config/ttl") - public HttpResponse affectedTTLConfigurations(HttpRequest request) { - final String acceptHeader = request.headers().get(HttpHeaderNames.ACCEPT); - if (acceptHeader != null && acceptHeader.toLowerCase().contains("application/json")) { - return HttpResponse.of(MediaType.JSON_UTF_8, getTTLStatusQuery().getTTL().generateTTLDefinitionAsJSONStr()); - } - return HttpResponse.of(MediaType.PLAIN_TEXT_UTF_8, getTTLStatusQuery().getTTL().generateTTLDefinition()); + public TTLDefinition effectiveTTLConfigurations() { + return getTTLStatusQuery().getTTL(); } } diff --git a/oap-server/server-tools/profile-exporter/tool-profile-snapshot-server-mock/src/main/java/org/apache/skywalking/oap/server/tool/profile/core/MockCoreModuleProvider.java b/oap-server/server-tools/profile-exporter/tool-profile-snapshot-server-mock/src/main/java/org/apache/skywalking/oap/server/tool/profile/core/MockCoreModuleProvider.java index 4639dfe334..a5e9838998 100755 --- a/oap-server/server-tools/profile-exporter/tool-profile-snapshot-server-mock/src/main/java/org/apache/skywalking/oap/server/tool/profile/core/MockCoreModuleProvider.java +++ b/oap-server/server-tools/profile-exporter/tool-profile-snapshot-server-mock/src/main/java/org/apache/skywalking/oap/server/tool/profile/core/MockCoreModuleProvider.java @@ -137,7 +137,7 @@ public class MockCoreModuleProvider extends CoreModuleProvider { CoreModuleConfig moduleConfig = new CoreModuleConfig(); this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig, this)); - this.registerServiceImplementation(ServerStatusService.class, new ServerStatusService(getManager(), moduleConfig)); + this.registerServiceImplementation(ServerStatusService.class, new ServerStatusService(getManager())); moduleConfig.setEnableHierarchy(false); this.registerServiceImplementation(HierarchyDefinitionService.class, new HierarchyDefinitionService(moduleConfig)); this.registerServiceImplementation(HierarchyService.class, new HierarchyService(getManager(), moduleConfig));