未验证 提交 44cae97c 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Set up restrict length rules for service, instance and endpoint (#4633)

* Set up restrict length rules for service, instance and endpoint

* Adjust two env names.
上级 6fe2041b
......@@ -62,10 +62,10 @@ public class StringFormatGroup {
public FormatResult format(String string) {
for (PatternRule rule : rules) {
if (rule.getPattern().matcher(string).matches()) {
return new FormatResult(true, rule.getName());
return new FormatResult(true, rule.getName(), string);
}
}
return new FormatResult(false, string);
return new FormatResult(false, string, string);
}
@Getter
......@@ -73,6 +73,7 @@ public class StringFormatGroup {
public static class FormatResult {
private final boolean match;
private final String name;
private final String replacedName;
}
@Getter
......
......@@ -39,7 +39,6 @@
<outputDirectory>/config</outputDirectory>
<includes>
<include>log4j2.xml</include>
<include>application.yml</include>
<include>alarm-settings.yml</include>
<include>alarm-settings-sample.yml</include>
</includes>
......@@ -47,6 +46,7 @@
<fileSet>
<directory>${project.basedir}/../oap-server/server-bootstrap/src/main/resources</directory>
<includes>
<include>application.yml</include>
<include>component-libraries.yml</include>
<include>official_analysis.oal</include>
<include>gateways.yml</include>
......
......@@ -39,7 +39,6 @@
<outputDirectory>/config</outputDirectory>
<includes>
<include>log4j2.xml</include>
<include>application.yml</include>
<include>alarm-settings.yml</include>
<include>alarm-settings-sample.yml</include>
</includes>
......@@ -47,6 +46,7 @@
<fileSet>
<directory>${project.basedir}/../oap-server/server-bootstrap/src/main/resources</directory>
<includes>
<include>application.yml</include>
<include>component-libraries.yml</include>
<include>official_analysis.oal</include>
<include>gateways.yml</include>
......
# 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.
cluster:
selector: ${SW_CLUSTER:standalone}
standalone:
# Please check your ZooKeeper is 3.5+, However, it is also compatible with ZooKeeper 3.4.x. Replace the ZooKeeper 3.5+
# library the oap-libs folder with your ZooKeeper 3.4.x library.
zookeeper:
nameSpace: ${SW_NAMESPACE:""}
hostPort: ${SW_CLUSTER_ZK_HOST_PORT:localhost:2181}
# Retry Policy
baseSleepTimeMs: ${SW_CLUSTER_ZK_SLEEP_TIME:1000} # initial amount of time to wait between retries
maxRetries: ${SW_CLUSTER_ZK_MAX_RETRIES:3} # max number of times to retry
# Enable ACL
enableACL: ${SW_ZK_ENABLE_ACL:false} # disable ACL in default
schema: ${SW_ZK_SCHEMA:digest} # only support digest schema
expression: ${SW_ZK_EXPRESSION:skywalking:skywalking}
kubernetes:
watchTimeoutSeconds: ${SW_CLUSTER_K8S_WATCH_TIMEOUT:60}
namespace: ${SW_CLUSTER_K8S_NAMESPACE:default}
labelSelector: ${SW_CLUSTER_K8S_LABEL:app=collector,release=skywalking}
uidEnvName: ${SW_CLUSTER_K8S_UID:SKYWALKING_COLLECTOR_UID}
consul:
serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
# Consul cluster nodes, example: 10.0.0.1:8500,10.0.0.2:8500,10.0.0.3:8500
hostPort: ${SW_CLUSTER_CONSUL_HOST_PORT:localhost:8500}
aclToken: ${SW_CLUSTER_CONSUL_ACLTOKEN:""}
nacos:
serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
hostPort: ${SW_CLUSTER_NACOS_HOST_PORT:localhost:8848}
# Nacos Configuration namespace
namespace: ${SW_CLUSTER_NACOS_NAMESPACE:"public"}
etcd:
serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
# etcd cluster nodes, example: 10.0.0.1:2379,10.0.0.2:2379,10.0.0.3:2379
hostPort: ${SW_CLUSTER_ETCD_HOST_PORT:localhost:2379}
core:
selector: ${SW_CORE:default}
default:
# Mixed: Receive agent data, Level 1 aggregate, Level 2 aggregate
# Receiver: Receive agent data, Level 1 aggregate
# Aggregator: Level 2 aggregate
role: ${SW_CORE_ROLE:Mixed} # Mixed/Receiver/Aggregator
restHost: ${SW_CORE_REST_HOST:0.0.0.0}
restPort: ${SW_CORE_REST_PORT:12800}
restContextPath: ${SW_CORE_REST_CONTEXT_PATH:/}
gRPCHost: ${SW_CORE_GRPC_HOST:0.0.0.0}
gRPCPort: ${SW_CORE_GRPC_PORT:11800}
gRPCSslEnabled: ${SW_CORE_GRPC_SSL_ENABLED:false}
gRPCSslKeyPath: ${SW_CORE_GRPC_SSL_KEY_PATH:""}
gRPCSslCertChainPath: ${SW_CORE_GRPC_SSL_CERT_CHAIN_PATH:""}
gRPCSslTrustedCAPath: ${SW_CORE_GRPC_SSL_TRUSTED_CA_PATH:""}
downsampling:
- Hour
- Day
- Month
# Set a timeout on metrics data. After the timeout has expired, the metrics data will automatically be deleted.
enableDataKeeperExecutor: ${SW_CORE_ENABLE_DATA_KEEPER_EXECUTOR:true} # Turn it off then automatically metrics data delete will be close.
dataKeeperExecutePeriod: ${SW_CORE_DATA_KEEPER_EXECUTE_PERIOD:5} # How often the data keeper executor runs periodically, unit is minute
recordDataTTL: ${SW_CORE_RECORD_DATA_TTL:3} # Unit is day
metricsDataTTL: ${SW_CORE_RECORD_DATA_TTL:7} # Unit is day
# Cache metric data for 1 minute to reduce database queries, and if the OAP cluster changes within that minute,
# the metrics may not be accurate within that minute.
enableDatabaseSession: ${SW_CORE_ENABLE_DATABASE_SESSION:true}
topNReportPeriod: ${SW_CORE_TOPN_REPORT_PERIOD:10} # top_n record worker report cycle, unit is minute
# Extra model column are the column defined by in the codes, These columns of model are not required logically in aggregation or further query,
# and it will cause more load for memory, network of OAP and storage.
# But, being activated, user could see the name in the storage entities, which make users easier to use 3rd party tool, such as Kibana->ES, to query the data by themselves.
activeExtraModelColumns: ${SW_CORE_ACTIVE_EXTRA_MODEL_COLUMNS:false}
# The max length of the endpoint name.
# In the current practice, we don't recommend the length over 190.
endpointNameMaxLength: ${SW_CORE_ENDPOINT_NAME_MAX_LENGTH:150}
storage:
selector: ${SW_STORAGE:h2}
elasticsearch:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:""}
trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are managed by 3rd party tool.
dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
elasticsearch7:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"}
trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}
dayStep: ${SW_STORAGE_DAY_STEP:1} # Represent the number of days in the one minute/hour/day index.
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""} # Secrets management file in the properties format includes the username, password, which are managed by 3rd party tool.
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
h2:
driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
user: ${SW_STORAGE_H2_USER:sa}
metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
mysql:
properties:
jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:3306/swtest"}
dataSource.user: ${SW_DATA_SOURCE_USER:root}
dataSource.password: ${SW_DATA_SOURCE_PASSWORD:root@1234}
dataSource.cachePrepStmts: ${SW_DATA_SOURCE_CACHE_PREP_STMTS:true}
dataSource.prepStmtCacheSize: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE:250}
dataSource.prepStmtCacheSqlLimit: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT:2048}
dataSource.useServerPrepStmts: ${SW_DATA_SOURCE_USE_SERVER_PREP_STMTS:true}
metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000}
influxdb:
url: ${SW_STORAGE_INFLUXDB_URL:http://localhost:8086}
user: ${SW_STORAGE_INFLUXDB_USER:root}
password: ${SW_STORAGE_INFLUXDB_PASSWORD:}
database: ${SW_STORAGE_INFLUXDB_DATABASE:skywalking}
actions: ${SW_STORAGE_INFLUXDB_ACTIONS:1000} # the number of actions to collect
duration: ${SW_STORAGE_INFLUXDB_DURATION:1000} # the time to wait at most (milliseconds)
fetchTaskLogMaxSize: ${SW_STORAGE_INFLUXDB_FETCH_TASK_LOG_MAX_SIZE:5000} # the max number of fetch task log in a request
receiver-sharing-server:
selector: ${SW_RECEIVER_SHARING_SERVER:default}
default:
authentication: ${SW_AUTHENTICATION:""}
receiver-register:
selector: ${SW_RECEIVER_REGISTER:default}
default:
receiver-trace:
selector: ${SW_RECEIVER_TRACE:default}
default:
sampleRate: ${SW_TRACE_SAMPLE_RATE:10000} # The sample rate precision is 1/10000. 10000 means 100% sample in default.
slowDBAccessThreshold: ${SW_SLOW_DB_THRESHOLD:default:200,mongodb:100} # The slow database access thresholds. Unit ms.
receiver-jvm:
selector: ${SW_RECEIVER_JVM:default}
default:
receiver-clr:
selector: ${SW_RECEIVER_CLR:default}
default:
receiver-profile:
selector: ${SW_RECEIVER_PROFILE:default}
default:
service-mesh:
selector: ${SW_SERVICE_MESH:default}
default:
istio-telemetry:
selector: ${SW_ISTIO_TELEMETRY:default}
default:
envoy-metric:
selector: ${SW_ENVOY_METRIC:default}
default:
alsHTTPAnalysis: ${SW_ENVOY_METRIC_ALS_HTTP_ANALYSIS:""}
receiver_zipkin:
selector: ${SW_RECEIVER_ZIPKIN:-}
default:
host: ${SW_RECEIVER_ZIPKIN_HOST:0.0.0.0}
port: ${SW_RECEIVER_ZIPKIN_PORT:9411}
contextPath: ${SW_RECEIVER_ZIPKIN_CONTEXT_PATH:/}
receiver_jaeger:
selector: ${SW_RECEIVER_JAEGER:-}
default:
gRPCHost: ${SW_RECEIVER_JAEGER_HOST:0.0.0.0}
gRPCPort: ${SW_RECEIVER_JAEGER_PORT:14250}
query:
selector: ${SW_QUERY:graphql}
graphql:
path: ${SW_QUERY_GRAPHQL_PATH:/graphql}
alarm:
selector: ${SW_ALARM:default}
default:
telemetry:
selector: ${SW_TELEMETRY:none}
none:
prometheus:
host: ${SW_TELEMETRY_PROMETHEUS_HOST:0.0.0.0}
port: ${SW_TELEMETRY_PROMETHEUS_PORT:1234}
so11y:
prometheusExporterEnabled: ${SW_TELEMETRY_SO11Y_PROMETHEUS_ENABLED:true}
prometheusExporterHost: ${SW_TELEMETRY_PROMETHEUS_HOST:0.0.0.0}
prometheusExporterPort: ${SW_TELEMETRY_PROMETHEUS_PORT:1234}
receiver-so11y:
selector: ${SW_RECEIVER_SO11Y:-}
default:
configuration:
selector: ${SW_CONFIGURATION:none}
none:
apollo:
apolloMeta: http://106.12.25.204:8080
apolloCluster: default
apolloEnv: ""
appId: skywalking
period: 5
nacos:
# Nacos Server Host
serverAddr: 127.0.0.1
# Nacos Server Port
port: 8848
# Nacos Configuration Group
group: 'skywalking'
# Nacos Configuration namespace
namespace: ''
# Unit seconds, sync period. Default fetch every 60 seconds.
period : 60
# the name of current cluster, set the name if you want to upstream system known.
clusterName: "default"
zookeeper:
period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
nameSpace: /default
hostPort: localhost:2181
# Retry Policy
baseSleepTimeMs: 1000 # initial amount of time to wait between retries
maxRetries: 3 # max number of times to retry
etcd:
period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
group : 'skywalking'
serverAddr: localhost:2379
clusterName: "default"
consul:
# Consul host and ports, separated by comma, e.g. 1.2.3.4:8500,2.3.4.5:8500
hostAndPorts: ${consul.address}
# Sync period in seconds. Defaults to 60 seconds.
period: 1
# Consul aclToken
#aclToken: ${consul.aclToken}
exporter:
selector: ${SW_EXPORTER:-}
grpc:
targetHost: ${SW_EXPORTER_GRPC_HOST:127.0.0.1}
targetPort: ${SW_EXPORTER_GRPC_PORT:9870}
......@@ -41,7 +41,7 @@ storage:
# other configurations
```
1. **`core`** is the module.
1. **`storage`** is the module.
1. **`selector`** selects one out of the all providers listed below, the unselected ones take no effect as if they were deleted.
1. **`default`** is the default implementor of core module.
1. `driver`, `url`, ... `metadataQueryMaxSize` are all setting items of the implementor.
......
......@@ -72,13 +72,13 @@ This is the properties list supported in `agent/config/agent.config`.
property key | Description | Default |
----------- | ---------- | --------- |
`agent.namespace` | Namespace isolates headers in cross process propagation. The HEADER name will be `HeaderName:Namespace`. | Not set |
`agent.service_name` | Application(5.x)/Service(6.x) code is showed in sky-walking-ui. Suggestion: set a unique name for each service, service instance nodes share the same code, Max length is 50(UTF-8 char) | `Your_ApplicationName` |
`agent.service_name` | The service name to represent a logic group providing the same capabilities/logic. Suggestion: set a unique name for every logic service group, service instance nodes share the same code, Max length is 50(UTF-8 char) | `Your_ApplicationName` |
`agent.sample_n_per_3_secs`|Negative or zero means off, by default.SAMPLE_N_PER_3_SECS means sampling N TraceSegment in 3 seconds tops.|Not set|
`agent.authentication`|Authentication active is based on backend setting, see application.yml for more details.For most scenarios, this needs backend extensions, only basic match auth provided in default implementation.|Not set|
`agent.span_limit_per_segment`|The max number of spans in a single segment. Through this config item, SkyWalking keep your application memory cost estimated.|300 |
`agent.ignore_suffix`|If the operation name of the first span is included in this set, this segment should be ignored.|Not set|
`agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder. SkyWalking team may ask for these files in order to resolve compatible problem.|Not set|
`agent.instance_name` |Instance name is the identity of an instance, should be unique in the service. If empty, SkyWalking agent will generate an 32-bit uuid. Default rule is `ServiceName` + UUID`@`hostname` as the instance name. Max length is 50(UTF-8 char)|`""`|
`agent.instance_name` |Instance name is the identity of an instance, should be unique in the service. If empty, SkyWalking agent will generate an 32-bit uuid. Default, use `UUID`@`hostname` as the instance name. Max length is 50(UTF-8 char)|`""`|
`agent.instance_properties[key]=value` | Add service instance custom properties. | Not set|
`agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|`5`|
`agent.force_reconnection_period `|Force reconnection period of grpc, based on grpc_channel_check_interval.|`1`|
......
......@@ -231,7 +231,6 @@
<exclude>log4j2.xml</exclude>
<exclude>alarm-settings.yml</exclude>
<exclude>component-libraries.yml</exclude>
<exclude>endpoint_naming_rules.properties</exclude>
<exclude>official_analysis.oal</exclude>
<exclude>gateways.yml</exclude>
<exclude>service-apdex-threshold.yml</exclude>
......
......@@ -81,9 +81,11 @@ core:
# and it will cause more load for memory, network of OAP and storage.
# But, being activated, user could see the name in the storage entities, which make users easier to use 3rd party tool, such as Kibana->ES, to query the data by themselves.
activeExtraModelColumns: ${SW_CORE_ACTIVE_EXTRA_MODEL_COLUMNS:false}
# The max length of the endpoint name.
# In the current practice, we don't recommend the length over 190.
endpointNameMaxLength: ${SW_CORE_ENDPOINT_NAME_MAX_LENGTH:150}
# The max length of service + instance names should be less than 200
serviceNameMaxLength: ${SW_SERVICE_NAME_MAX_LENGTH:70}
instanceNameMaxLength: ${SW_INSTANCE_NAME_MAX_LENGTH:70}
# The max length of service + endpoint names should be less than 240
endpointNameMaxLength: ${SW_ENDPOINT_NAME_MAX_LENGTH:150}
storage:
selector: ${SW_STORAGE:h2}
elasticsearch:
......@@ -248,19 +250,19 @@ configuration:
# Nacos Configuration namespace
namespace: ''
# Unit seconds, sync period. Default fetch every 60 seconds.
period : 60
period: 60
# the name of current cluster, set the name if you want to upstream system known.
clusterName: "default"
zookeeper:
period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
period: 60 # Unit seconds, sync period. Default fetch every 60 seconds.
nameSpace: /default
hostPort: localhost:2181
# Retry Policy
baseSleepTimeMs: 1000 # initial amount of time to wait between retries
maxRetries: 3 # max number of times to retry
etcd:
period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
group : 'skywalking'
period: 60 # Unit seconds, sync period. Default fetch every 60 seconds.
group: 'skywalking'
serverAddr: localhost:2379
clusterName: "default"
consul:
......
#
# 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.
#
#
istio.mixer.v1.Mixer=.*/istio.mixer.v1.Mixer/.*
\ No newline at end of file
......@@ -26,6 +26,7 @@ import org.apache.skywalking.oap.server.core.command.CommandService;
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.config.DownSamplingConfigService;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.profile.ProfileTaskMutationService;
import org.apache.skywalking.oap.server.core.query.AggregationQueryService;
import org.apache.skywalking.oap.server.core.query.AlarmQueryService;
......@@ -53,7 +54,6 @@ import org.apache.skywalking.oap.server.library.module.ModuleDefine;
*/
public class CoreModule extends ModuleDefine {
public static final String NAME = "core";
private static int ENDPOINT_NAME_MAX_LENGTH = 150;
public CoreModule() {
super(NAME);
......@@ -64,6 +64,7 @@ public class CoreModule extends ModuleDefine {
List<Class> classes = new ArrayList<>();
classes.add(ConfigService.class);
classes.add(DownSamplingConfigService.class);
classes.add(NamingLengthControl.class);
classes.add(IComponentLibraryCatalogService.class);
classes.add(IWorkerInstanceGetter.class);
......@@ -81,26 +82,6 @@ public class CoreModule extends ModuleDefine {
return classes.toArray(new Class[] {});
}
/**
* Format endpoint name by using the length config in the core module. This is a global rule, every place including
* endpoint as the {@link org.apache.skywalking.oap.server.core.source.Source} should follow this for any core
* module implementation.
*
* @param endpointName raw data, literal string.
* @return the string, which length less than or equals {@link #ENDPOINT_NAME_MAX_LENGTH};
*/
public static String formatEndpointName(String endpointName) {
if (endpointName.length() > ENDPOINT_NAME_MAX_LENGTH) {
return endpointName.substring(0, ENDPOINT_NAME_MAX_LENGTH);
} else {
return endpointName;
}
}
public static void setEndpointNameMaxLength(final int endpointNameMaxLength) {
ENDPOINT_NAME_MAX_LENGTH = endpointNameMaxLength;
}
private void addProfileService(List<Class> classes) {
classes.add(ProfileTaskMutationService.class);
classes.add(ProfileTaskQueryService.class);
......
......@@ -21,72 +21,55 @@ package org.apache.skywalking.oap.server.core;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.ScopeDefaultColumn;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
@Getter
public class CoreModuleConfig extends ModuleConfig {
@Setter
private String role = "Mixed";
@Setter
private String nameSpace;
@Setter
private String restHost;
@Setter
private int restPort;
@Setter
private int jettySelectors = 1;
@Setter
private String restContextPath;
@Setter
private String gRPCHost;
@Setter
private int gRPCPort;
@Setter
private boolean gRPCSslEnabled = false;
@Setter
private String gRPCSslKeyPath;
@Setter
private String gRPCSslCertChainPath;
@Setter
private String gRPCSslTrustedCAPath;
@Setter
private int maxConcurrentCallsPerConnection;
@Setter
private int maxMessageSize;
@Setter
private boolean enableDatabaseSession;
@Setter
private int topNReportPeriod;
private final List<String> downsampling;
/**
* The period of doing data persistence. Unit is second.
*/
@Setter
private long persistentPeriod = 3;
@Setter
private boolean enableDataKeeperExecutor = true;
@Setter
private int dataKeeperExecutePeriod = 5;
/**
* The time to live of all metrics data. Unit is day.
*/
@Setter
private int metricsDataTTL = 3;
/**
* The time to live of all record data, including tracing. Unit is Day.
*/
@Setter
private int recordDataTTL = 7;
@Setter
private int gRPCThreadPoolSize;
@Setter
private int gRPCThreadPoolQueueSize;
/**
* Timeout for cluster internal communication, in seconds.
*/
@Setter
private int remoteTimeout = 20;
/**
* The size of network address alias.
......@@ -113,6 +96,14 @@ public class CoreModuleConfig extends ModuleConfig {
* tool, such as Kibana->ES, to query the data by themselves.
*/
private boolean activeExtraModelColumns = false;
/**
* The max length of the service name.
*/
private int serviceNameMaxLength = 70;
/**
* The max length of the service instance name.
*/
private int instanceNameMaxLength = 70;
/**
* The max length of the endpoint name.
*
......
......@@ -40,6 +40,7 @@ import org.apache.skywalking.oap.server.core.config.ComponentLibraryCatalogServi
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.config.DownSamplingConfigService;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.oal.rt.OALEngine;
import org.apache.skywalking.oap.server.core.oal.rt.OALEngineLoader;
import org.apache.skywalking.oap.server.core.profile.ProfileTaskMutationService;
......@@ -131,9 +132,11 @@ public class CoreModuleProvider extends ModuleProvider {
if (moduleConfig.isActiveExtraModelColumns()) {
DefaultScopeDefine.activeExtraModelColumns();
}
if (moduleConfig.getEndpointNameMaxLength() > 0) {
CoreModule.setEndpointNameMaxLength(moduleConfig.getEndpointNameMaxLength());
}
this.registerServiceImplementation(NamingLengthControl.class, new NamingLengthControl(
moduleConfig.getServiceNameMaxLength(),
moduleConfig.getInstanceNameMaxLength(),
moduleConfig.getEndpointNameMaxLength()
));
StreamAnnotationListener streamAnnotationListener = new StreamAnnotationListener(getManager());
......
/*
* 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.skywalking.oap.server.core.config;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.library.module.Service;
/**
* NamingLengthControl provides the service to make the names of service, instance and endpoint following the length
* rules.
*/
@RequiredArgsConstructor
@Slf4j
public class NamingLengthControl implements Service {
private final int serviceNameMaxLength;
private final int instanceNameMaxLength;
private final int endpointNameMaxLength;
/**
* Format endpoint name by using the length config in the core module. This is a global rule, every place including
* service as the {@link org.apache.skywalking.oap.server.core.source.Source} should follow this for any core module
* implementation.
*
* @param serviceName raw data, literal string.
* @return the string, which length less than or equals {@link #serviceNameMaxLength};
*/
public String formatServiceName(String serviceName) {
if (serviceName.length() > serviceNameMaxLength) {
final String rename = serviceName.substring(0, serviceNameMaxLength);
if (log.isDebugEnabled()) {
log.debug(
"Service {} has been renamed to {} due to length limitation {}",
serviceName,
rename,
serviceNameMaxLength
);
}
return rename;
} else {
return serviceName;
}
}
/**
* Format endpoint name by using the length config in the core module. This is a global rule, every place including
* instance as the {@link org.apache.skywalking.oap.server.core.source.Source} should follow this for any core
* module implementation.
*
* @param instanceName raw data, literal string.
* @return the string, which length less than or equals {@link #instanceNameMaxLength};
*/
public String formatInstanceName(String instanceName) {
if (instanceName.length() > instanceNameMaxLength) {
final String rename = instanceName.substring(0, instanceNameMaxLength);
if (log.isDebugEnabled()) {
log.debug(
"Service instance {} has been renamed to {} due to length limitation {}",
instanceName,
rename,
serviceNameMaxLength
);
}
return rename;
} else {
return instanceName;
}
}
/**
* Format endpoint name by using the length config in the core module. This is a global rule, every place including
* endpoint as the {@link org.apache.skywalking.oap.server.core.source.Source} should follow this for any core
* module implementation.
*
* @param endpointName raw data, literal string.
* @return the string, which length less than or equals {@link #endpointNameMaxLength};
*/
public String formatEndpointName(String endpointName) {
if (endpointName.length() > endpointNameMaxLength) {
final String rename = endpointName.substring(0, endpointNameMaxLength);
if (log.isDebugEnabled()) {
log.debug(
"Endpoint {} has been renamed to {} due to length limitation {}",
endpointName,
rename,
serviceNameMaxLength
);
}
return rename;
} else {
return endpointName;
}
}
}
......@@ -20,8 +20,8 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
......@@ -30,6 +30,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EN
@ScopeDeclaration(id = ENDPOINT, name = "Endpoint", catalog = ENDPOINT_CATALOG_NAME)
@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class)
@Slf4j
public class Endpoint extends Source {
private String entityId;
......@@ -47,13 +48,9 @@ public class Endpoint extends Source {
}
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "name", requireDynamicActive = true)
private String name;
public void setName(final String name) {
this.name = CoreModule.formatEndpointName(name);
}
@Getter
@ScopeDefaultColumn.DefinedByField(columnName = "service_id")
private String serviceId;
......
......@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
......@@ -43,13 +42,10 @@ public class EndpointRelation extends Source {
}
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "source_endpoint_name")
private String endpoint;
public void setEndpoint(final String endpoint) {
this.endpoint = CoreModule.formatEndpointName(endpoint);
}
@Getter
@ScopeDefaultColumn.DefinedByField(columnName = "service_id")
private String serviceId;
......@@ -63,13 +59,9 @@ public class EndpointRelation extends Source {
@Setter
private String serviceInstanceName;
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "child_endpoint_name")
private String childEndpoint;
public void setChildEndpoint(final String childEndpoint) {
this.childEndpoint = CoreModule.formatEndpointName(childEndpoint);
}
@Getter
@ScopeDefaultColumn.DefinedByField(columnName = "child_service_id")
private String childServiceId;
......
......@@ -26,6 +26,6 @@ public class CoreModuleTest {
public void testOpenServiceList() {
CoreModule coreModule = new CoreModule();
Assert.assertEquals(26, coreModule.services().length);
Assert.assertEquals(27, coreModule.services().length);
}
}
......@@ -209,7 +209,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
if (downstreamService.equals(ServiceMetaInfo.UNKNOWN)) {
// Ingress -> sidecar(server side)
// Mesh telemetry without source, the relation would be generated.
ServiceMeshMetric metric = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder metric = ServiceMeshMetric.newBuilder()
.setStartTime(startTime)
.setEndTime(startTime + duration)
.setDestServiceName(localService.getServiceName())
......@@ -219,14 +219,13 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(protocol)
.setDetectPoint(DetectPoint.server)
.build();
.setDetectPoint(DetectPoint.server);
logger.debug("Transformed ingress->sidecar inbound mesh metric {}", metric);
forward(metric);
} else {
// sidecar -> sidecar(server side)
ServiceMeshMetric metric = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder metric = ServiceMeshMetric.newBuilder()
.setStartTime(startTime)
.setEndTime(startTime + duration)
.setSourceServiceName(downstreamService.getServiceName())
......@@ -238,8 +237,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(protocol)
.setDetectPoint(DetectPoint.server)
.build();
.setDetectPoint(DetectPoint.server);
logger.debug("Transformed sidecar->sidecar(server side) inbound mesh metric {}", metric);
forward(metric);
......@@ -251,7 +249,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.getAddress(), upstreamRemoteAddress.getSocketAddress()
.getPortValue());
ServiceMeshMetric metric = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder metric = ServiceMeshMetric.newBuilder()
.setStartTime(startTime)
.setEndTime(startTime + duration)
.setSourceServiceName(downstreamService.getServiceName())
......@@ -263,8 +261,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(protocol)
.setDetectPoint(DetectPoint.client)
.build();
.setDetectPoint(DetectPoint.client);
logger.debug("Transformed sidecar->sidecar(server side) inbound mesh metric {}", metric);
forward(metric);
......@@ -312,7 +309,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
}
boolean status = responseCode >= 200 && responseCode < 400;
ServiceMeshMetric metric = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder metric = ServiceMeshMetric.newBuilder()
.setStartTime(startTime)
.setEndTime(startTime + duration)
.setSourceServiceName(outside.getServiceName())
......@@ -324,8 +321,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(protocol)
.setDetectPoint(DetectPoint.server)
.build();
.setDetectPoint(DetectPoint.server);
logger.debug("Transformed ingress inbound mesh metric {}", metric);
forward(metric);
......@@ -337,7 +333,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
long outboundStartTime = startTime + formatAsLong(properties.getTimeToFirstUpstreamTxByte());
long outboundEndTime = startTime + formatAsLong(properties.getTimeToLastUpstreamRxByte());
ServiceMeshMetric outboundMetric = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder outboundMetric = ServiceMeshMetric.newBuilder()
.setStartTime(outboundStartTime)
.setEndTime(outboundEndTime)
.setSourceServiceName(ingress.getServiceName())
......@@ -349,8 +345,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(protocol)
.setDetectPoint(DetectPoint.client)
.build();
.setDetectPoint(DetectPoint.client);
logger.debug("Transformed ingress outbound mesh metric {}", outboundMetric);
forward(outboundMetric);
......@@ -391,7 +386,7 @@ public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
return ServiceMetaInfo.UNKNOWN;
}
protected void forward(ServiceMeshMetric metric) {
protected void forward(ServiceMeshMetric.Builder metric) {
TelemetryDataDispatcher.process(metric);
}
......
......@@ -76,12 +76,12 @@ public class K8sHTTPAnalysisTest {
Assert.assertEquals(2, analysis.metrics.size());
ServiceMeshMetric incoming = analysis.metrics.get(0);
ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
Assert.assertEquals("UNKNOWN", incoming.getSourceServiceName());
Assert.assertEquals("ingress", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
ServiceMeshMetric outgoing = analysis.metrics.get(1);
ServiceMeshMetric.Builder outgoing = analysis.metrics.get(1);
Assert.assertEquals("ingress", outgoing.getSourceServiceName());
Assert.assertEquals("productpage", outgoing.getDestServiceName());
Assert.assertEquals(DetectPoint.client, outgoing.getDetectPoint());
......@@ -99,7 +99,7 @@ public class K8sHTTPAnalysisTest {
Assert.assertEquals(1, analysis.metrics.size());
ServiceMeshMetric incoming = analysis.metrics.get(0);
ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
Assert.assertEquals("", incoming.getSourceServiceName());
Assert.assertEquals("productpage", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
......@@ -117,7 +117,7 @@ public class K8sHTTPAnalysisTest {
Assert.assertEquals(1, analysis.metrics.size());
ServiceMeshMetric incoming = analysis.metrics.get(0);
ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
Assert.assertEquals("productpage", incoming.getSourceServiceName());
Assert.assertEquals("review", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
......@@ -135,7 +135,7 @@ public class K8sHTTPAnalysisTest {
Assert.assertEquals(1, analysis.metrics.size());
ServiceMeshMetric incoming = analysis.metrics.get(0);
ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
Assert.assertEquals("productpage", incoming.getSourceServiceName());
Assert.assertEquals("detail", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.client, incoming.getDetectPoint());
......@@ -143,7 +143,7 @@ public class K8sHTTPAnalysisTest {
}
public static class MockK8sAnalysis extends K8sALSServiceMeshHTTPAnalysis {
private List<ServiceMeshMetric> metrics = new ArrayList<>();
private List<ServiceMeshMetric.Builder> metrics = new ArrayList<>();
@Override
public void init(EnvoyMetricReceiverConfig config) {
......@@ -156,7 +156,7 @@ public class K8sHTTPAnalysisTest {
}
@Override
protected void forward(ServiceMeshMetric metric) {
protected void forward(ServiceMeshMetric.Builder metric) {
metrics.add(metric);
}
}
......
......@@ -19,37 +19,42 @@
package org.apache.skywalking.oap.server.receiver.clr.provider.handler;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.common.v3.Commands;
import org.apache.skywalking.apm.network.language.agent.v3.CLRMetricCollection;
import org.apache.skywalking.apm.network.language.agent.v3.CLRMetricReportServiceGrpc;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
**/
@Slf4j
public class CLRMetricReportServiceHandler extends CLRMetricReportServiceGrpc.CLRMetricReportServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(CLRMetricReportServiceHandler.class);
private final CLRSourceDispatcher clrSourceDispatcher;
private final NamingLengthControl namingLengthControl;
public CLRMetricReportServiceHandler(ModuleManager moduleManager) {
clrSourceDispatcher = new CLRSourceDispatcher(moduleManager);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
public void collect(CLRMetricCollection request, StreamObserver<Commands> responseObserver) {
if (logger.isDebugEnabled()) {
logger.debug("receive the clr metrics from service instance, id: {}", request.getServiceInstance());
if (log.isDebugEnabled()) {
log.debug("receive the clr metrics from service instance, id: {}", request.getServiceInstance());
}
final CLRMetricCollection.Builder builder = request.toBuilder();
builder.setService(namingLengthControl.formatServiceName(builder.getService()));
builder.setServiceInstance(namingLengthControl.formatInstanceName(builder.getServiceInstance()));
request.getMetricsList().forEach(metrics -> {
long minuteTimeBucket = TimeBucket.getMinuteTimeBucket(metrics.getTime());
clrSourceDispatcher.sendMetric(request.getService(), request.getServiceInstance(), minuteTimeBucket, metrics);
clrSourceDispatcher.sendMetric(
request.getService(), request.getServiceInstance(), minuteTimeBucket, metrics);
});
responseObserver.onNext(Commands.newBuilder().build());
......
......@@ -117,7 +117,7 @@ public class IstioTelemetryGRPCHandler extends HandleMetricServiceGrpc.HandleMet
destServiceName = string(i, "destinationService");
}
ServiceMeshMetric metrics = ServiceMeshMetric.newBuilder()
ServiceMeshMetric.Builder metrics = ServiceMeshMetric.newBuilder()
.setStartTime(requestTime.toEpochMilli())
.setEndTime(responseTime.toEpochMilli())
.setSourceServiceName(sourceServiceName)
......@@ -129,8 +129,7 @@ public class IstioTelemetryGRPCHandler extends HandleMetricServiceGrpc.HandleMet
.setResponseCode(Math.toIntExact(responseCode))
.setStatus(status)
.setProtocol(netProtocol)
.setDetectPoint(detectPoint)
.build();
.setDetectPoint(detectPoint);
logger.debug("Transformed metrics {}", metrics);
TelemetryDataDispatcher.process(metrics);
......
......@@ -23,15 +23,21 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.common.v3.Commands;
import org.apache.skywalking.apm.network.language.agent.v3.JVMMetricCollection;
import org.apache.skywalking.apm.network.language.agent.v3.JVMMetricReportServiceGrpc;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
@Slf4j
public class JVMMetricReportServiceHandler extends JVMMetricReportServiceGrpc.JVMMetricReportServiceImplBase implements GRPCHandler {
private final JVMSourceDispatcher jvmSourceDispatcher;
private final NamingLengthControl namingLengthControl;
public JVMMetricReportServiceHandler(ModuleManager moduleManager) {
this.jvmSourceDispatcher = new JVMSourceDispatcher(moduleManager);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
......@@ -43,9 +49,12 @@ public class JVMMetricReportServiceHandler extends JVMMetricReportServiceGrpc.JV
request.getServiceInstance()
);
}
final JVMMetricCollection.Builder builder = request.toBuilder();
builder.setService(namingLengthControl.formatServiceName(builder.getService()));
builder.setServiceInstance(namingLengthControl.formatInstanceName(builder.getServiceInstance()));
request.getMetricsList().forEach(jvmMetric -> {
jvmSourceDispatcher.sendMetric(request.getService(), request.getServiceInstance(), jvmMetric);
builder.getMetricsList().forEach(jvmMetric -> {
jvmSourceDispatcher.sendMetric(builder.getService(), builder.getServiceInstance(), jvmMetric);
});
responseObserver.onNext(Commands.newBuilder().build());
......
......@@ -33,6 +33,7 @@ import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceUpdate;
import org.apache.skywalking.oap.server.core.source.ServiceUpdate;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
......@@ -41,17 +42,23 @@ import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
public class ManagementServiceHandler extends ManagementServiceGrpc.ManagementServiceImplBase implements GRPCHandler {
private final SourceReceiver sourceReceiver;
private final NamingLengthControl namingLengthControl;
public ManagementServiceHandler(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
public void reportInstanceProperties(final InstanceProperties request,
final StreamObserver<Commands> responseObserver) {
ServiceInstanceUpdate serviceInstanceUpdate = new ServiceInstanceUpdate();
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(request.getService(), NodeType.Normal));
serviceInstanceUpdate.setName(request.getServiceInstance());
final String serviceName = namingLengthControl.formatServiceName(request.getService());
final String instanceName = namingLengthControl.formatInstanceName(request.getServiceInstance());
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(serviceName, NodeType.Normal));
serviceInstanceUpdate.setName(instanceName);
JsonObject properties = new JsonObject();
List<String> ipv4List = new ArrayList<>();
......@@ -75,14 +82,17 @@ public class ManagementServiceHandler extends ManagementServiceGrpc.ManagementSe
@Override
public void keepAlive(final InstancePingPkg request, final StreamObserver<Commands> responseObserver) {
final long timeBucket = TimeBucket.getTimeBucket(System.currentTimeMillis(), DownSampling.Minute);
final String serviceName = namingLengthControl.formatServiceName(request.getService());
final String instanceName = namingLengthControl.formatInstanceName(request.getServiceInstance());
ServiceInstanceUpdate serviceInstanceUpdate = new ServiceInstanceUpdate();
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(request.getService(), NodeType.Normal));
serviceInstanceUpdate.setName(request.getServiceInstance());
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(serviceName, NodeType.Normal));
serviceInstanceUpdate.setName(instanceName);
serviceInstanceUpdate.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceUpdate);
ServiceUpdate serviceUpdate = new ServiceUpdate();
serviceUpdate.setName(request.getService());
serviceUpdate.setName(serviceName);
serviceUpdate.setNodeType(NodeType.Normal);
serviceUpdate.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceUpdate);
......
......@@ -29,6 +29,7 @@ import org.apache.skywalking.oap.server.core.analysis.DownSampling;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceUpdate;
import org.apache.skywalking.oap.server.core.source.ServiceUpdate;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
......@@ -39,10 +40,14 @@ import org.apache.skywalking.oap.server.library.util.ProtoBufJsonUtils;
public class ManagementServiceKeepAliveHandler extends JettyJsonHandler {
private final SourceReceiver sourceReceiver;
private final NamingLengthControl namingLengthControl;
private final Gson gson = new Gson();
public ManagementServiceKeepAliveHandler(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
......@@ -55,16 +60,18 @@ public class ManagementServiceKeepAliveHandler extends JettyJsonHandler {
final InstanceProperties.Builder request = InstanceProperties.newBuilder();
ProtoBufJsonUtils.fromJSON(getJsonBody(req), request);
final String serviceName = namingLengthControl.formatServiceName(request.getService());
final String instanceName = namingLengthControl.formatInstanceName(request.getServiceInstance());
final long timeBucket = TimeBucket.getTimeBucket(System.currentTimeMillis(), DownSampling.Minute);
ServiceInstanceUpdate serviceInstanceUpdate = new ServiceInstanceUpdate();
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(request.getService(), NodeType.Normal));
serviceInstanceUpdate.setName(request.getServiceInstance());
serviceInstanceUpdate.setTimeBucket(
timeBucket);
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(serviceName, NodeType.Normal));
serviceInstanceUpdate.setName(instanceName);
serviceInstanceUpdate.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceUpdate);
ServiceUpdate serviceUpdate = new ServiceUpdate();
serviceUpdate.setName(request.getService());
serviceUpdate.setName(serviceName);
serviceUpdate.setNodeType(NodeType.Normal);
serviceUpdate.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceUpdate);
......
......@@ -31,9 +31,10 @@ import org.apache.skywalking.apm.network.management.v3.InstanceProperties;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.DownSampling;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceUpdate;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
......@@ -43,10 +44,14 @@ import org.apache.skywalking.oap.server.library.util.ProtoBufJsonUtils;
public class ManagementServiceReportPropertiesHandler extends JettyJsonHandler {
private final SourceReceiver sourceReceiver;
private final NamingLengthControl namingLengthControl;
private final Gson gson = new Gson();
public ManagementServiceReportPropertiesHandler(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
......@@ -59,9 +64,12 @@ public class ManagementServiceReportPropertiesHandler extends JettyJsonHandler {
final InstanceProperties.Builder request = InstanceProperties.newBuilder();
ProtoBufJsonUtils.fromJSON(getJsonBody(req), request);
final String serviceName = namingLengthControl.formatServiceName(request.getService());
final String instanceName = namingLengthControl.formatInstanceName(request.getServiceInstance());
ServiceInstanceUpdate serviceInstanceUpdate = new ServiceInstanceUpdate();
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(request.getService(), NodeType.Normal));
serviceInstanceUpdate.setName(request.getServiceInstance());
serviceInstanceUpdate.setServiceId(IDManager.ServiceID.buildId(serviceName, NodeType.Normal));
serviceInstanceUpdate.setName(instanceName);
JsonObject properties = new JsonObject();
List<String> ipv4List = new ArrayList<>();
......
/*
* 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.skywalking.aop.server.receiver.mesh;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.util.StringFormatGroup;
import org.apache.skywalking.oap.server.library.util.ResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EndpointNameFormater {
private static final Logger logger = LoggerFactory.getLogger(EndpointNameFormater.class);
private static Map<String, StringFormatGroup> ALL_RULES = new ConcurrentHashMap<>();
private static void init(String service) {
if (ALL_RULES.containsKey(service)) {
return;
}
StringFormatGroup endpointRule = new StringFormatGroup();
Properties properties = new Properties();
try {
InputStream stream = ResourceUtils.class.getClassLoader()
.getResourceAsStream(service + "_endpoint_naming_rules.properties");
if (stream == null) {
logger.info("{}_endpoint_naming_rules.properties not found. Try to find global endpoint rule file.", service);
stream = ResourceUtils.class.getClassLoader().getResourceAsStream("endpoint_naming_rules.properties");
}
if (stream == null) {
logger.info("endpoint_naming_rules.properties not found. No endpoint naming setup.");
} else {
properties.load(stream);
properties.forEach((key, value) -> {
endpointRule.addRule((String) key, (String) value);
logger.debug("endpoint naming rule of service {} found, name[{}] and rule[{}]", service, key, value);
});
}
} catch (IOException e) {
logger.info("{}_endpoint_rules.properties not found. No endpoint naming setup.", service);
}
ALL_RULES.put(service, endpointRule);
logger.debug("endpoint naming rules of service {} added. {}", service, endpointRule);
}
public static StringFormatGroup.FormatResult format(String service, String endpointName) {
init(service);
return ALL_RULES.get(service).format(endpointName);
}
}
......@@ -42,7 +42,7 @@ public class MeshGRPCHandler extends ServiceMeshMetricServiceGrpc.ServiceMeshMet
logger.debug("Received mesh metrics: {}", metrics);
}
TelemetryDataDispatcher.process(metrics);
TelemetryDataDispatcher.process(metrics.toBuilder());
}
@Override
......
......@@ -21,12 +21,12 @@ package org.apache.skywalking.aop.server.receiver.mesh;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.servicemesh.v3.Protocol;
import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
import org.apache.skywalking.apm.util.StringFormatGroup;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.All;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.Endpoint;
......@@ -50,7 +50,7 @@ import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
@Slf4j
public class TelemetryDataDispatcher {
private static SourceReceiver SOURCE_RECEIVER;
private static NamingLengthControl NAME_LENGTH_CONTROL;
private static HistogramMetrics MESH_ANALYSIS_METRICS;
private TelemetryDataDispatcher() {
......@@ -61,25 +61,32 @@ public class TelemetryDataDispatcher {
MetricsCreator metricsCreator = moduleManager.find(TelemetryModule.NAME)
.provider()
.getService(MetricsCreator.class);
NAME_LENGTH_CONTROL = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
MESH_ANALYSIS_METRICS = metricsCreator.createHistogramMetric(
"mesh_analysis_latency", "The process latency of service mesh telemetry", MetricsTag.EMPTY_KEY,
MetricsTag.EMPTY_VALUE
);
}
public static void process(ServiceMeshMetric data) {
public static void process(ServiceMeshMetric.Builder data) {
HistogramMetrics.Timer timer = MESH_ANALYSIS_METRICS.createTimer();
try {
String service = data.getDestServiceName();
String endpointName = data.getEndpoint();
StringFormatGroup.FormatResult formatResult = EndpointNameFormater.format(service, endpointName);
if (formatResult.isMatch()) {
data = data.toBuilder().setEndpoint(formatResult.getName()).build();
if (data.getSourceServiceName() != null) {
data.setSourceServiceName(NAME_LENGTH_CONTROL.formatServiceName(data.getSourceServiceName()));
}
if (data.getSourceServiceInstance() != null) {
data.setSourceServiceInstance(NAME_LENGTH_CONTROL.formatInstanceName(data.getSourceServiceInstance()));
}
if (data.getDestServiceName() != null) {
data.setDestServiceName(NAME_LENGTH_CONTROL.formatServiceName(data.getDestServiceName()));
}
if (data.getDestServiceInstance() != null) {
data.setDestServiceInstance(NAME_LENGTH_CONTROL.formatInstanceName(data.getDestServiceInstance()));
}
if (log.isDebugEnabled()) {
if (formatResult.isMatch()) {
log.debug("Endpoint {} is renamed to {}", endpointName, data.getEndpoint());
}
if (data.getEndpoint() != null) {
data.setEndpoint(NAME_LENGTH_CONTROL.formatEndpointName(data.getEndpoint()));
}
doDispatch(data);
......@@ -88,7 +95,7 @@ public class TelemetryDataDispatcher {
}
}
static void doDispatch(ServiceMeshMetric metrics) {
static void doDispatch(ServiceMeshMetric.Builder metrics) {
long minuteTimeBucket = TimeBucket.getMinuteTimeBucket(metrics.getStartTime());
heartbeat(metrics, minuteTimeBucket);
......@@ -107,7 +114,7 @@ public class TelemetryDataDispatcher {
}
}
private static void heartbeat(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void heartbeat(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
// source
final String sourceServiceName = metrics.getSourceServiceName();
final String sourceServiceInstance = metrics.getSourceServiceInstance();
......@@ -134,7 +141,7 @@ public class TelemetryDataDispatcher {
}
}
private static void toAll(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toAll(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
All all = new All();
all.setTimeBucket(minuteTimeBucket);
all.setName(metrics.getDestServiceName());
......@@ -148,7 +155,7 @@ public class TelemetryDataDispatcher {
SOURCE_RECEIVER.receive(all);
}
private static void toService(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toService(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
Service service = new Service();
service.setTimeBucket(minuteTimeBucket);
service.setName(metrics.getDestServiceName());
......@@ -163,7 +170,7 @@ public class TelemetryDataDispatcher {
SOURCE_RECEIVER.receive(service);
}
private static void toServiceRelation(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toServiceRelation(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
ServiceRelation serviceRelation = new ServiceRelation();
serviceRelation.setTimeBucket(minuteTimeBucket);
serviceRelation.setSourceServiceName(metrics.getSourceServiceName());
......@@ -183,7 +190,7 @@ public class TelemetryDataDispatcher {
SOURCE_RECEIVER.receive(serviceRelation);
}
private static void toServiceInstance(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toServiceInstance(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setTimeBucket(minuteTimeBucket);
serviceInstance.setName(metrics.getDestServiceInstance());
......@@ -198,7 +205,7 @@ public class TelemetryDataDispatcher {
SOURCE_RECEIVER.receive(serviceInstance);
}
private static void toServiceInstanceRelation(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toServiceInstanceRelation(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
ServiceInstanceRelation serviceRelation = new ServiceInstanceRelation();
serviceRelation.setTimeBucket(minuteTimeBucket);
serviceRelation.setSourceServiceInstanceName(metrics.getSourceServiceInstance());
......@@ -218,7 +225,7 @@ public class TelemetryDataDispatcher {
SOURCE_RECEIVER.receive(serviceRelation);
}
private static void toEndpoint(ServiceMeshMetric metrics, long minuteTimeBucket) {
private static void toEndpoint(ServiceMeshMetric.Builder metrics, long minuteTimeBucket) {
Endpoint endpoint = new Endpoint();
endpoint.setTimeBucket(minuteTimeBucket);
endpoint.setName(metrics.getEndpoint());
......
......@@ -43,9 +43,9 @@ public class MeshDataMock {
meshObserver.onNext(ServiceMeshMetric.newBuilder()
.setSourceServiceName("e2e-test-source-service")
.setSourceServiceInstance("e2e-test-source-service-instance")
.setDestServiceName("e2e-test-dest-service")
.setDestServiceInstance("e2e-test-dest-service-instance")
.setEndpoint("e2e/test")
.setDestServiceName("Extra model column are the column defined by in the codes, These columns of model are not required logically in aggregation or further query,")
.setDestServiceInstance("Extra model column are the column defined by in the codes, These columns of model are not required logically in aggregation or further query,")
.setEndpoint("Extra model column are the column defined by in the codes, These columns of model are not required logically in aggregation or further query,")
.setStartTime(System.currentTimeMillis() - 1000L)
.setEndTime(System.currentTimeMillis() - 500L + i)
.setLatency(2000)
......
......@@ -45,6 +45,7 @@ public class TraceModuleProvider extends ModuleProvider {
private final TraceServiceModuleConfig moduleConfig;
private DBLatencyThresholdsAndWatcher thresholds;
private UninstrumentedGatewaysConfig uninstrumentedGatewaysConfig;
private SegmentParserServiceImpl segmentParserService;
public TraceModuleProvider() {
this.moduleConfig = new TraceServiceModuleConfig();
......@@ -74,8 +75,8 @@ public class TraceModuleProvider extends ModuleProvider {
moduleConfig.setDbLatencyThresholdsAndWatcher(thresholds);
moduleConfig.setUninstrumentedGatewaysConfig(uninstrumentedGatewaysConfig);
this.registerServiceImplementation(
ISegmentParserService.class, new SegmentParserServiceImpl(getManager(), listenerManager(), moduleConfig));
segmentParserService = new SegmentParserServiceImpl(getManager(), moduleConfig);
this.registerServiceImplementation(ISegmentParserService.class, segmentParserService);
}
@Override
......@@ -93,6 +94,7 @@ public class TraceModuleProvider extends ModuleProvider {
dynamicConfigurationService.registerConfigChangeWatcher(thresholds);
dynamicConfigurationService.registerConfigChangeWatcher(uninstrumentedGatewaysConfig);
segmentParserService.setListenerManager(listenerManager());
grpcHandlerRegister.addHandler(
new TraceSegmentReportServiceHandler(getManager(), listenerManager(), moduleConfig));
......@@ -118,10 +120,10 @@ public class TraceModuleProvider extends ModuleProvider {
private SegmentParserListenerManager listenerManager() {
SegmentParserListenerManager listenerManager = new SegmentParserListenerManager();
if (moduleConfig.isTraceAnalysis()) {
listenerManager.add(new MultiScopesAnalysisListener.Factory());
listenerManager.add(new NetworkAddressAliasMappingListener.Factory());
listenerManager.add(new MultiScopesAnalysisListener.Factory(getManager()));
listenerManager.add(new NetworkAddressAliasMappingListener.Factory(getManager()));
}
listenerManager.add(new SegmentAnalysisListener.Factory(moduleConfig.getSampleRate()));
listenerManager.add(new SegmentAnalysisListener.Factory(getManager(), moduleConfig));
return listenerManager;
}
......
......@@ -18,6 +18,8 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModuleConfig;
......@@ -25,18 +27,12 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModu
/**
* The open service to the receivers.
*/
@RequiredArgsConstructor
public class SegmentParserServiceImpl implements ISegmentParserService {
private ModuleManager moduleManager;
private final ModuleManager moduleManager;
private final TraceServiceModuleConfig config;
@Setter
private SegmentParserListenerManager listenerManager;
private TraceServiceModuleConfig config;
public SegmentParserServiceImpl(ModuleManager moduleManager,
SegmentParserListenerManager listenerManager,
TraceServiceModuleConfig config) {
this.moduleManager = moduleManager;
this.listenerManager = listenerManager;
this.config = config;
}
@Override
public void send(SegmentObject segment) {
......
......@@ -19,6 +19,8 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser;
public class SpanTags {
public static final String STATUS_CODE = "status_code";
public static final String DB_STATEMENT = "db.statement";
public static final String DB_TYPE = "db.type";
......
......@@ -19,8 +19,8 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
......@@ -35,6 +35,7 @@ import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.manual.networkalias.NetworkAddressAlias;
import org.apache.skywalking.oap.server.core.cache.NetworkAddressAliasCache;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.DatabaseSlowStatement;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.EndpointRelation;
......@@ -52,24 +53,15 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.parser.SpanTags;
* This listener traverses the whole segment.
*/
@Slf4j
@RequiredArgsConstructor
public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitAnalysisListener {
private final List<SourceBuilder> entrySourceBuilders = new ArrayList<>(10);
private final List<SourceBuilder> exitSourceBuilders = new ArrayList<>(10);
private final List<DatabaseSlowStatement> slowDatabaseAccesses = new ArrayList<>(10);
private final SourceReceiver sourceReceiver;
private final List<SourceBuilder> entrySourceBuilders;
private final List<SourceBuilder> exitSourceBuilders;
private final List<DatabaseSlowStatement> slowDatabaseAccesses;
private final TraceServiceModuleConfig config;
private final NetworkAddressAliasCache networkAddressAliasCache;
private MultiScopesAnalysisListener(ModuleManager moduleManager, TraceServiceModuleConfig config) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.entrySourceBuilders = new LinkedList<>();
this.exitSourceBuilders = new LinkedList<>();
this.slowDatabaseAccesses = new ArrayList<>(10);
this.networkAddressAliasCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NetworkAddressAliasCache.class);
this.config = config;
}
private final NamingLengthControl namingLengthControl;
@Override
public boolean containsPoint(Point point) {
......@@ -95,7 +87,7 @@ public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitA
if (span.getRefsCount() > 0) {
for (int i = 0; i < span.getRefsCount(); i++) {
SegmentReference reference = span.getRefs(i);
SourceBuilder sourceBuilder = new SourceBuilder();
SourceBuilder sourceBuilder = new SourceBuilder(namingLengthControl);
if (StringUtil.isEmpty(reference.getParentEndpoint())) {
sourceBuilder.setSourceEndpointName(Const.USER_ENDPOINT_NAME);
......@@ -125,7 +117,7 @@ public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitA
entrySourceBuilders.add(sourceBuilder);
}
} else {
SourceBuilder sourceBuilder = new SourceBuilder();
SourceBuilder sourceBuilder = new SourceBuilder(namingLengthControl);
sourceBuilder.setSourceServiceName(Const.USER_SERVICE_NAME);
sourceBuilder.setSourceServiceInstanceName(Const.USER_INSTANCE_NAME);
sourceBuilder.setSourceEndpointName(Const.USER_ENDPOINT_NAME);
......@@ -152,7 +144,7 @@ public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitA
return;
}
SourceBuilder sourceBuilder = new SourceBuilder();
SourceBuilder sourceBuilder = new SourceBuilder(namingLengthControl);
final String networkAddress = span.getPeer();
if (StringUtil.isEmpty(networkAddress)) {
......@@ -235,6 +227,16 @@ public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitA
sourceBuilder.setTimeBucket(TimeBucket.getMinuteTimeBucket(span.getStartTime()));
sourceBuilder.setLatency((int) latency);
sourceBuilder.setResponseCode(Const.NONE);
span.getTagsList().forEach(tag -> {
if (SpanTags.STATUS_CODE.equals(tag.getKey())) {
try {
sourceBuilder.setResponseCode(Integer.parseInt(tag.getValue()));
} catch (NumberFormatException e) {
log.warn("span {} has illegal status code {}", span, tag.getValue());
}
}
});
sourceBuilder.setStatus(!span.getIsError());
switch (span.getSpanLayer()) {
......@@ -293,9 +295,24 @@ public class MultiScopesAnalysisListener implements EntryAnalysisListener, ExitA
}
public static class Factory implements AnalysisListenerFactory {
private final SourceReceiver sourceReceiver;
private final NetworkAddressAliasCache networkAddressAliasCache;
private final NamingLengthControl namingLengthControl;
public Factory(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.networkAddressAliasCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NetworkAddressAliasCache.class);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
public AnalysisListener create(ModuleManager moduleManager, TraceServiceModuleConfig config) {
return new MultiScopesAnalysisListener(moduleManager, config);
return new MultiScopesAnalysisListener(
sourceReceiver, config, networkAddressAliasCache, namingLengthControl);
}
}
}
......@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.language.agent.v3.RefType;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
......@@ -26,6 +27,7 @@ import org.apache.skywalking.apm.network.language.agent.v3.SpanObject;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.NetworkAddressAliasSetup;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
......@@ -40,14 +42,11 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModu
* This is a key point of SkyWalking header propagation protocol.
*/
@Slf4j
@RequiredArgsConstructor
public class NetworkAddressAliasMappingListener implements EntryAnalysisListener {
private final TraceServiceModuleConfig config;
private final SourceReceiver sourceReceiver;
public NetworkAddressAliasMappingListener(ModuleManager moduleManager, TraceServiceModuleConfig config) {
this.config = config;
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
}
private final TraceServiceModuleConfig config;
private final NamingLengthControl namingLengthControl;
@Override
public void parseEntry(SpanObject span, SegmentObject segmentObject) {
......@@ -60,7 +59,8 @@ public class NetworkAddressAliasMappingListener implements EntryAnalysisListener
if (!span.getSpanLayer().equals(SpanLayer.MQ)) {
span.getRefsList().forEach(segmentReference -> {
if (RefType.CrossProcess.equals(segmentReference.getRefType())) {
final String networkAddressUsedAtPeer = segmentReference.getNetworkAddressUsedAtPeer();
final String networkAddressUsedAtPeer = namingLengthControl.formatServiceName(
segmentReference.getNetworkAddressUsedAtPeer());
if (config.getUninstrumentedGatewaysConfig().isAddressConfiguredAsGateway(
networkAddressUsedAtPeer)) {
/*
......@@ -68,11 +68,15 @@ public class NetworkAddressAliasMappingListener implements EntryAnalysisListener
*/
return;
}
final String serviceName = namingLengthControl.formatServiceName(segmentObject.getService());
final String instanceName = namingLengthControl.formatInstanceName(
segmentObject.getServiceInstance());
final NetworkAddressAliasSetup networkAddressAliasSetup = new NetworkAddressAliasSetup();
networkAddressAliasSetup.setAddress(networkAddressUsedAtPeer);
networkAddressAliasSetup.setRepresentService(segmentObject.getService());
networkAddressAliasSetup.setRepresentService(serviceName);
networkAddressAliasSetup.setRepresentServiceNodeType(NodeType.Normal);
networkAddressAliasSetup.setRepresentServiceInstance(segmentObject.getServiceInstance());
networkAddressAliasSetup.setRepresentServiceInstance(instanceName);
networkAddressAliasSetup.setTimeBucket(TimeBucket.getMinuteTimeBucket(span.getStartTime()));
sourceReceiver.receive(networkAddressAliasSetup);
......@@ -92,10 +96,19 @@ public class NetworkAddressAliasMappingListener implements EntryAnalysisListener
}
public static class Factory implements AnalysisListenerFactory {
private final SourceReceiver sourceReceiver;
private final NamingLengthControl namingLengthControl;
public Factory(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
public AnalysisListener create(ModuleManager moduleManager, TraceServiceModuleConfig config) {
return new NetworkAddressAliasMappingListener(moduleManager, config);
return new NetworkAddressAliasMappingListener(sourceReceiver, config, namingLengthControl);
}
}
}
......@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
import org.apache.skywalking.apm.network.language.agent.v3.SpanObject;
......@@ -27,6 +28,7 @@ import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.Segment;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
......@@ -37,9 +39,12 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModu
* SegmentSpanListener forwards the segment raw data to the persistence layer with the query required conditions.
*/
@Slf4j
@RequiredArgsConstructor
public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnalysisListener, SegmentListener {
private final SourceReceiver sourceReceiver;
private final TraceSegmentSampler sampler;
private final NamingLengthControl namingLengthControl;
private final Segment segment = new Segment();
private SAMPLE_STATUS sampleStatus = SAMPLE_STATUS.UNKNOWN;
private String serviceId = Const.EMPTY_STRING;
......@@ -50,11 +55,6 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
private int duration;
private boolean isError;
private SegmentAnalysisListener(ModuleManager moduleManager, TraceSegmentSampler sampler) {
this.sampler = sampler;
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
}
@Override
public boolean containsPoint(Point point) {
return Point.First.equals(point) || Point.Entry.equals(point) || Point.Segment.equals(point);
......@@ -68,7 +68,9 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
if (StringUtil.isEmpty(serviceId)) {
serviceId = IDManager.ServiceID.buildId(
segmentObject.getService(), NodeType.Normal);
namingLengthControl.formatServiceName(segmentObject.getService()),
NodeType.Normal
);
}
long timeBucket = TimeBucket.getRecordTimeBucket(startTimestamp);
......@@ -77,7 +79,7 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
segment.setServiceId(serviceId);
segment.setServiceInstanceId(IDManager.ServiceInstanceID.buildId(
serviceId,
segmentObject.getServiceInstance()
namingLengthControl.formatInstanceName(segmentObject.getServiceInstance())
));
segment.setLatency(duration);
segment.setStartTime(startTimestamp);
......@@ -87,11 +89,12 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
segment.setDataBinary(segmentObject.toByteArray());
segment.setVersion(3);
endpointName = namingLengthControl.formatEndpointName(span.getOperationName());
endpointId = IDManager.EndpointID.buildId(
serviceId,
span.getOperationName()
endpointName
);
endpointName = span.getOperationName();
}
@Override
......@@ -106,7 +109,11 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
span.getOperationName()
);
endpointName = span.getOperationName();
endpointName = namingLengthControl.formatEndpointName(span.getOperationName());
endpointId = IDManager.EndpointID.buildId(
serviceId,
endpointName
);
}
@Override
......@@ -160,15 +167,21 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
}
public static class Factory implements AnalysisListenerFactory {
private final SourceReceiver sourceReceiver;
private final TraceSegmentSampler sampler;
public Factory(int segmentSamplingRate) {
this.sampler = new TraceSegmentSampler(segmentSamplingRate);
private final NamingLengthControl namingLengthControl;
public Factory(ModuleManager moduleManager, TraceServiceModuleConfig config) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.sampler = new TraceSegmentSampler(config.getSampleRate());
this.namingLengthControl = moduleManager.find(CoreModule.NAME)
.provider()
.getService(NamingLengthControl.class);
}
@Override
public AnalysisListener create(ModuleManager moduleManager, TraceServiceModuleConfig config) {
return new SegmentAnalysisListener(moduleManager, sampler);
return new SegmentAnalysisListener(sourceReceiver, sampler, namingLengthControl);
}
}
}
......@@ -19,45 +19,74 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.source.All;
import org.apache.skywalking.oap.server.core.source.DatabaseAccess;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.Endpoint;
import org.apache.skywalking.oap.server.core.source.EndpointRelation;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.source.RequestType;
import org.apache.skywalking.oap.server.core.source.Service;
import org.apache.skywalking.oap.server.core.source.ServiceInstance;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceRelation;
import org.apache.skywalking.oap.server.core.source.ServiceRelation;
@RequiredArgsConstructor
class SourceBuilder {
private final NamingLengthControl namingLengthControl;
@Getter
@Setter
private String sourceServiceName;
public void setSourceServiceName(final String sourceServiceName) {
this.sourceServiceName = namingLengthControl.formatServiceName(sourceServiceName);
}
@Getter
@Setter
private NodeType sourceNodeType;
@Getter
@Setter
private String sourceServiceInstanceName;
public void setSourceServiceInstanceName(final String sourceServiceInstanceName) {
this.sourceServiceInstanceName = namingLengthControl.formatInstanceName(sourceServiceInstanceName);
}
@Getter
@Setter
private String sourceEndpointName;
public void setSourceEndpointName(final String sourceEndpointName) {
this.sourceEndpointName = namingLengthControl.formatEndpointName(sourceEndpointName);
}
@Getter
@Setter
private String destServiceName;
public void setDestServiceName(final String destServiceName) {
this.destServiceName = namingLengthControl.formatServiceName(destServiceName);
}
@Getter
@Setter
private NodeType destNodeType;
@Getter
@Setter
private String destServiceInstanceName;
public void setDestServiceInstanceName(final String destServiceInstanceName) {
this.destServiceInstanceName = namingLengthControl.formatServiceName(destServiceInstanceName);
}
@Getter
@Setter
private String destEndpointName;
public void setDestEndpointName(final String destEndpointName) {
this.destEndpointName = namingLengthControl.formatEndpointName(destEndpointName);
}
@Getter
@Setter
private int componentId;
......
......@@ -30,6 +30,7 @@ import org.apache.skywalking.oap.server.core.command.CommandService;
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.config.DownSamplingConfigService;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.config.NamingLengthControl;
import org.apache.skywalking.oap.server.core.profile.ProfileTaskMutationService;
import org.apache.skywalking.oap.server.core.query.AggregationQueryService;
import org.apache.skywalking.oap.server.core.query.AlarmQueryService;
......@@ -92,6 +93,8 @@ public class MockCoreModuleProvider extends CoreModuleProvider {
@Override
public void prepare() throws ServiceNotProvidedException, ModuleStartException {
this.registerServiceImplementation(NamingLengthControl.class, new NamingLengthControl(50, 50, 150));
MockStreamAnnotationListener streamAnnotationListener = new MockStreamAnnotationListener(getManager());
annotationScan.registerListener(streamAnnotationListener);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册