You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/09/25 16:19:35 UTC
[shardingsphere] branch master updated: Refactor the agent.yaml configuration file #21067 (#21118)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 8d558df1843 Refactor the agent.yaml configuration file #21067 (#21118)
8d558df1843 is described below
commit 8d558df1843dc07e8420f071e0f57f3f00ce4bdb
Author: jiangML <10...@qq.com>
AuthorDate: Mon Sep 26 00:19:22 2022 +0800
Refactor the agent.yaml configuration file #21067 (#21118)
* Refactor: refactor the agent.yaml configuration file
* Adjust the format of the agent.yaml configuration parameter
* Update observability documentation
* Add metrics documentation
* Adjust SQLRouteEngineAdvice to fit SQLRouteEngine
* Modify the jaeger system property to uppercase
* Optimize code and documentation
* Update the observability documentation
* Update the observability documentation
* Remove duplicate checksums
---
.../observability/_index.cn.md | 133 ++++++++++++---------
.../observability/_index.en.md | 133 ++++++++++++---------
.../agent/config/AgentConfiguration.java | 8 +-
.../core/config/yaml/YamlAgentConfiguration.java | 11 +-
...n.java => YamlPluginCategoryConfiguration.java} | 12 +-
.../swapper/YamlAgentConfigurationSwapper.java | 20 +++-
.../agent/core/plugin/AgentPluginLoader.java | 18 ++-
.../core/plugin/PluginBootServiceManager.java | 7 --
.../src/test/resources/conf/agent.yaml | 66 +++++-----
.../src/main/resources/conf/agent.yaml | 72 +++++------
.../BaseLoggingPluginDefinitionService.java | 2 +-
.../base/service/BaseLoggingPluginBootService.java | 2 +-
.../metrics/api/advice/SQLRouteEngineAdvice.java | 2 +-
.../api/advice/SQLRouteEngineAdviceTest.java | 3 +-
.../src/test/resources/conf/agent.yaml | 64 +++++-----
.../service/PrometheusPluginBootService.java | 4 +-
.../service/JaegerTracingPluginBootService.java | 18 +--
.../OpenTelemetryTracingPluginBootService.java | 7 +-
.../service/OpenTracingPluginBootService.java | 4 +-
.../service/OpenTracingPluginBootServiceTest.java | 2 +-
.../service/ZipkinTracingPluginBootService.java | 24 +++-
.../test/resources/docker/proxy/conf/agent.yaml | 69 +++++------
.../test/resources/docker/proxy/conf/agent.yaml | 73 ++++++-----
23 files changed, 418 insertions(+), 336 deletions(-)
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
index d94229f77d6..e9ca8ed047b 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
@@ -40,66 +40,60 @@ tree
* 配置说明
`conf/agent.yaml` 用于管理 agent 配置。
-内置插件包括 Jaeger、OpenTracing、Zipkin、OpenTelemetry、Logging 及 Prometheus。
-当需要开启插件时,只需要移除 `ignoredPluginNames` 中对应的插件名称即可。
+内置插件包括 Jaeger、OpenTracing、Zipkin、OpenTelemetry、BaseLogging 及 Prometheus。
+默认不开启任何插件。
```yaml
-applicationName: shardingsphere-agent
-ignoredPluginNames:
- - Jaeger
- - OpenTracing
- - Zipkin
- - OpenTelemetry
- - Logging
- - Prometheus
-
plugins:
- Prometheus:
- host: "localhost"
- port: 9090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere-agent"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere-agent"
- URL_VERSION: "/api/v2/spans"
- SAMPLER_TYPE: "const"
- SAMPLER_PARAM: "1"
- OpenTracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- OpenTelemetry:
- props:
- otel.resource.attributes: "service.name=shardingsphere-agent"
- otel.traces.exporter: "zipkin"
- Logging:
- props:
- LEVEL: "INFO"
-
+# logging:
+# BaseLogging:
+# props:
+# level: "INFO"
+# metrics:
+# Prometheus:
+# host: "localhost"
+# port: 9090
+# props:
+# jvm-information-collector-enabled: "true"
+# tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# Zipkin:
+# host: "localhost"
+# port: 9411
+# props:
+# service-name: "shardingsphere"
+# url-version: "/api/v2/spans"
+# sampler-type: "const"
+# sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+# OpenTelemetry:
+# props:
+# otel-resource-attributes: "service.name=shardingsphere"
+# otel-traces-exporter: "zipkin"
```
* 参数说明;
-| 名称 | 说明 |取值范围 |默认值 |
-| :--------- | :-------- |:--------- | :-------- |
-| JVM_INFORMATION_COLLECTOR_ENABLED | 是否开启 JVM 采集器 |true、false|true|
-| SERVICE_NAME | 链路跟踪的服务名称 | 自定义 | shardingsphere-agent |
-| JAEGER_SAMPLER_TYPE | Jaeger 采样率类型 | const、probabilistic、ratelimiting、remote | const |
-| JAEGER_SAMPLER_PARAM | Jaeger 采样率参数 |const:0、1,probabilistic:0.0 - 1.0,ratelimiting:> 0,自定义每秒采集数量,remote:需要自定义配置远程采样率管理服务地址,JAEGER_SAMPLER_MANAGER_HOST_PORT |1(const 类型)|
-| SAMPLER_TYPE | Zipkin 采样率类型 |const、counting、ratelimiting、boundary | const |
-| SAMPLER_PARAM | Zipkin 采样率参数 |const: 0、1,counting:0.01 - 1.0,ratelimiting:> 0,自定义每秒采集数量,boundary: 0.0001 - 1.0 | 1(const 类型)|
-| otel.resource.attributes|opentelemetry 资源属性 | 字符串键值对(,分割) | service.name=shardingsphere-agent |
-| otel.traces.exporter | Tracing expoter | zipkin、jaeger | zipkin |
-| otel.traces.sampler | opentelemetry 采样率类型 | always_on、always_off、traceidratio | always_on |
-| otel.traces.sampler.arg | opentelemetry 采样率参数 | traceidratio:0.0 - 1.0 | 1.0 |
+| 名称 | 说明 |取值范围 | 默认值 |
+|:----------------------------------|:--------------------|:--------- |:----------------------------------|
+| jvm-information-collector-enabled | 是否开启 JVM 采集器 |true、false| true |
+| service-name | 链路跟踪的服务名称 | 自定义 | shardingsphere |
+| jaeger-sampler-type | Jaeger 采样率类型 | const、probabilistic、ratelimiting、remote | const |
+| jaeger-sampler-param | Jaeger 采样率参数 |const:0、1,probabilistic:0.0 - 1.0,ratelimiting:> 0,自定义每秒采集数量,remote:需要自定义配置远程采样率管理服务地址,JAEGER_SAMPLER_MANAGER_HOST_PORT | 1(const 类型) |
+| url-version | Zipkin url 地址 | 自定义 | /api/v2/spans |
+| sampler-type | Zipkin 采样率类型 |const、counting、ratelimiting、boundary | const |
+| sampler-param | Zipkin 采样率参数 |const: 0、1,counting:0.01 - 1.0,ratelimiting:> 0,自定义每秒采集数量,boundary: 0.0001 - 1.0 | 1(const 类型) |
+| otel-resource-attributes | opentelemetry 资源属性 | 字符串键值对(,分割) | service.name=shardingsphere-agent |
+| otel-traces-exporter | Tracing expoter | zipkin、jaeger | zipkin |
+| otel-traces-sampler | opentelemetry 采样率类型 | always_on、always_off、traceidratio | always_on |
+| otel-traces-sampler-arg | opentelemetry 采样率参数 | traceidratio:0.0 - 1.0 | 1.0 |
## ShardingSphere-Proxy 中使用
@@ -117,3 +111,34 @@ nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} \
bin/start.sh
```
正常启动后,可以在 ShardingSphere-Proxy 日志中找到 plugin 的加载信息,访问 Proxy 后,可以通过配置的监控地址查看到 `Metric` 和 `Tracing` 的数据。
+
+
+## Metrics
+| 指标名称 | 类型 | 描述 |
+|:----------------------------------|:-----------|:-------------------------------------------------------|
+| proxy_request_total | COUNTER | 请求总数 |
+| proxy_connection_total | GAUGE | 当前连接总数 |
+| proxy_execute_latency_millis | HISTOGRAM | 执行耗时毫秒 |
+| proxy_execute_error_total | COUNTER | 执行异常总数 |
+| route_sql_select_total | COUNTER | 路由执行 select SQL 语句总数 |
+| route_sql_insert_total | COUNTER | 路由执行 insert SQL 语句总数 |
+| route_sql_update_total | COUNTER | 路由执行 update SQL 语句总数 |
+| route_sql_delete_total | COUNTER | 路由执行 delete SQL 语句总数 |
+| route_datasource_total | COUNTER | 数据源路由总数 |
+| route_table_total | COUNTER | 表路由数 |
+| proxy_transaction_commit_total | COUNTER | 事务提交次数 |
+| proxy_transaction_rollback_total | COUNTER | 事务回滚次数 |
+| parse_sql_dml_insert_total | COUNTER | 解析 insert SQL 语句总数 |
+| parse_sql_dml_delete_total | COUNTER | 解析 delete SQL 语句总数 |
+| parse_sql_dml_update_total | COUNTER | 解析 update SQL 语句总数 |
+| parse_sql_dml_select_total | COUNTER | 解析 select SQL 语句总数 |
+| parse_sql_ddl_total | COUNTER | 解析 DDL SQL 语句总数 |
+| parse_sql_dcl_total | COUNTER | 解析 DCL SQL 语句总数 |
+| parse_sql_dal_total | COUNTER | 解析 DAL SQL 语句总数 |
+| parse_sql_tcl_total | COUNTER | 解析 TCL SQL 语句总数 |
+| parse_dist_sql_rql_total | COUNTER | 解析 RQL 类型 DistSQL 总数 |
+| parse_dist_sql_rdl_total | COUNTER | 解析 RDL 类型 DistSQL 总数 |
+| parse_dist_sql_ral_total | COUNTER | 解析 RAL 类型 DistSQL 总数 |
+| build_info | GAUGE | 构建信息 |
+| proxy_info | GAUGE | proxy 信息, state:1 正常状态, state:2 熔断状态 |
+| meta_data_info | GAUGE | proxy 元数据信息, schema_count:逻辑库数量, database_count:数据源数量 |
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
index f288ce086b0..df5e7620a33 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
@@ -40,66 +40,60 @@ tree
* Configuration file
`conf/agent.yaml` is used to manage agent configuration.
-Built-in plugins include Jaeger, OpenTracing, Zipkin, OpenTelemetry, Logging and Prometheus.
-When a plugin needs to be enabled, just remove the corresponding name in `ignoredPluginNames`.
+Built-in plugins include Jaeger, OpenTracing, Zipkin, OpenTelemetry, BaseLogging and Prometheus.
+No plugin is enabled by default.
```yaml
-applicationName: shardingsphere-agent
-ignoredPluginNames:
- - Jaeger
- - OpenTracing
- - Zipkin
- - OpenTelemetry
- - Logging
- - Prometheus
-
plugins:
- Prometheus:
- host: "localhost"
- port: 9090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere-agent"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere-agent"
- URL_VERSION: "/api/v2/spans"
- SAMPLER_TYPE: "const"
- SAMPLER_PARAM: "1"
- OpenTracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- OpenTelemetry:
- props:
- otel.resource.attributes: "service.name=shardingsphere-agent"
- otel.traces.exporter: "zipkin"
- Logging:
- props:
- LEVEL: "INFO"
-
+# logging:
+# BaseLogging:
+# props:
+# level: "INFO"
+# metrics:
+# Prometheus:
+# host: "localhost"
+# port: 9090
+# props:
+# jvm-information-collector-enabled: "true"
+# tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# Zipkin:
+# host: "localhost"
+# port: 9411
+# props:
+# service-name: "shardingsphere"
+# url-version: "/api/v2/spans"
+# sampler-type: "const"
+# sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+# OpenTelemetry:
+# props:
+# otel-resource-attributes: "service.name=shardingsphere"
+# otel-traces-exporter: "zipkin"
```
* Parameter description:
-| Name | Description | Value range | Default value |
-| :--------- | :-------- |:--------- | :-------- |
-| JVM_INFORMATION_COLLECTOR_ENABLED | Start JVM collector | true, false | true |
-| SERVICE_NAME | Tracking service name | Custom | shardingsphere-agent |
-| JAEGER_SAMPLER_TYPE | Jaeger sample rate type | const, probabilistic, ratelimiting, remote | const |
-| JAEGER_SAMPLER_PARAM | Jaeger sample rate parameter |const:0, 1, probabilistic:0.0 - 1.0, ratelimiting: > 0, Customize the number of acquisitions per second, remote:need to customize the remote service addres,JAEGER_SAMPLER_MANAGER_HOST_PORT | 1 (const type) |
-| SAMPLER_TYPE | Zipkin sample rate type | const, counting, ratelimiting, boundary | const |
-| SAMPLER_PARAM | Zipkin sampling rate parameter |const:0, 1, counting:0.01 - 1.0, ratelimiting: > 0, boundary:0.0001 - 1.0 | 1 (const type) |
-| otel.resource.attributes | opentelemetry properties | String key value pair (, split) | service.name=shardingsphere-agent |
-| otel.traces.exporter | Tracing expoter | zipkin, jaeger | zipkin |
-| otel.traces.sampler | Opentelemetry sample rate type | always_on, always_off, traceidratio | always_on |
-| otel.traces.sampler.arg | Opentelemetry sample rate parameter | traceidratio:0.0 - 1.0 | 1.0 |
+| Name | Description | Value range | Default value |
+|:----------------------------------|:------------------------------------|:--------- | :-------- |
+| jvm-information-collector-enabled | Start JVM collector | true, false | true |
+| service-name | Tracking service name | Custom | shardingsphere-agent |
+| jaeger-sampler-type | Jaeger sample rate type | const, probabilistic, ratelimiting, remote | const |
+| jaeger-sampler-param | Jaeger sample rate parameter |const:0, 1, probabilistic:0.0 - 1.0, ratelimiting: > 0, Customize the number of acquisitions per second, remote:need to customize the remote service addres,JAEGER_SAMPLER_MANAGER_HOST_PORT | 1 (const type) |
+| url-version | Zipkin url address | Custom | /api/v2/spans |
+| sampler-type | Zipkin sample rate type | const, counting, ratelimiting, boundary | const |
+| sampler-param | Zipkin sampling rate parameter |const:0, 1, counting:0.01 - 1.0, ratelimiting: > 0, boundary:0.0001 - 1.0 | 1 (const type) |
+| otel-resource-attributes | opentelemetry properties | String key value pair (, split) | service.name=shardingsphere-agent |
+| otel-traces-exporter | Tracing expoter | zipkin, jaeger | zipkin |
+| otel-traces-sampler | Opentelemetry sample rate type | always_on, always_off, traceidratio | always_on |
+| otel-traces-sampler-arg | Opentelemetry sample rate parameter | traceidratio:0.0 - 1.0 | 1.0 |
## Usage in ShardingSphere-Proxy
@@ -117,3 +111,34 @@ nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} \
bin/start.sh
```
After startup, you can find the plugin info in the log of ShardingSphere-Proxy, `Metric` and `Tracing` data can be viewed through the configured monitoring address.
+
+
+## Metrics
+| name | type | description |
+|:---------------------------------|:-----------|:---------------------------------------------------------------------------------------------------------|
+| proxy_request_total | COUNTER | proxy request total |
+| proxy_connection_total | GAUGE | proxy connection total |
+| proxy_execute_latency_millis | HISTOGRAM | proxy executor latency millis |
+| proxy_execute_error_total | COUNTER | proxy executor error total |
+| route_sql_select_total | COUNTER | proxy executor route select sql total |
+| route_sql_insert_total | COUNTER | proxy executor route insert sql total |
+| route_sql_update_total | COUNTER | proxy executor route update sql total |
+| route_sql_delete_total | COUNTER | proxy executor route delete sql total |
+| route_datasource_total | COUNTER | number of datasource routed |
+| route_table_total | COUNTER | number of table routed |
+| proxy_transaction_commit_total | COUNTER | transaction commit count total |
+| proxy_transaction_rollback_total | COUNTER | transaction rollback count total |
+| parse_sql_dml_insert_total | COUNTER | proxy executor parse insert sql total |
+| parse_sql_dml_delete_total | COUNTER | proxy executor parse delete sql total |
+| parse_sql_dml_update_total | COUNTER | proxy executor parse update sql total |
+| parse_sql_dml_select_total | COUNTER | proxy executor parse select sql total |
+| parse_sql_ddl_total | COUNTER | proxy executor parse ddl sql total |
+| parse_sql_dcl_total | COUNTER | proxy executor parse dcl sql total |
+| parse_sql_dal_total | COUNTER | proxy executor parse dal sql total |
+| parse_sql_tcl_total | COUNTER | proxy executor parse tcl sql total |
+| parse_dist_sql_rql_total | COUNTER | proxy executor parse rql sql total |
+| parse_dist_sql_rdl_total | COUNTER | proxy executor parse rdl sql total |
+| parse_dist_sql_ral_total | COUNTER | proxy executor parse ral sql total |
+| build_info | GAUGE | build information |
+| proxy_info | GAUGE | proxy information, state:1 OK, state:2 CIRCUIT BREAK |
+| meta_data_info | GAUGE | meta data information, schema_count:logic number of databases, database_count:actual number of databases |
\ No newline at end of file
diff --git a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
index e90a56822dd..ee2c582e2f4 100644
--- a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.agent.config;
-import java.util.Map;
-import java.util.Set;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import java.util.Map;
+
/**
* Agent configuration.
*/
@@ -29,9 +29,5 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public final class AgentConfiguration {
- private final String applicationName;
-
- private final Set<String> ignoredPluginNames;
-
private final Map<String, PluginConfiguration> plugins;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
index 82e0cad8bf2..7e2cca941df 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
@@ -20,11 +20,6 @@ package org.apache.shardingsphere.agent.core.config.yaml;
import lombok.Getter;
import lombok.Setter;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
/**
* YAML agent configuration.
*/
@@ -32,9 +27,5 @@ import java.util.Set;
@Setter
public final class YamlAgentConfiguration {
- private String applicationName = "shardingsphere-agent";
-
- private Set<String> ignoredPluginNames = new HashSet<>();
-
- private Map<String, YamlPluginConfiguration> plugins = new LinkedHashMap<>();
+ private YamlPluginCategoryConfiguration plugins;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java
similarity index 76%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java
index 82e0cad8bf2..eab341f1bc2 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java
@@ -20,21 +20,19 @@ package org.apache.shardingsphere.agent.core.config.yaml;
import lombok.Getter;
import lombok.Setter;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Set;
/**
- * YAML agent configuration.
+ * YAML plugin category configuration.
*/
@Getter
@Setter
-public final class YamlAgentConfiguration {
+public final class YamlPluginCategoryConfiguration {
- private String applicationName = "shardingsphere-agent";
+ private Map<String, YamlPluginConfiguration> logging = new LinkedHashMap<>();
- private Set<String> ignoredPluginNames = new HashSet<>();
+ private Map<String, YamlPluginConfiguration> metrics = new LinkedHashMap<>();
- private Map<String, YamlPluginConfiguration> plugins = new LinkedHashMap<>();
+ private Map<String, YamlPluginConfiguration> tracing = new LinkedHashMap<>();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
index 6554f611a9f..47d18faaa20 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginCategoryConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginConfiguration;
import java.util.LinkedHashMap;
@@ -42,10 +43,23 @@ public final class YamlAgentConfigurationSwapper {
*/
public static AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
Map<String, PluginConfiguration> configurationMap = new LinkedHashMap<>();
- for (Entry<String, YamlPluginConfiguration> entry : yamlConfig.getPlugins().entrySet()) {
- configurationMap.put(entry.getKey(), transform(entry.getValue()));
+ YamlPluginCategoryConfiguration plugins = yamlConfig.getPlugins();
+ if (null != plugins) {
+ configurationMap.putAll(transformPluginConfigurationMap(plugins.getLogging()));
+ configurationMap.putAll(transformPluginConfigurationMap(plugins.getMetrics()));
+ configurationMap.putAll(transformPluginConfigurationMap(plugins.getTracing()));
}
- return new AgentConfiguration(yamlConfig.getApplicationName(), yamlConfig.getIgnoredPluginNames(), configurationMap);
+ return new AgentConfiguration(configurationMap);
+ }
+
+ private static Map<String, PluginConfiguration> transformPluginConfigurationMap(final Map<String, YamlPluginConfiguration> yamlConfigurationMap) {
+ Map<String, PluginConfiguration> configurationMap = new LinkedHashMap<>();
+ if (null != yamlConfigurationMap && yamlConfigurationMap.size() > 0) {
+ for (Entry<String, YamlPluginConfiguration> entry : yamlConfigurationMap.entrySet()) {
+ configurationMap.put(entry.getKey(), transform(entry.getValue()));
+ }
+ }
+ return configurationMap;
}
private static PluginConfiguration transform(final YamlPluginConfiguration yamlConfig) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
index f93079b722c..fe0b7f400fe 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
@@ -44,6 +44,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -108,7 +109,6 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable, P
return;
}
Map<String, PluginInterceptorPoint> pointMap = new HashMap<>();
- Set<String> ignoredPluginNames = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
for (File each : jarFiles) {
outputStream.reset();
@@ -117,10 +117,20 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable, P
log.info("Loaded jar {}", each.getName());
}
}
- loadPluginDefinitionServices(ignoredPluginNames, pointMap);
+ Collection<String> pluginNames = getPluginNames();
+ loadPluginDefinitionServices(pluginNames, pointMap);
interceptorPointMap = ImmutableMap.<String, PluginInterceptorPoint>builder().putAll(pointMap).build();
}
+ private Collection<String> getPluginNames() {
+ AgentConfiguration configuration = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class);
+ Set<String> pluginNames = new HashSet<>();
+ if (null != configuration && null != configuration.getPlugins()) {
+ pluginNames.addAll(configuration.getPlugins().keySet());
+ }
+ return pluginNames;
+ }
+
/**
* To find all intercepting target classes then to build TypeMatcher.
*
@@ -238,10 +248,10 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable, P
}
}
- private void loadPluginDefinitionServices(final Set<String> ignoredPluginNames, final Map<String, PluginInterceptorPoint> pointMap) {
+ private void loadPluginDefinitionServices(final Collection<String> pluginNames, final Map<String, PluginInterceptorPoint> pointMap) {
PluginServiceLoader.newServiceInstances(PluginDefinitionService.class)
.stream()
- .filter(each -> ignoredPluginNames.isEmpty() || !ignoredPluginNames.contains(each.getType()))
+ .filter(each -> pluginNames.contains(each.getType()))
.forEach(each -> buildPluginInterceptorPointMap(each, pointMap));
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
index 2a3ab181390..5c5be3765aa 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
@@ -20,15 +20,12 @@ package org.apache.shardingsphere.agent.core.plugin;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
/**
* Plugin boot service manager.
@@ -43,11 +40,7 @@ public final class PluginBootServiceManager {
* @param pluginConfigurationMap plugin configuration map
*/
public static void startAllServices(final Map<String, PluginConfiguration> pluginConfigurationMap) {
- Set<String> ignoredPluginNames = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
for (Entry<String, PluginConfiguration> entry : pluginConfigurationMap.entrySet()) {
- if (!ignoredPluginNames.isEmpty() && ignoredPluginNames.contains(entry.getKey())) {
- continue;
- }
AgentTypedSPIRegistry.getRegisteredServiceOptional(PluginBootService.class, entry.getKey()).ifPresent(optional -> {
try {
log.info("Start plugin: {}", optional.getType());
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
index 2daa053734e..0ed75454ea4 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
@@ -15,35 +15,39 @@
# limitations under the License.
#
-applicationName: shardingsphere
-ignoredPluginNames:
- - Jaeger
- - Opentracing
-
plugins:
- prometheus:
- host: "localhost"
- port: 9090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- JAEGER_REPORTER_LOG_SPANS: "true"
- JAEGER_REPORTER_FLUSH_INTERVAL: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere"
- URL_VERSION: "/api/v2/spans"
- Opentracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- Logging:
- props:
- LEVEL: "INFO"
+ logging:
+ BaseLogging:
+ props:
+ level: "INFO"
+ metrics:
+ Prometheus:
+ host: "localhost"
+ port: 9090
+ props:
+ jvm-information-collector-enabled: "true"
+ tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# jaeger-reporter-log-spans: "true"
+# jaeger-reporter-flush-interval: "1"
+ Zipkin:
+ host: "localhost"
+ port: 9411
+ props:
+ service-name: "shardingsphere"
+ url-version: "/api/v2/spans"
+ sampler-type: "const"
+ sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+ OpenTelemetry:
+ props:
+ otel-resource-attributes: "service.name=shardingsphere"
+ otel-traces-exporter: "zipkin"
diff --git a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
index 83544b10390..271181c381e 100644
--- a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
@@ -15,43 +15,37 @@
# limitations under the License.
#
-applicationName: shardingsphere
-ignoredPluginNames:
- - Jaeger
- - OpenTracing
- - Zipkin
- - OpenTelemetry
- - Logging
- - Prometheus
-
plugins:
- Prometheus:
- host: "localhost"
- port: 9090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere"
- URL_VERSION: "/api/v2/spans"
- SAMPLER_TYPE: "const"
- SAMPLER_PARAM: "1"
- OpenTracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- OpenTelemetry:
- props:
- otel.resource.attributes: "service.name=shardingsphere"
- otel.traces.exporter: "zipkin"
- Logging:
- props:
- LEVEL: "INFO"
+# logging:
+# BaseLogging:
+# props:
+# level: "INFO"
+# metrics:
+# Prometheus:
+# host: "localhost"
+# port: 9090
+# props:
+# jvm-information-collector-enabled: "true"
+# tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# Zipkin:
+# host: "localhost"
+# port: 9411
+# props:
+# service-name: "shardingsphere"
+# url-version: "/api/v2/spans"
+# sampler-type: "const"
+# sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+# OpenTelemetry:
+# props:
+# otel-resource-attributes: "service.name=shardingsphere"
+# otel-traces-exporter: "zipkin"
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingPluginDefinitionService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingPluginDefinitionService.java
index abad4721d35..632a3b23ee9 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingPluginDefinitionService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingPluginDefinitionService.java
@@ -41,6 +41,6 @@ public final class BaseLoggingPluginDefinitionService extends AbstractPluginDefi
@Override
public String getType() {
- return "Logging";
+ return "BaseLogging";
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
index 6cb0a6d1ff2..29bc7483fdc 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-logging/shardingsphere-agent-logging-base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
@@ -35,6 +35,6 @@ public final class BaseLoggingPluginBootService implements PluginBootService {
@Override
public String getType() {
- return "Logging";
+ return "BaseLogging";
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdvice.java
index 7da41cb5644..a1f3c4044e5 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdvice.java
@@ -52,7 +52,7 @@ public final class SQLRouteEngineAdvice implements InstanceMethodAroundAdvice {
@Override
public void beforeMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
- QueryContext queryContext = (QueryContext) args[0];
+ QueryContext queryContext = (QueryContext) args[1];
SQLStatement sqlStatement = queryContext.getSqlStatementContext().getSqlStatement();
if (sqlStatement instanceof InsertStatement) {
MetricsPool.get(MetricIds.ROUTE_SQL_INSERT).ifPresent(MetricsWrapper::inc);
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
index 5405d56b9ef..611bd9491f0 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
import org.apache.shardingsphere.agent.metrics.api.fixture.FixtureWrapper;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
@@ -70,7 +71,7 @@ public final class SQLRouteEngineAdviceTest extends MetricsAdviceBaseTest {
public void assertRoute(final String metricIds, final QueryContext queryContext) {
MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
- sqlRouteEngineAdvice.beforeMethod(targetObject, mock(Method.class), new Object[]{queryContext}, new MethodInvocationResult());
+ sqlRouteEngineAdvice.beforeMethod(targetObject, mock(Method.class), new Object[]{new ConnectionContext(), queryContext}, new MethodInvocationResult());
FixtureWrapper wrapper = (FixtureWrapper) MetricsPool.get(metricIds).get();
assertTrue(MetricsPool.get(metricIds).isPresent());
assertThat(((FixtureWrapper) MetricsPool.get(metricIds).get()).getFixtureValue(), is(1.0));
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
index 431a62c4414..0ed75454ea4 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
@@ -15,33 +15,39 @@
# limitations under the License.
#
-applicationName: shardingsphere
-ignoredPluginNames:
- - Jaeger
- - OpenTracing
-
plugins:
- prometheus:
- host: "localhost"
- port: 9090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- JAEGER_REPORTER_LOG_SPANS: "true"
- JAEGER_REPORTER_FLUSH_INTERVAL: "1"
- Zipkin:
- host: "localhost"
- port: 9441
- props:
- NAME: "Zipkin"
- Opentracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- Logging:
- props:
- LEVEL: "INFO"
+ logging:
+ BaseLogging:
+ props:
+ level: "INFO"
+ metrics:
+ Prometheus:
+ host: "localhost"
+ port: 9090
+ props:
+ jvm-information-collector-enabled: "true"
+ tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# jaeger-reporter-log-spans: "true"
+# jaeger-reporter-flush-interval: "1"
+ Zipkin:
+ host: "localhost"
+ port: 9411
+ props:
+ service-name: "shardingsphere"
+ url-version: "/api/v2/spans"
+ sampler-type: "const"
+ sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+ OpenTelemetry:
+ props:
+ otel-resource-attributes: "service.name=shardingsphere"
+ otel-traces-exporter: "zipkin"
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
index 396324b54e9..0a7c33db8bf 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
@@ -39,6 +39,8 @@ import java.net.InetSocketAddress;
@Slf4j
public final class PrometheusPluginBootService implements PluginBootService {
+ private static final String KEY_JVM_INFORMATION_COLLECTOR_ENABLED = "jvm-information-collector-enabled";
+
private HTTPServer httpServer;
@Override
@@ -49,7 +51,7 @@ public final class PrometheusPluginBootService implements PluginBootService {
}
private void startServer(final PluginConfiguration pluginConfig) {
- registerCollector(Boolean.parseBoolean(pluginConfig.getProps().getProperty("JVM_INFORMATION_COLLECTOR_ENABLED")));
+ registerCollector(Boolean.parseBoolean(pluginConfig.getProps().getProperty(KEY_JVM_INFORMATION_COLLECTOR_ENABLED)));
InetSocketAddress socketAddress = getSocketAddress(pluginConfig.getHost(), pluginConfig.getPort());
try {
httpServer = new HTTPServer(socketAddress, CollectorRegistry.defaultRegistry, true);
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
index 5c919257d6f..82a7fd391ff 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import io.jaegertracing.Configuration;
import io.opentracing.util.GlobalTracer;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
@@ -31,26 +29,32 @@ import java.util.Optional;
*/
public final class JaegerTracingPluginBootService implements PluginBootService {
+ private static final String DEFAULT_SERVICE_NAME = "shardingsphere";
+
+ private static final String KEY_SERVICE_NAME = "service-name";
+
private Configuration config;
@SuppressWarnings("AccessOfSystemProperties")
@Override
public void start(final PluginConfiguration pluginConfig) {
pluginConfig.validate("Jaeger");
- pluginConfig.getProps().forEach((key, value) -> System.setProperty(String.valueOf(key), String.valueOf(value)));
+ pluginConfig.getProps().forEach((key, value) -> setSystemProperty(String.valueOf(key), String.valueOf(value)));
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
.withSender(Configuration.SenderConfiguration.fromEnv().withAgentHost(pluginConfig.getHost()).withAgentPort(pluginConfig.getPort()));
- String serviceName = Optional.ofNullable(pluginConfig.getProps().getProperty("SERVICE_NAME")).orElse("shardingsphere-agent");
+ String serviceName = Optional.ofNullable(pluginConfig.getProps().getProperty(KEY_SERVICE_NAME)).orElse(DEFAULT_SERVICE_NAME);
config = new Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig);
if (!GlobalTracer.isRegistered()) {
GlobalTracer.register(config.getTracer());
}
}
- private void checkConfiguration(final PluginConfiguration pluginConfig) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(pluginConfig.getHost()), "Jaeger hostname is required");
- Preconditions.checkArgument(pluginConfig.getPort() > 0, "Jaeger port `%d` must be a positive number");
+ private void setSystemProperty(final String key, final String value) {
+ if (!KEY_SERVICE_NAME.equalsIgnoreCase(key)) {
+ String propertyKey = key.replaceAll("-", "_").toUpperCase();
+ System.setProperty(propertyKey, String.valueOf(value));
+ }
}
@Override
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/service/OpenTelemetryTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/service/OpenTelemet [...]
index 63f233e1191..ea1bf3b7268 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/service/OpenTelemetryTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/service/OpenTelemetryTracingPluginBootService.java
@@ -26,12 +26,17 @@ public class OpenTelemetryTracingPluginBootService implements PluginBootService
@Override
public void start(final PluginConfiguration pluginConfig) {
- pluginConfig.getProps().forEach((key, value) -> System.setProperty(String.valueOf(key), String.valueOf(value)));
+ pluginConfig.getProps().forEach((key, value) -> setSystemProperty(String.valueOf(key), String.valueOf(value)));
OpenTelemetrySdk sdk = OpenTelemetrySdkAutoConfiguration.initialize();
// tracer will be created
sdk.getTracer("shardingsphere-agent");
}
+ private void setSystemProperty(final String key, final String value) {
+ String propertyKey = key.replaceAll("-", ".");
+ System.setProperty(propertyKey, String.valueOf(value));
+ }
+
@Override
public void close() {
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootService.java
index 081bfbaf7bc..3ba67c20849 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootService.java
@@ -28,9 +28,11 @@ import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
*/
public final class OpenTracingPluginBootService implements PluginBootService {
+ private static final String KEY_OPENTRACING_TRACER_CLASS_NAME = "opentracing-tracer-class-name";
+
@Override
public void start(final PluginConfiguration pluginConfig) {
- String tracerClassName = pluginConfig.getProps().getProperty("OPENTRACING_TRACER_CLASS_NAME");
+ String tracerClassName = pluginConfig.getProps().getProperty(KEY_OPENTRACING_TRACER_CLASS_NAME);
Preconditions.checkNotNull(tracerClassName, "Can not find opentracing tracer implementation in you config");
try {
init((Tracer) Class.forName(tracerClassName).getDeclaredConstructor().newInstance());
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootSer [...]
index 9bc9e1cf085..0812d589cbc 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java
@@ -38,7 +38,7 @@ public final class OpenTracingPluginBootServiceTest {
private Properties createProperties() {
Properties result = new Properties();
- result.setProperty("OPENTRACING_TRACER_CLASS_NAME", "io.opentracing.mock.MockTracer");
+ result.setProperty("opentracing-tracer-class-name", "io.opentracing.mock.MockTracer");
return result;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
index aa7738af02b..00ba309900e 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
@@ -34,6 +34,22 @@ import java.util.Properties;
*/
public final class ZipkinTracingPluginBootService implements PluginBootService {
+ private static final String DEFAULT_SERVICE_NAME = "shardingsphere";
+
+ private static final String KEY_SERVICE_NAME = "service-name";
+
+ private static final String DEFAULT_URL_VERSION = "/api/v2/spans";
+
+ private static final String KEY_URL_VERSION = "url-version";
+
+ private static final String DEFAULT_SAMPLER_TYPE = "const";
+
+ private static final String KEY_SAMPLER_TYPE = "sampler-type";
+
+ private static final String DEFAULT_SAMPLER_PARAM = "1";
+
+ private static final String KEY_SAMPLER_PARAM = "sampler-param";
+
private AsyncZipkinSpanHandler zipkinSpanHandler;
private OkHttpSender sender;
@@ -44,8 +60,8 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
public void start(final PluginConfiguration pluginConfig) {
pluginConfig.validate("Zipkin");
Properties props = pluginConfig.getProps();
- String urlVersion = Optional.ofNullable(props.getProperty("URL_VERSION")).orElse("/api/v2/spans");
- String serviceName = Optional.ofNullable(props.getProperty("SERVICE_NAME")).orElse("shardingsphere-agent");
+ String urlVersion = Optional.ofNullable(props.getProperty(KEY_URL_VERSION)).orElse(DEFAULT_URL_VERSION);
+ String serviceName = Optional.ofNullable(props.getProperty(KEY_SERVICE_NAME)).orElse(DEFAULT_SERVICE_NAME);
sender = OkHttpSender.create(String.format("http://%s:%s%s", pluginConfig.getHost(), pluginConfig.getPort(), urlVersion));
Sampler sampler = createSampler(pluginConfig);
zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
@@ -53,8 +69,8 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
}
private Sampler createSampler(final PluginConfiguration pluginConfig) {
- String samplerType = Optional.ofNullable(pluginConfig.getProps().getProperty("SAMPLER_TYPE")).orElse("const");
- String samplerParameter = Optional.ofNullable(pluginConfig.getProps().getProperty("SAMPLER_PARAM")).orElse("1");
+ String samplerType = Optional.ofNullable(pluginConfig.getProps().getProperty(KEY_SAMPLER_TYPE)).orElse(DEFAULT_SAMPLER_TYPE);
+ String samplerParameter = Optional.ofNullable(pluginConfig.getProps().getProperty(KEY_SAMPLER_PARAM)).orElse(DEFAULT_SAMPLER_PARAM);
switch (samplerType) {
case "const":
return "0".equals(samplerParameter) ? Sampler.NEVER_SAMPLE : Sampler.ALWAYS_SAMPLE;
diff --git a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/resources/docker/proxy/conf/agent.yaml b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/resources/docker/proxy/conf/agent.yaml
index 2779540532f..9e18f54da94 100644
--- a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/resources/docker/proxy/conf/agent.yaml
+++ b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/resources/docker/proxy/conf/agent.yaml
@@ -15,40 +15,37 @@
# limitations under the License.
#
-applicationName: shardingsphere
-ignoredPluginNames:
- - Jaeger
- - Opentracing
- - Zipkin
- - OpenTelemetry
-
plugins:
- prometheus:
- port: 18090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- JAEGER_REPORTER_LOG_SPANS: "true"
- JAEGER_REPORTER_FLUSH_INTERVAL: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere"
- URL_VERSION: "/api/v2/spans"
- Opentracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- OpenTelemetry:
- props:
- otel.resource.attributes: "service.name=shardingsphere"
- otel.traces.exporter: "zipkin"
- Logging:
- props:
- LEVEL: "INFO"
+ logging:
+ BaseLogging:
+ props:
+ level: "INFO"
+ metrics:
+ Prometheus:
+ host: "localhost"
+ port: 18090
+ props:
+ jvm-information-collector-enabled: "true"
+ tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# Zipkin:
+# host: "localhost"
+# port: 9411
+# props:
+# service-name: "shardingsphere"
+# url-version: "/api/v2/spans"
+# sampler-type: "const"
+# sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+# OpenTelemetry:
+# props:
+# otel-resource-attributes: "service.name=shardingsphere"
+# otel-traces-exporter: "zipkin"
diff --git a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-opentelemetry/src/test/resources/docker/proxy/conf/agent.yaml b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-opentelemetry/src/test/resources/docker/proxy/conf/agent.yaml
index a22737e5992..35efa5725f7 100644
--- a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-opentelemetry/src/test/resources/docker/proxy/conf/agent.yaml
+++ b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-opentelemetry/src/test/resources/docker/proxy/conf/agent.yaml
@@ -15,41 +15,40 @@
# limitations under the License.
#
-applicationName: shardingsphere
-ignoredPluginNames:
- - Jaeger
- - Opentracing
- - Zipkin
- - Prometheus
-
plugins:
- prometheus:
- port: 18090
- props:
- JVM_INFORMATION_COLLECTOR_ENABLED : "true"
- Jaeger:
- host: "localhost"
- port: 5775
- props:
- SERVICE_NAME: "shardingsphere"
- JAEGER_SAMPLER_TYPE: "const"
- JAEGER_SAMPLER_PARAM: "1"
- JAEGER_REPORTER_LOG_SPANS: "true"
- JAEGER_REPORTER_FLUSH_INTERVAL: "1"
- Zipkin:
- host: "localhost"
- port: 9411
- props:
- SERVICE_NAME: "shardingsphere"
- URL_VERSION: "/api/v2/spans"
- Opentracing:
- props:
- OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
- OpenTelemetry:
- props:
- otel.resource.attributes: "service.name=shardingsphere"
- otel.traces.exporter: "zipkin"
- otel.exporter.zipkin.endpoint: "http://zipkin.agent.tracing.opentelemetry.host:9411/api/v2/spans"
- Logging:
- props:
- LEVEL: "INFO"
+ logging:
+ BaseLogging:
+ props:
+ level: "INFO"
+ metrics:
+# Prometheus:
+# host: "localhost"
+# port: 18090
+# props:
+# jvm-information-collector-enabled: "true"
+ tracing:
+# Jaeger:
+# host: "localhost"
+# port: 5775
+# props:
+# service-name: "shardingsphere"
+# jaeger-sampler-type: "const"
+# jaeger-sampler-param: "1"
+# jaeger-reporter-log-spans: "true"
+# jaeger-reporter-flush-interval: "1"
+# Zipkin:
+# host: "localhost"
+# port: 9411
+# props:
+# service-name: "shardingsphere"
+# url-version: "/api/v2/spans"
+# sampler-type: "const"
+# sampler-param: "1"
+# OpenTracing:
+# props:
+# opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
+ OpenTelemetry:
+ props:
+ otel-resource-attributes: "service.name=shardingsphere"
+ otel-traces-exporter: "zipkin"
+ otel-exporter-zipkin-endpoint: "http://zipkin.agent.tracing.opentelemetry.host:9411/api/v2/spans"