refactor: simplify the `Accept` http header process (#13275)
This commit is contained in:
parent
284521ca99
commit
6e435d80b8
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue