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

Provide Consul dynamic configuration center implementation #3560

Merged
merged 5 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions docker/oap/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ configuration:
EOT
}

generateConfigurationConsul() {
cat <<EOT >> ${var_application_file}
configuration:
consul:
# Consul host and ports, separated by comma, e.g. 1.2.3.4:8500,2.3.4.5:8500
hostAndPorts: \${SW_CONFIGURATION_CONSUL_ADDRESS:127.0.0.1:8500}
# Sync period in seconds. Defaults to 60 seconds.
period: \${SW_CONFIGURATION_CONSUL_PERIOD:60}
EOT
}

generateTelemetryNone() {
cat <<EOT >> ${var_application_file}
telemetry:
Expand Down Expand Up @@ -346,6 +357,7 @@ EOT
apollo) generateConfigurationApollo;;
nacos) generateConfigurationNacos;;
zookeeper) generateConfigurationZookeeper;;
consul) generateConfigurationConsul;;
esac

cat <<EOT >> ${var_application_file}
Expand Down
16 changes: 13 additions & 3 deletions docs/en/setup/backend/dynamic-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@ configuration:
clusterName: "default"
```

## 3rd party Configuration Center
We are welcome contributions to implement this module provider to support popular configuration center,
such as Consul. Submit issue to discuss.
## Dynamic Configuration Consul Implementation

[Consul](https://github.com/rickfast/consul-client) is also supported as DCC(Dynamic Configuration Center), to use it, please configure as follows:

```yaml
configuration:
consul:
# Consul host and ports, separated by comma, e.g. 1.2.3.4:8500,2.3.4.5:8500
hostAndPorts: 127.0.0.1:8500
# Sync period in seconds. Defaults to 60 seconds.
period: 60
```



161 changes: 161 additions & 0 deletions oap-server/server-configuration/configuration-consul/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>server-configuration</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.5.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>configuration-consul</artifactId>

<properties>
<consul.client.version>1.2.6</consul.client.version>
<consul.image.version>0.9</consul.image.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>configuration-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>library-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.orbitz.consul</groupId>
<artifactId>consul-client</artifactId>
<version>${consul.client.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<profiles>
<profile>
<id>CI-with-IT</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<sourceMode>all</sourceMode>
<showLogs>true</showLogs>
<logDate>default</logDate>
<verbose>true</verbose>
<imagePullPolicy>IfNotPresent</imagePullPolicy>
<images>
<image>
<name>consul:${consul.image.version}</name>
<alias>cluster-consul-plugin-integration-test-cluster</alias>
<run>
<cmd>agent -server -bootstrap-expect=1 -client=0.0.0.0</cmd>
<ports>
<port>consul.port:8500</port>
</ports>
<wait>
<log>Synced node info</log>
<time>30000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>${gmaven-plugin.version}</version>
<executions>
<execution>
<id>add-default-properties</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>2.0</providerSelection>
<source>
project.properties.setProperty('docker.hostname', 'localhost')

log.info("Docker hostname is " + project.properties['docker.hostname'])
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<consul.address>
${docker.hostname}:${consul.port}
</consul.address>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.configuration.consul;

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

/**
* @author kezhenxu94
*/
public class ConsulConfigurationCenterSettings extends ModuleConfig {
@Getter
@Setter
private long period;

@Getter
@Setter
private String hostAndPorts;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.configuration.consul;

import com.google.common.base.Strings;
import org.apache.skywalking.oap.server.configuration.api.AbstractConfigurationProvider;
import org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Get configuration from Consul.
*
* @author kezhenxu94
*/
public class ConsulConfigurationProvider extends AbstractConfigurationProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfigurationProvider.class);

private final ConsulConfigurationCenterSettings settings;

public ConsulConfigurationProvider() {
this.settings = new ConsulConfigurationCenterSettings();
}

@Override
public String name() {
return "consul";
}

@Override
public ModuleConfig createConfigBeanIfAbsent() {
return settings;
}

@Override
protected ConfigWatcherRegister initConfigReader() throws ModuleStartException {
LOGGER.info("consul settings: {}", settings);

if (Strings.isNullOrEmpty(settings.getHostAndPorts())) {
throw new ModuleStartException("Consul hostAndPorts cannot be null or empty");
}

return new ConsulConfigurationWatcherRegister(settings);
}
}
Loading