Skip to content

Commit

Permalink
xds service discovery demo
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Jul 4, 2024
1 parent 35bd9a3 commit 604d4de
Show file tree
Hide file tree
Showing 30 changed files with 969 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,14 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/package/result/sermant-examples-first-plugin-demo-${{ env.version }}.tar.gz
asset_name: sermant-examples-first-plugin-demo-${{ env.version }}.tar.gz
asset_content_type: application/tar
- name: Upload Release xds-service-discovery-demo # xds-service-discovery-demo release包
id: upload-release-asset-xds-service-discovery
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/package/result/sermant-examples-xds-service-discovery-demo-${{ env.version }}.tar.gz
asset_name: sermant-examples-xds-service-discovery-demo-${{ env.version }}.tar.gz
asset_content_type: application/tar
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<module>mq-consume-prohibition-demo</module>
<module>loadbalancer-demo</module>
<module>database-write-prohibition-demo</module>
<module>xds-service-discovery-demo</module>
</modules>

<properties>
Expand Down
4 changes: 4 additions & 0 deletions scripts/copy_jar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ mkdir -p package/removal-demo
mkdir -p package/mq-consume-prohibition-demo
mkdir -p package/database-write-prohibition-demo
mkdir -p package/first-plugin-demo
mkdir -p package/xds-service-discovery-demo

# 按照文件名模式将对应的jar文件复制到对应目录
# 创建首个插件
find . -type d -name "agent" -exec cp -rv {} package/first-plugin-demo/ \;
# xDS服务发现
find . -type d -name "product" -exec cp -rv {} package/xds-service-discovery-demo/ \;
# 动态配置
find . -type f -name "spring-provider.jar" -exec cp -v {} package/dynamic-demo/ \;
# 流控
Expand Down Expand Up @@ -72,6 +75,7 @@ find . -type f -name "rest-provider.jar" -exec cp -v {} package/removal-demo/ \;

# 打包
tar -czvf package/result/sermant-examples-first-plugin-demo-$*.tar.gz -C package/first-plugin-demo/ .
tar -czvf package/result/sermant-examples-xds-service-discovery-demo-$*.tar.gz -C package/xds-service-discovery-demo/ .
tar -czvf package/result/sermant-examples-dynamic-demo-$*.tar.gz -C package/dynamic-demo/ .
tar -czvf package/result/sermant-examples-flowcontrol-demo-$*.tar.gz -C package/flowcontrol-demo/ .
tar -czvf package/result/sermant-examples-grace-demo-$*.tar.gz -C package/grace-demo/ .
Expand Down
8 changes: 8 additions & 0 deletions xds-service-discovery-demo/config/bootstrap.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Specifies the artifact name of the current Sermant artifact, used to identify different Sermant artifacts in a multi-Sermant scenario, and to isolate different Sermant configurations and service governance capabilities based on the artifact
artifact=default
# Specifies application name of the current host instance accessed by Sermant
appName=default
# Specifies application type of the current host instance accessed by Sermant
appType=default
# Specifies service name of the current host instance accessed by Sermant
serviceName=default
115 changes: 115 additions & 0 deletions xds-service-discovery-demo/config/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#=============================bytecode enhancement configuration==============================#
# ReTransform switch. If enabled, bytecode enhancement can be performed on loaded classes by ReTransform. The default value is true.
agent.config.isReTransformEnable=true
# If this function is enabled, logs related to bytecode enhancement will be output to log files. The default value is false.
agent.config.isShowEnhanceLog=false
# Enhanced class bytecode output switch. If this switch is enabled, the enhanced bytecode is output as a file. The default value is false
agent.config.isOutputEnhancedClasses=false
# The enhanced bytecode output location of the enhanced class. If this parameter is not configured, it is agent/enhancedClasses by default
agent.config.enhancedClassesOutputPath=
# Enable the host service instance class to be loaded by the thread context classloader during interceptor execution. If enabled, the host class is loaded by the context classloader during interceptor execution for service governance logic use. The default value is true.
agent.config.useContextLoader=true
# List of class prefixes that need be ignored when bytecode enhancement is performed.
agent.config.ignoredPrefixes=io.sermant
# List of interfaces that need to be ignored when bytecode enhancement is used to search for a class. If all implementation classes of an interface do not want to be bytecode enhanced, you can configure this configuration item
agent.config.ignoredInterfaces=org.springframework.cglib.proxy.Factory
# Specifies which classes in the plugins are allowed to be bytecode enhanced (classes in the plugins are not allowed to be bytecode enhanced by default)
agent.config.serviceInjectList=io.sermant.discovery.service.lb.filter.NopInstanceFilter,io.sermant.discovery.service.lb.DiscoveryManager,io.sermant.discovery.service.util.ApplyUtil,io.sermant.discovery.service.lb.cache.InstanceCacheManager
# Generate unmatched class name to file, used to reduce startup time for the second time and after
agent.config.preFilter.enable=false
# Path of unmatched class name file, the default path is the same directory of sermant-agent.jar
agent.config.preFilter.path=
# File name of unmatched class name, the default file is 'unmatched_class_name.txt'
agent.config.preFilter.file=
#============================= core service configuration =============================#
# Heartbeat service switch
agent.service.heartbeat.enable=false
# Gateway service switch
agent.service.gateway.enable=false
# Tracing service switch
agent.service.tracing.enable=false
# Spring inject service switch
agent.service.inject.enable=true
# Dynamic config service switch
agent.service.dynamic.config.enable=false
# HTTP server switch
agent.service.httpserver.enable=false
# xDS service switch
agent.service.xds.service.enable=true
#============================= Event configuration =============================#
# Event switch
event.enable=false
# Report warn log switch
event.offerWarnLog=false
# Report error log switch
event.offerErrorLog=false
# Event sending interval, specifying the interval (ms) for events to be sent to Sermant Backend
event.sendInterval=30000
# Specify the same event recording interval to repeat event compression (ms) over a certain period of time
event.offerInterval=300000
# Internal event notification switch
notification.enable=false
#=============================Dynamic config service configuration =============================#
# Specify config read timeout (ms)
dynamic.config.timeoutValue=30000
# Specify the default group for the config
dynamic.config.defaultGroup=sermant
# Specify the server address of the configuration center
dynamic.config.serverAddress=127.0.0.1:2181
# Specify the type of dynamic configuration center. The value can be NOP(no implementation), ZOOKEEPER, KIE, or NACOS
dynamic.config.dynamicConfigType=ZOOKEEPER
# Specify the number of reconnections to the configuration center when Sermant is started
dynamic.config.connectRetryTimes=5
# Specify the timeout (ms) of connection to the configuration center when Sermant is started
dynamic.config.connectTimeout=1000
# Specify whether to enable the authorization of the configuration center. If enable authorization, you need to verify the user name and password
dynamic.config.enableAuth=false
# Specify the user name for connecting to the dynamic configuration center
dynamic.config.userName=
# Specify the password for connecting to the dynamic configuration center
dynamic.config.password=
# Specify the AES privateKey that encrypts and decrypts the password
dynamic.config.privateKey=
# Specify the request timeout time (ms) to get the configuration
dynamic.config.requestTimeout=3000
#=============================Heartbeat service configuration===============================#
# Specify Heartbeat Interval (ms)
heartbeat.interval=30000
#=============================Spring inject service configuration=========================#
# The packages needed for Spring inject service
inject.essentialPackage=io.sermant,io.sermant.dynamic.config,io.sermant.flowcontrol,io.sermant.loadbalancer,io.sermant.monitor,io.sermant.dubbo.registry,io.sermant.registry,io.sermant.visibility,io.sermant.discovery
#=============================Gateway service configuration===============================#
# Specify the IP address of Netty server
gateway.nettyIp=127.0.0.1
# Specify the port of Netty server
gateway.nettyPort=6888
# Specify the Netty server connection timeout duration (ms)
#gateway.nettyConnectTimeout=5000
# Specify read/write wait time of Netty (ms).
#gateway.nettyWriteAndReadWaitTime=60000
# Specify the interval that data sent to the server (s).
#gateway.sendInternalTime=10
# Specify retreat algorithm initial connection interval (s)
#gateway.initReconnectInternalTime=5
# Specify retreat algorithm maximum connection interval (s)
#gateway.maxReconnectInternalTime=180
#=============================xds configuration===============================#
# istiod control plane address, security.enable=false with 15010 port, and security.enable=true with 15012 port
xds.config.control.plane.address=istiod.istio-system.svc:15010
# Whether to use secure communication with the control plane
xds.config.security.enable=false
# service account token used for secure communication with the control plane
xds.config.service.account.token.path=/var/run/secrets/kubernetes.io/serviceaccount/token
#=============================Metadata===============================#
# Service name for host service instance
service.meta.service=default
# Application name for host service instance, used in service governance scenarios such as service registration and label routing
service.meta.application=default
# Version for host service instance, used in service governance scenarios such as service registration and label routing
service.meta.version=1.0.0
# Namespace for host service instance, used in service governance scenarios such as service registration and label routing
service.meta.project=default
# Environment for host service instance, used in service governance scenarios such as service registration and label routing
service.meta.environment=
# Availability Zone for host service instance, used in service governance scenarios such as service registration and label routing
service.meta.zone=
63 changes: 63 additions & 0 deletions xds-service-discovery-demo/config/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>

<configuration scan="true" debug="false">
<!-- No operation event listener -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>

<!-- Configure the log file output location -->
<property name="log.home_dir" value="${sermant_log_dir:-./logs/sermant/core}"/>
<property name="log.app_name" value="${sermant_app_name:-sermant}"/>
<!-- The maximum log history -->
<property name="log.maxHistory" value="${sermant_log_max_history:-30}"/>
<property name="log.level" value="${sermant_log_level:-info}"/>
<property name="log.maxSize" value="${sermant_log_max_size:-50MB}"/>
<property name="log.totalSize" value="${sermant_log_total_size:-20GB}"/>

<!-- Configure the log output format -->
<!-- %d{yyyy-MM-dd HH:mm:ss.SSS} for date-->
<!-- %C for class name-->
<!-- %F for file name-->
<!-- %M for method name-->
<!-- %L for line number-->
<!-- %thread for thread name-->
<!-- %m %msg for message-->
<!-- %n for line break-->
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%le] [%C] [%M:%L] [%thread] %m%n"/>

<!-- ConsoleAppender for console output log -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>
${log.pattern}
</pattern>
</encoder>
</appender>

<!--Configure an up-pass appender that outputs logs of all levels-->
<appender name="app" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.home_dir}/app/%d{yyyy-MM-dd}/${log.app_name}-%i.log</fileNamePattern>
<maxHistory>${log.maxHistory}</maxHistory>
<MaxFileSize>${log.maxSize}</MaxFileSize>
<totalSizeCap>${log.totalSize}</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<pattern>
${log.pattern}
</pattern>
</encoder>
</appender>

<root>
<!-- Print logs for debug and higher level -->
<level value="${log.level}"/>
<appender-ref ref="app"/>
</root>

</configuration>
17 changes: 17 additions & 0 deletions xds-service-discovery-demo/config/plugins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The premain loads the plugin directory configured under plugins, and the agentmain loads the active plugin directory under dynamicPlugins
# Plugins are loaded in the following order:
# 1. First load the default plugins in the order configured in 'plugins'.
# 2. Then load the list of scene plugins according to the scene order configured in 'profile'. The loading order of scene plugins is the same as that in the configuration file.
# 3. If the plugin configured in 'profiles' has been loaded before, it will not be loaded again.
# 4. Bytecode enhancements at the same intercept point for different plugins take effect in the same order as the plugins load.
# 'plugins' is used to configure static plugins. The plugins take effect when Sermant starts by premain. Plugins that support static installation are configured and cannot be uninstalled
plugins:
- xds-service-discovery
# 'dynamicPlugins' is used to configure plugins that support dynamic installation. The plugins take effect when Sermant starts by agentmain. allows uninstallation:
# 1. active plugins will be actively enabled
# 2. passive plugins need to be enabled by commands
dynamicPlugins:
active:
# - active-plugin
passive:
# - passive-plugin
24 changes: 24 additions & 0 deletions xds-service-discovery-demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>io.sermant</groupId>
<artifactId>xds-service-discovery-demo</artifactId>
<version>2.0.0</version>

<modules>
<module>spring-client</module>
<module>spring-server</module>
<module>xds-service-discovery</module>
</modules>

<packaging>pom</packaging>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<spring.version>2.7.15</spring.version>
</properties>

</project>
7 changes: 7 additions & 0 deletions xds-service-discovery-demo/product/spring-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:8
WORKDIR /home
COPY agent/ /home/agent
COPY spring-client.jar /home/spring-client.jar
COPY start.sh /home
RUN chmod -R 777 /home
ENTRYPOINT ["sh", "/home/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -f Dockerfile -t spring-client:1.0.0 .
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-client
spec:
replicas: 1
selector:
matchLabels:
app: spring-client
template:
metadata:
labels:
app: spring-client
spec:
containers:
- name: spring-client
image: spring-client:1.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
imagePullSecrets:
- name: default-secret
---
apiVersion: v1
kind: Service
metadata:
name: spring-client
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 30110
selector:
app: spring-client
1 change: 1 addition & 0 deletions xds-service-discovery-demo/product/spring-client/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec java -javaagent:/home/agent/sermant-agent.jar -jar /home/spring-client.jar
6 changes: 6 additions & 0 deletions xds-service-discovery-demo/product/spring-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:8
WORKDIR /home
COPY spring-server.jar /home/spring-server.jar
COPY start.sh /home
RUN chmod -R 777 /home
ENTRYPOINT ["sh", "/home/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -f Dockerfile -t spring-server:1.0.0 .
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-server
spec:
replicas: 1
selector:
matchLabels:
app: spring-server
template:
metadata:
labels:
app: spring-server
spec:
containers:
- name: spring-server
image: spring-server:1.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
imagePullSecrets:
- name: default-secret
---
apiVersion: v1
kind: Service
metadata:
name: spring-server
spec:
type: ClusterIP
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
selector:
app: spring-server
1 change: 1 addition & 0 deletions xds-service-discovery-demo/product/spring-server/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec java -jar /home/spring-server.jar
Loading

0 comments on commit 604d4de

Please sign in to comment.