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.
|
* Storage: separate `SpanAttachedEventRecord` for SkyWalking trace and Zipkin trace.
|
||||||
* [Break Change]BanyanDB: Setup new Group policy.
|
* [Break Change]BanyanDB: Setup new Group policy.
|
||||||
* Bump up commons-beanutils to 1.11.0.
|
* Bump up commons-beanutils to 1.11.0.
|
||||||
|
* Refactor: simplify the `Accept` http header process.
|
||||||
|
|
||||||
#### UI
|
#### UI
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,17 @@ This API is used to get the unified and effective TTL configurations.
|
||||||
{
|
{
|
||||||
"host": "10.0.12.23",
|
"host": "10.0.12.23",
|
||||||
"port": 11800,
|
"port": 11800,
|
||||||
"isSelf": true
|
"self": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host": "10.0.12.25",
|
"host": "10.0.12.25",
|
||||||
"port": 11800,
|
"port": 11800,
|
||||||
"isSelf": false
|
"self": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host": "10.0.12.37",
|
"host": "10.0.12.37",
|
||||||
"port": 11800,
|
"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 `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
|
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();
|
httpServer.initialize();
|
||||||
|
|
||||||
this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig, this));
|
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));
|
this.registerServiceImplementation(HierarchyDefinitionService.class, new HierarchyDefinitionService(moduleConfig));
|
||||||
hierarchyService = new HierarchyService(getManager(), moduleConfig);
|
hierarchyService = new HierarchyService(getManager(), moduleConfig);
|
||||||
this.registerServiceImplementation(HierarchyService.class, hierarchyService);
|
this.registerServiceImplementation(HierarchyService.class, hierarchyService);
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,11 @@
|
||||||
|
|
||||||
package org.apache.skywalking.oap.server.core.status;
|
package org.apache.skywalking.oap.server.core.status;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import java.util.HashMap;
|
||||||
import io.vavr.Tuple2;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.ApplicationConfiguration;
|
||||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||||
import org.apache.skywalking.oap.server.library.module.Service;
|
import org.apache.skywalking.oap.server.library.module.Service;
|
||||||
|
|
@ -43,7 +40,6 @@ import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ServerStatusService implements Service {
|
public class ServerStatusService implements Service {
|
||||||
private final ModuleManager manager;
|
private final ModuleManager manager;
|
||||||
private final CoreModuleConfig moduleConfig;
|
|
||||||
@Getter
|
@Getter
|
||||||
private BootingStatus bootingStatus = new BootingStatus();
|
private BootingStatus bootingStatus = new BootingStatus();
|
||||||
@Getter
|
@Getter
|
||||||
|
|
@ -98,7 +94,7 @@ public class ServerStatusService implements Service {
|
||||||
for (ApplicationConfiguration.ModuleConfiguration configuration : configurations) {
|
for (ApplicationConfiguration.ModuleConfiguration configuration : configurations) {
|
||||||
final String moduleName = configuration.getModuleName();
|
final String moduleName = configuration.getModuleName();
|
||||||
if (configuration.getProviders().size() == 1) {
|
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(
|
configuration.getProviders().forEach(
|
||||||
(providerName, providerConfiguration) ->
|
(providerName, providerConfiguration) ->
|
||||||
|
|
@ -109,7 +105,7 @@ public class ServerStatusService implements Service {
|
||||||
value = "******";
|
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;
|
return configList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConfigList {
|
public static class ConfigList extends HashMap<String, String> {
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder configList = new StringBuilder();
|
StringBuilder configList = new StringBuilder();
|
||||||
for (Tuple2 tuple : configurations) {
|
for (final var entry : this.entrySet()) {
|
||||||
configList.append(tuple._1)
|
configList.append(entry.getKey())
|
||||||
.append("=")
|
.append("=")
|
||||||
.append(tuple._2)
|
.append(entry.getValue())
|
||||||
.append("\n");
|
.append("\n");
|
||||||
}
|
}
|
||||||
return configList.toString();
|
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;
|
package org.apache.skywalking.oap.server.core.storage.ttl;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,11 +25,11 @@ import lombok.Data;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class TTLDefinition {
|
public class TTLDefinition {
|
||||||
private final static Gson GSON = new Gson();
|
|
||||||
private final MetricsTTL metrics;
|
private final MetricsTTL metrics;
|
||||||
private final RecordsTTL records;
|
private final RecordsTTL records;
|
||||||
|
|
||||||
public String generateTTLDefinition() {
|
@Override
|
||||||
|
public String toString() {
|
||||||
StringBuilder ttlDefinition = new StringBuilder();
|
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("# Metrics TTL includes the definition of the TTL of the metrics-ish data in the storage,\n");
|
||||||
ttlDefinition.append("# e.g.\n");
|
ttlDefinition.append("# e.g.\n");
|
||||||
|
|
@ -67,8 +66,4 @@ public class TTLDefinition {
|
||||||
ttlDefinition.append("records.browserErrorLog.cold=").append(records.getColdBrowserErrorLog()).append("\n");
|
ttlDefinition.append("records.browserErrorLog.cold=").append(records.getColdBrowserErrorLog()).append("\n");
|
||||||
return ttlDefinition.toString();
|
return ttlDefinition.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateTTLDefinitionAsJSONStr() {
|
|
||||||
return GSON.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,18 @@
|
||||||
|
|
||||||
package org.apache.skywalking.oap.query.debug;
|
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.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.ExceptionHandler;
|
||||||
import com.linecorp.armeria.server.annotation.Get;
|
import com.linecorp.armeria.server.annotation.Get;
|
||||||
|
import com.linecorp.armeria.server.annotation.ProducesJson;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.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.core.remote.client.RemoteClientManager;
|
||||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||||
|
|
||||||
|
|
@ -50,22 +52,15 @@ public class ClusterStatusQueryHandler {
|
||||||
return remoteClientManager;
|
return remoteClientManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ProducesJson
|
||||||
@Get("/status/cluster/nodes")
|
@Get("/status/cluster/nodes")
|
||||||
public HttpResponse buildClusterNodeList(HttpRequest request) {
|
public Map<String, ?> buildClusterNodeList(HttpRequest request) {
|
||||||
JsonObject clusterInfo = new JsonObject();
|
return Map.of(
|
||||||
|
"nodes",
|
||||||
JsonArray nodeList = new JsonArray();
|
getRemoteClientManager().getRemoteClient()
|
||||||
clusterInfo.add("nodes", nodeList);
|
.stream()
|
||||||
getRemoteClientManager().getRemoteClient().stream().map(c -> {
|
.map(RemoteClient::getAddress)
|
||||||
final Address address = c.getAddress();
|
.collect(Collectors.toList())
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.linecorp.armeria.common.AggregatedHttpResponse;
|
import com.linecorp.armeria.common.AggregatedHttpResponse;
|
||||||
import com.linecorp.armeria.common.HttpHeaderNames;
|
|
||||||
import com.linecorp.armeria.common.HttpRequest;
|
import com.linecorp.armeria.common.HttpRequest;
|
||||||
import com.linecorp.armeria.server.annotation.Default;
|
import com.linecorp.armeria.server.annotation.Default;
|
||||||
import com.linecorp.armeria.server.annotation.ExceptionHandler;
|
import com.linecorp.armeria.server.annotation.ExceptionHandler;
|
||||||
import com.linecorp.armeria.server.annotation.Get;
|
import com.linecorp.armeria.server.annotation.Get;
|
||||||
import com.linecorp.armeria.server.annotation.Param;
|
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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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.DebuggingTrace;
|
||||||
import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext;
|
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;
|
||||||
|
import org.apache.skywalking.oap.server.core.status.ServerStatusService.ConfigList;
|
||||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||||
import zipkin2.Span;
|
import zipkin2.Span;
|
||||||
|
|
||||||
|
|
@ -110,14 +113,11 @@ public class DebuggingHTTPHandler {
|
||||||
this.logQuery = new LogQuery(manager);
|
this.logQuery = new LogQuery(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ProducesText
|
||||||
|
@ProducesJson
|
||||||
@Get("/debugging/config/dump")
|
@Get("/debugging/config/dump")
|
||||||
public String dumpConfigurations(HttpRequest request) {
|
public ConfigList dumpConfigurations(HttpRequest request) {
|
||||||
final String acceptHeader = request.headers().get(HttpHeaderNames.ACCEPT);
|
return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig());
|
||||||
if (acceptHeader != null && acceptHeader.toLowerCase().contains("application/json")) {
|
|
||||||
return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig())
|
|
||||||
.toJsonString();
|
|
||||||
}
|
|
||||||
return serverStatusService.dumpBootingConfigurations(config.getKeywords4MaskingSecretsOfConfig()).toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@
|
||||||
|
|
||||||
package org.apache.skywalking.oap.query.debug;
|
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.ExceptionHandler;
|
||||||
import com.linecorp.armeria.server.annotation.Get;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||||
import org.apache.skywalking.oap.server.core.query.TTLStatusQuery;
|
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;
|
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -48,12 +48,10 @@ public class TTLConfigQueryHandler {
|
||||||
return ttlStatusQuery;
|
return ttlStatusQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ProducesText
|
||||||
|
@ProducesJson
|
||||||
@Get("/status/config/ttl")
|
@Get("/status/config/ttl")
|
||||||
public HttpResponse affectedTTLConfigurations(HttpRequest request) {
|
public TTLDefinition effectiveTTLConfigurations() {
|
||||||
final String acceptHeader = request.headers().get(HttpHeaderNames.ACCEPT);
|
return getTTLStatusQuery().getTTL();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class MockCoreModuleProvider extends CoreModuleProvider {
|
||||||
|
|
||||||
CoreModuleConfig moduleConfig = new CoreModuleConfig();
|
CoreModuleConfig moduleConfig = new CoreModuleConfig();
|
||||||
this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig, this));
|
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);
|
moduleConfig.setEnableHierarchy(false);
|
||||||
this.registerServiceImplementation(HierarchyDefinitionService.class, new HierarchyDefinitionService(moduleConfig));
|
this.registerServiceImplementation(HierarchyDefinitionService.class, new HierarchyDefinitionService(moduleConfig));
|
||||||
this.registerServiceImplementation(HierarchyService.class, new HierarchyService(getManager(), moduleConfig));
|
this.registerServiceImplementation(HierarchyService.class, new HierarchyService(getManager(), moduleConfig));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue