This is an automated email from the ASF dual-hosted git repository.
yui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new b852f78 [type: refactor] refactor agent code (#3050)
b852f78 is described below
commit b852f784dd6710204ee6d4cc790b24f048d85746
Author: xiaoyu <[email protected]>
AuthorDate: Thu Mar 17 13:24:30 2022 +0800
[type: refactor] refactor agent code (#3050)
* [type: refactor] refactor agent code
---
.../agent/api/exception/ShenyuAgentException.java | 6 ++
.../transformer/ShenyuAgentTransformer.java | 4 +-
.../agent/core/loader/ShenyuAgentPluginLoader.java | 6 +-
.../agent/core/locator/ShenyuAgentLocator.java | 27 ++++----
.../agent/plugin/metrics/api/MetricsRecorder.java | 1 -
.../prometheus/collector/BuildInfoCollector.java | 13 ++--
.../jaeger/boot/JaegerAgentPluginBootService.java | 2 +-
.../tracing/jaeger/span/JaegerErrorSpan.java | 2 +-
.../zipkin/boot/ZipkinAgentPluginBootService.java | 35 +++++-----
.../tracing/zipkin/enums/SamplerTypeEnum.java | 79 ++++++++++++++++++++++
.../src/main/resources/conf/shenyu-agent.yaml | 10 +--
11 files changed, 136 insertions(+), 49 deletions(-)
diff --git
a/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/api/exception/ShenyuAgentException.java
b/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/api/exception/ShenyuAgentException.java
index 354b4e8..5aadcf5 100644
---
a/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/api/exception/ShenyuAgentException.java
+++
b/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/api/exception/ShenyuAgentException.java
@@ -22,6 +22,12 @@ package org.apache.shenyu.agent.api.exception;
*/
public final class ShenyuAgentException extends RuntimeException {
+ /**
+ * Instantiates a new Shenyu agent exception.
+ *
+ * @param errorMessage the error message
+ * @param args the args
+ */
public ShenyuAgentException(final String errorMessage, final Object...
args) {
super(String.format(errorMessage, args));
}
diff --git
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/bytebuddy/transformer/ShenyuAgentTransformer.java
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/bytebuddy/transformer/ShenyuAgentTransformer.java
index 74fb93d..abb21cf 100644
---
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/bytebuddy/transformer/ShenyuAgentTransformer.java
+++
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/bytebuddy/transformer/ShenyuAgentTransformer.java
@@ -53,7 +53,7 @@ import java.util.stream.Collectors;
*/
public final class ShenyuAgentTransformer implements Transformer {
- private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
+ private static final String EXT_OBJECT = "_$EXT_OBJECT$_";
private static final Logger LOG =
LoggerFactory.getLogger(ShenyuAgentTransformer.class);
@@ -64,7 +64,7 @@ public final class ShenyuAgentTransformer implements
Transformer {
if (!MATCHER.containsType(typeDescription)) {
return builder;
}
- Builder<?> result = builder.defineField(EXTRA_DATA, Object.class,
Opcodes.ACC_PRIVATE |
Opcodes.ACC_VOLATILE).implement(TargetObject.class).intercept(FieldAccessor.ofField(EXTRA_DATA));
+ Builder<?> result = builder.defineField(EXT_OBJECT, Object.class,
Opcodes.ACC_PRIVATE |
Opcodes.ACC_VOLATILE).implement(TargetObject.class).intercept(FieldAccessor.ofField(EXT_OBJECT));
ShenyuAgentJoinPoint joinPoint =
MATCHER.loadShenyuAgentJoinPoint(typeDescription);
result = interceptorConstructorPoint(typeDescription,
joinPoint.getConstructorPoints(), result);
result = interceptorStaticMethodPoint(typeDescription,
joinPoint.getStaticMethodPoints(), result);
diff --git
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/loader/ShenyuAgentPluginLoader.java
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/loader/ShenyuAgentPluginLoader.java
index ac44654..106919f 100644
---
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/loader/ShenyuAgentPluginLoader.java
+++
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/loader/ShenyuAgentPluginLoader.java
@@ -113,11 +113,11 @@ public final class ShenyuAgentPluginLoader extends
ClassLoader implements Closea
byte[] data =
ByteStreams.toByteArray(each.jarFile.getInputStream(entry));
return defineClass(name, data, 0, data.length);
} catch (final IOException ex) {
- LOG.error("Failed to load class {}", name, ex);
+ LOG.error("Failed to load shenyu plugin class {}", name,
ex);
}
}
}
- throw new ClassNotFoundException(String.format("Class name is %s not
found", name));
+ throw new ClassNotFoundException(String.format("shenyu plugin class
name is %s not found", name));
}
@Override
@@ -155,7 +155,7 @@ public final class ShenyuAgentPluginLoader extends
ClassLoader implements Closea
try {
each.jarFile.close();
} catch (final IOException ex) {
- LOG.error("Exception occur when closing jar", ex);
+ LOG.error("Exception closing for shenyu plugin jar", ex);
}
}
}
diff --git
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/locator/ShenyuAgentLocator.java
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/locator/ShenyuAgentLocator.java
index 85d4d0a..016ebce 100644
---
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/locator/ShenyuAgentLocator.java
+++
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/core/locator/ShenyuAgentLocator.java
@@ -33,6 +33,8 @@ public final class ShenyuAgentLocator {
private static final Logger LOG =
LoggerFactory.getLogger(ShenyuAgentLocator.class);
+ private static final String PRE_FILE = "file:";
+
private ShenyuAgentLocator() {
}
@@ -42,13 +44,12 @@ public final class ShenyuAgentLocator {
* @return the file
*/
public static File locatorAgent() {
- String classResourcePath = String.join("",
ShenyuAgentLocator.class.getName().replaceAll("\\.", "/"), ".class");
- URL resource =
ClassLoader.getSystemClassLoader().getResource(classResourcePath);
+ String path = String.join("",
ShenyuAgentLocator.class.getName().replaceAll("\\.", "/"), ".class");
+ URL resource = ClassLoader.getSystemClassLoader().getResource(path);
assert resource != null;
String url = resource.toString();
- int existFileInJarIndex = url.indexOf('!');
- boolean isInJar = existFileInJarIndex > -1;
- return isInJar ? getFileInJar(url, existFileInJarIndex) :
getFileInResource(url, classResourcePath);
+ int index = url.indexOf('!');
+ return index > -1 ? buildFileInJar(url, index) :
buildFileInResource(url, path);
}
/**
@@ -80,17 +81,17 @@ public final class ShenyuAgentLocator {
return new File(String.join("/", file.getPath(), "conf", fileName));
}
- private static File getFileInResource(final String url, final String
classResourcePath) {
- int prefixLength = "file:".length();
- String classLocation = url.substring(prefixLength, url.length() -
classResourcePath.length());
- return new File(classLocation);
+ private static File buildFileInResource(final String url, final String
path) {
+ return new File(url.substring(PRE_FILE.length(), url.length() -
path.length()));
}
- private static File getFileInJar(final String url, final int
fileInJarIndex) {
- String realUrl = url.substring(url.indexOf("file:"), fileInJarIndex);
+ private static File buildFileInJar(final String url, final int index) {
try {
- File agentJarFile = new File(new URL(realUrl).toURI());
- return agentJarFile.exists() ? agentJarFile.getParentFile() : null;
+ final File jarFile = new File(new
URL(url.substring(url.indexOf(PRE_FILE), index)).toURI());
+ if (jarFile.exists()) {
+ return jarFile.getParentFile();
+ }
+ return null;
} catch (final MalformedURLException | URISyntaxException ex) {
return null;
}
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-api/src/main/java/org/apache/shenyu/agent/plugin/metrics/api/MetricsRecorder.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-api/src/main/java/org/apache/shenyu/agent/plugin/metrics/api/MetricsRecorder.java
index 27a391d..c27cfde 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-api/src/main/java/org/apache/shenyu/agent/plugin/metrics/api/MetricsRecorder.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-api/src/main/java/org/apache/shenyu/agent/plugin/metrics/api/MetricsRecorder.java
@@ -104,5 +104,4 @@ public interface MetricsRecorder {
*/
default void observe(double value, String... labels) {
}
-
}
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-prometheus/src/main/java/org/apache/shenyu/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-prometheus/src/main/java/org/apache/shenyu/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
index a8db6e7..29364ea 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-prometheus/src/main/java/org/apache/shenyu/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-metrics/shenyu-agent-plugin-metrics-prometheus/src/main/java/org/apache/shenyu/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
@@ -19,6 +19,7 @@ package
org.apache.shenyu.agent.plugin.metrics.prometheus.collector;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,6 +37,8 @@ public final class BuildInfoCollector extends Collector {
private static final String CLASS_NAME =
"org.apache.shenyu.web.handler.ShenyuWebHandler";
+ private static final String UNKNOWN = "unknown";
+
@Override
public List<MetricFamilySamples> collect() {
List<String> labels = new ArrayList<>();
@@ -43,12 +46,12 @@ public final class BuildInfoCollector extends Collector {
labels.add("name");
GaugeMetricFamily gaugeMetricFamily = new
GaugeMetricFamily("build_info", "build information", labels);
try {
- Package proxyPkg = Class.forName(CLASS_NAME).getPackage();
- final String proxyVersion = proxyPkg.getImplementationVersion();
- final String proxyName = proxyPkg.getImplementationTitle();
- gaugeMetricFamily.addMetric(Arrays.asList(null != proxyVersion ?
proxyVersion : "unknown", null != proxyName ? proxyName : "unknown"), 1L);
+ Package pkg = Class.forName(CLASS_NAME).getPackage();
+ String version =
StringUtils.isBlank(pkg.getImplementationVersion()) ? UNKNOWN :
pkg.getImplementationVersion();
+ String name = StringUtils.isBlank(pkg.getImplementationTitle()) ?
UNKNOWN : pkg.getImplementationTitle();
+ gaugeMetricFamily.addMetric(Arrays.asList(version, name), 1L);
} catch (ClassNotFoundException ex) {
- LOG.error("No proxy class find :{}", CLASS_NAME);
+ LOG.error("No shenyu gateway class find :{}", CLASS_NAME);
}
return Collections.singletonList(gaugeMetricFamily);
}
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/boot/JaegerAgentPluginBootService.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/boot/JaegerAgentPluginBootService.java
index d8c3578..ff1bfc9 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/boot/JaegerAgentPluginBootService.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/boot/JaegerAgentPluginBootService.java
@@ -44,7 +44,7 @@ public class JaegerAgentPluginBootService implements
AgentPluginBootService {
Configuration.SamplerConfiguration samplerConfig =
Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig =
Configuration.ReporterConfiguration.fromEnv()
.withSender(Configuration.SenderConfiguration.fromEnv().withAgentHost(agentPluginConfig.getHost()).withAgentPort(agentPluginConfig.getPort()));
- String serviceName =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("SERVICE_NAME")).orElse("shenyu-agent");
+ String serviceName =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("name")).orElse("shenyu-agent");
configuration = new
Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig);
if (!GlobalTracer.isRegistered()) {
GlobalTracer.registerIfAbsent(configuration.getTracer());
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/span/JaegerErrorSpan.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/span/JaegerErrorSpan.java
index 7a60b03..ef5d710 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/span/JaegerErrorSpan.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/plugin/tracing/jaeger/span/JaegerErrorSpan.java
@@ -40,7 +40,7 @@ public final class JaegerErrorSpan {
}
private static Map<String, ?> getReason(final Throwable cause) {
- Map<String, String> result = new HashMap<>(3, 1);
+ Map<String, String> result = new HashMap<>();
result.put(TracingConstants.ErrorLogTags.EVENT,
TracingConstants.ErrorLogTags.EVENT_ERROR_TYPE);
result.put(TracingConstants.ErrorLogTags.ERROR_KIND,
cause.getClass().getName());
result.put(TracingConstants.ErrorLogTags.MESSAGE, cause.getMessage());
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/boot/ZipkinAgentPluginBootService.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/boot/ZipkinAgentPluginBootService.java
index 415a861..11bee4a 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/boot/ZipkinAgentPluginBootService.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/boot/ZipkinAgentPluginBootService.java
@@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.agent.api.config.AgentPluginConfig;
import org.apache.shenyu.agent.api.exception.ShenyuAgentException;
import org.apache.shenyu.agent.api.spi.AgentPluginBootService;
+import org.apache.shenyu.agent.plugin.tracing.zipkin.enums.SamplerTypeEnum;
import org.apache.shenyu.spi.Join;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.okhttp3.OkHttpSender;
@@ -38,6 +39,7 @@ import java.util.Properties;
*/
@Join
public class ZipkinAgentPluginBootService implements AgentPluginBootService {
+
private static final String DEFAULT_URL_VERSION = "/api/v2/spans";
private static final String DEFAULT_SERVICE_NAME = "shenyu-agent";
@@ -62,14 +64,13 @@ public class ZipkinAgentPluginBootService implements
AgentPluginBootService {
if (StringUtils.isEmpty(agentPluginConfig.getHost()) ||
agentPluginConfig.getPort() < 0) {
throw new ShenyuAgentException("zipkin config error, host can not
config or port is %s", agentPluginConfig.getPort());
}
-
Properties props = agentPluginConfig.getProps();
- String urlVersion =
Optional.ofNullable(props.getProperty("URL_VERSION")).orElse(DEFAULT_URL_VERSION);
+ String urlVersion =
Optional.ofNullable(props.getProperty("version")).orElse(DEFAULT_URL_VERSION);
sender = OkHttpSender.create(String.format("http://%s:%s%s",
agentPluginConfig.getHost(), agentPluginConfig.getPort(), urlVersion));
zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
Sampler sampler = createSampler(agentPluginConfig);
- String serviceName =
Optional.ofNullable(props.getProperty("SERVICE_NAME")).orElse(DEFAULT_SERVICE_NAME);
+ String serviceName =
Optional.ofNullable(props.getProperty("name")).orElse(DEFAULT_SERVICE_NAME);
tracing = Tracing.newBuilder()
.localServiceName(serviceName)
.sampler(sampler)
@@ -83,11 +84,9 @@ public class ZipkinAgentPluginBootService implements
AgentPluginBootService {
if (Objects.nonNull(tracing)) {
tracing.close();
}
-
if (Objects.nonNull(zipkinSpanHandler)) {
zipkinSpanHandler.close();
}
-
if (Objects.nonNull(sender)) {
sender.close();
}
@@ -100,23 +99,23 @@ public class ZipkinAgentPluginBootService implements
AgentPluginBootService {
* @return sample.
*/
private Sampler createSampler(final AgentPluginConfig agentPluginConfig) {
- String samplerType =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("SAMPLER_TYPE")).orElse(DEFAULT_SAMPLER_TYPE);
- String samplerParam =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("SAMPLER_PARAM")).orElse(DEFAULT_SAMPLER_PARAM);
- switch (samplerType) {
- case "const":
- if (Objects.equals(samplerParam, "0")) {
+ String type =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("type")).orElse(DEFAULT_SAMPLER_TYPE);
+ String param =
Optional.ofNullable(agentPluginConfig.getProps().getProperty("param")).orElse(DEFAULT_SAMPLER_PARAM);
+ SamplerTypeEnum typeEnum = SamplerTypeEnum.getEnumByName(type);
+ switch (typeEnum) {
+ case CONS:
+ if (Objects.equals(param, "0")) {
return Sampler.NEVER_SAMPLE;
}
return Sampler.ALWAYS_SAMPLE;
- case "counting":
- return Sampler.create(Float.parseFloat(samplerParam));
- case "ratelimiting":
- return
RateLimitingSampler.create(Integer.parseInt(samplerParam));
- case "boundary":
- return BoundarySampler.create(Float.parseFloat(samplerParam));
+ case COUNTING:
+ return Sampler.create(Float.parseFloat(param));
+ case RATE_LIMITING:
+ return RateLimitingSampler.create(Integer.parseInt(param));
+ case BOUNDARY:
+ return BoundarySampler.create(Float.parseFloat(param));
default:
- break;
+ return Sampler.ALWAYS_SAMPLE;
}
- return Sampler.ALWAYS_SAMPLE;
}
}
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/enums/SamplerTypeEnum.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/enums/SamplerTypeEnum.java
new file mode 100644
index 0000000..4881918
--- /dev/null
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-zipkin/src/main/java/org/apache/shenyu/agent/plugin/tracing/zipkin/enums/SamplerTypeEnum.java
@@ -0,0 +1,79 @@
+/*
+ * 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.shenyu.agent.plugin.tracing.zipkin.enums;
+
+import java.util.Arrays;
+
+/**
+ * The enum Sampler type enum.
+ */
+public enum SamplerTypeEnum {
+
+ /**
+ * Cons sampler type enum.
+ */
+ CONS("const"),
+
+ /**
+ * Counting sampler type enum.
+ */
+ COUNTING("counting"),
+
+ /**
+ * Rate limiting sampler type enum.
+ */
+ RATE_LIMITING("ratelimiting"),
+
+ /**
+ * Boundary sampler type enum.
+ */
+ BOUNDARY("boundary"),
+
+ /**
+ * Always sample sampler type enum.
+ */
+ ALWAYS_SAMPLE("AlwaysSample");
+
+ private final String name;
+
+ SamplerTypeEnum(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * get name.
+ *
+ * @return name name
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ /**
+ * Gets enum by name.
+ *
+ * @param name the name
+ * @return the enum by name
+ */
+ public static SamplerTypeEnum getEnumByName(final String name) {
+ return Arrays.stream(SamplerTypeEnum.values())
+ .filter(e -> e.getName().equals(name)).findFirst()
+ .orElse(SamplerTypeEnum.ALWAYS_SAMPLE);
+ }
+}
diff --git
a/shenyu-dist/shenyu-agent-dist/src/main/resources/conf/shenyu-agent.yaml
b/shenyu-dist/shenyu-agent-dist/src/main/resources/conf/shenyu-agent.yaml
index 669c135..67f185c 100644
--- a/shenyu-dist/shenyu-agent-dist/src/main/resources/conf/shenyu-agent.yaml
+++ b/shenyu-dist/shenyu-agent-dist/src/main/resources/conf/shenyu-agent.yaml
@@ -32,7 +32,7 @@ plugins:
host: "localhost"
port: 5775
props:
- SERVICE_NAME: "shenyu-agent"
+ name: "shenyu-agent"
JAEGER_SAMPLER_TYPE: "const"
JAEGER_SAMPLER_PARAM: "1"
opentelemetry:
@@ -44,10 +44,10 @@ plugins:
host: "localhost"
port: 9411
props:
- SERVICE_NAME: "shenyu-agent"
- URL_VERSION: "/api/v2/spans"
- SAMPLER_TYPE: "const"
- SAMPLER_PARAM: "1"
+ name: "shenyu-agent"
+ version: "/api/v2/spans"
+ type: "const"
+ param: "1"
metrics:
prometheus:
host: "localhost"