Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of datasource-settings.properties, use application.yml for MySQLStorageProvider #3564

Merged
merged 29 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f56379d
Is it a typo or not?
tristaZero Sep 27, 2019
d77b831
Merge branch 'master' into master
wu-sheng Sep 27, 2019
12bd1b3
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Sep 30, 2019
c87b845
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 5, 2019
7bd1183
Merge branch 'master' of https://github.com/tristaZero/incubator-skyw…
tristaZero Oct 5, 2019
9fa1fd5
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 6, 2019
27fc67d
delete datasource-settings.properties
tristaZero Oct 6, 2019
b6b3462
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 6, 2019
40efde6
handle 'metadataQueryMaxSize'
tristaZero Oct 6, 2019
65f006e
Merge branch 'master' into master
wu-sheng Oct 9, 2019
8e21eb4
delete DynamicModuleConfig.java
tristaZero Oct 10, 2019
13d4546
modify mysql config
tristaZero Oct 10, 2019
3fa15ad
parsing yaml to support the configuration for multiple properties
tristaZero Oct 10, 2019
44b67c5
Merge remote-tracking branch 'origin/master'
tristaZero Oct 10, 2019
fa3fc1f
Merge branch 'master' into master
tristaZero Oct 10, 2019
6ceda9b
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 10, 2019
6306469
Merge branch 'master' of https://github.com/tristaZero/incubator-skyw…
tristaZero Oct 10, 2019
046300e
Merge branch 'master' into master
wu-sheng Oct 10, 2019
226ece8
delete datasource-settings.properties
tristaZero Oct 11, 2019
d3be5e1
modify doc
tristaZero Oct 11, 2019
b87fe2f
Merge remote-tracking branch 'origin/master'
tristaZero Oct 11, 2019
787a202
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 11, 2019
409f180
Merge branch 'master' into master
wu-sheng Oct 12, 2019
bdb52ba
add properties for docker-entrypoint.sh
tristaZero Oct 12, 2019
ec3c3be
Merge remote-tracking branch 'origin/master'
tristaZero Oct 12, 2019
afd5617
Merge branch 'master' into master
wu-sheng Oct 12, 2019
ddf2956
add testLoadConfig()
tristaZero Oct 12, 2019
d6b4e28
Merge remote-tracking branch 'origin/master'
tristaZero Oct 12, 2019
4e1123a
Merge branch 'master' of https://github.com/apache/skywalking
tristaZero Oct 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docker/oap/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,15 @@ generateStorageMySQL() {
cat <<EOT >> ${var_application_file}
storage:
mysql:
metadataQueryMaxSize: \${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
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}
tristaZero marked this conversation as resolved.
Show resolved Hide resolved
EOT
}

Expand Down
29 changes: 22 additions & 7 deletions docs/en/setup/backend/backend-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,18 @@ Please download MySQL driver by yourself. Copy the connection driver jar to `oap
```yaml
storage:
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}
```

All connection related settings including link url, username and password
are in `datasource-settings.properties`.
This setting file follow [HikariCP](https://github.com/brettwooldridge/HikariCP) connection pool document.
All connection related settings including link url, username and password are in `application.yml`.
Here are some of the settings, please follow [HikariCP](https://github.com/brettwooldridge/HikariCP) connection pool document for all the settings.
wu-sheng marked this conversation as resolved.
Show resolved Hide resolved

## TiDB
Currently tested TiDB in version 2.0.9, and Mysql Client driver in version 8.0.13.
Expand All @@ -172,10 +179,18 @@ Active TiDB as storage, set storage provider to **mysql**.
```yaml
storage:
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}
tristaZero marked this conversation as resolved.
Show resolved Hide resolved
metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000}
```

All connection related settings including link url, username and password
are in `datasource-settings.properties`. And these settings can refer to the configuration of *MySQL* above.
All connection related settings including link url, username and password are in `application.yml`.
These settings can refer to the configuration of *MySQL* above.

## ElasticSearch 5
ElasticSearch 5 is incompatible with ElasticSearch 6 Java client jar, so it could not be included in native distribution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package org.apache.skywalking.oap.server.library.module;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.Enumeration;
import java.util.Properties;
import java.util.ServiceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A module definition.
Expand Down Expand Up @@ -93,7 +94,7 @@ void prepare(ModuleManager moduleManager, ApplicationConfiguration.ModuleConfigu
}
loadedProvider.prepare();
}

private void copyProperties(ModuleConfig dest, Properties src, String moduleName,
String providerName) throws IllegalAccessException {
if (dest == null) {
Expand All @@ -103,7 +104,6 @@ private void copyProperties(ModuleConfig dest, Properties src, String moduleName
while (propertyNames.hasMoreElements()) {
String propertyName = (String)propertyNames.nextElement();
Class<? extends ModuleConfig> destClass = dest.getClass();

try {
Field field = getDeclaredField(destClass, propertyName);
field.setAccessible(true);
Expand Down
1 change: 0 additions & 1 deletion oap-server/server-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@
<exclude>log4j2.xml</exclude>
<exclude>alarm-settings.yml</exclude>
<exclude>component-libraries.yml</exclude>
<exclude>datasource-settings.properties</exclude>
<exclude>endpoint_naming_rules.properties</exclude>
<exclude>official_analysis.oal</exclude>
<exclude>gateways.yml</exclude>
Expand Down
10 changes: 9 additions & 1 deletion oap-server/server-starter/src/main/assembly/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ storage:
user: ${SW_STORAGE_H2_USER:sa}
metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
# mysql:
# metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
# 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}
receiver-sharing-server:
default:
receiver-register:
Expand Down
1 change: 0 additions & 1 deletion oap-server/server-starter/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<include>application.yml</include>
<include>alarm-settings.yml</include>
<include>alarm-settings-sample.yml</include>
<include>datasource-settings.properties</include>
<include>gateways.yml</include>
</includes>
</fileSet>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

package org.apache.skywalking.oap.server.starter.config;

import java.io.FileNotFoundException;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
Expand All @@ -30,6 +26,11 @@
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.io.FileNotFoundException;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;

/**
* Initialize collector settings with following sources. Use application.yml as primary setting, and fix missing setting
* by default settings in application-default.yml.
Expand Down Expand Up @@ -61,21 +62,25 @@ private void loadConfig(ApplicationConfiguration configuration) throws ConfigFil
if (providerConfig.size() > 0) {
logger.info("Get a module define from application.yml, module name: {}", moduleName);
ApplicationConfiguration.ModuleConfiguration moduleConfiguration = configuration.addModule(moduleName);
providerConfig.forEach((name, propertiesConfig) -> {
logger.info("Get a provider define belong to {} module, provider name: {}", moduleName, name);
providerConfig.forEach((providerName, propertiesConfig) -> {
logger.info("Get a provider define belong to {} module, provider name: {}", moduleName, providerName);
Properties properties = new Properties();
if (propertiesConfig != null) {
propertiesConfig.forEach((key, value) -> {
properties.put(key, value);
final Object replaceValue = yaml.load(PropertyPlaceholderHelper.INSTANCE
.replacePlaceholders(value + "", properties));
if (replaceValue != null) {
properties.replace(key, replaceValue);
propertiesConfig.forEach((propertyName, propertyValue) -> {
if (propertyValue instanceof Map) {
tristaZero marked this conversation as resolved.
Show resolved Hide resolved
Properties subProperties = new Properties();
((Map) propertyValue).forEach((key, value) -> {
subProperties.put(key, value);
replacePropertyAndLog(key, value, subProperties, providerName);
});
properties.put(propertyName, subProperties);
} else {
properties.put(propertyName, propertyValue);
replacePropertyAndLog(propertyName, propertyValue, properties, providerName);
}
logger.info("The property with key: {}, value: {}, in {} provider", key, replaceValue.toString(), name);
});
}
moduleConfiguration.addProviderConfiguration(name, properties);
moduleConfiguration.addProviderConfiguration(providerName, properties);
});
} else {
logger.warn("Get a module define from application.yml, but no provider define, use default, module name: {}", moduleName);
Expand All @@ -86,6 +91,14 @@ private void loadConfig(ApplicationConfiguration configuration) throws ConfigFil
throw new ConfigFileNotFoundException(e.getMessage(), e);
}
}

private void replacePropertyAndLog(final Object propertyName, final Object propertyValue, final Properties target, final Object providerName) {
final Object replaceValue = yaml.load(PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(propertyValue + "", target));
if (replaceValue != null) {
target.replace(propertyName, replaceValue);
logger.info("The property with key: {}, value: {}, in {} provider", propertyName, replaceValue.toString(), providerName);
}
}

private void overrideConfigBySystemEnv(ApplicationConfiguration configuration) {
for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
Expand Down
10 changes: 9 additions & 1 deletion oap-server/server-starter/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ storage:
# user: ${SW_STORAGE_H2_USER:sa}
# metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
# mysql:
# metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
# 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}
receiver-sharing-server:
default:
receiver-register:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.storage.plugin.jdbc.mysql;

import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;

import java.util.Properties;

/**
*
* @author panjuan
*/
@Setter
@Getter
public final class MySQLStorageConfig extends ModuleConfig {

private int metadataQueryMaxSize = 5000;
private Properties properties;
}
Loading