You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-cloud-tencent/spring-cloud-tencent-examples/polaris-router-grayrelease-...
Haotian Zhang e5f7a75e09
refactor:optimize project and code (#368)
3 years ago
..
router-grayrelease-backend fix some bugs and optimize example 3 years ago
router-grayrelease-frontend refactor:optimize project and code (#368) 3 years ago
router-grayrelease-gateway refactor:optimize project and code (#368) 3 years ago
router-grayrelease-middle refactor:optimize project and code (#368) 3 years ago
README-zh.md optimize gray-release router example 3 years ago
README.md optimize gray-release router example 3 years ago
pom.xml feat: 支持灰度发布的demo (#193) 3 years ago

README.md

Spring Cloud Polaris Gray Release Example

English | 简体中文

Project Explanation

This project shows how to use Spring Cloud Tencent route and transitive feature to do the full chain gray releasing.

Architecture

Incoming requests dispatched from Gateway service to 3 environments

  • gray1(match uid=1), env=green(green environment)
  • gray2(match uid=2), env=purple(purple environment)
  • baselinestable environment, match all other requests, env=blue(blue environment)

How to access

Start Gateway service

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
  2. start router-grayrelease-gateway application

    • Launch by IDEStart the main class GrayReleaseGatewayApplication.
    • Launch by JarExecute mvn clean package to compile with jar package, then use java -jar router-grayrelease-gateway-${verion}.jar to launch application.
  3. add the route rule

    Send http request to polaris server to add the route rule, make requests dispatched to 3 environments.

    POST /naming/v1/routings
    
    [{
    	"service": "gray-release-gateway",
    	"namespace": "default",
    	"outbounds": [
       {
    	    "sources": [
         {
    		   "service": "gray-release-gateway",
    		   "namespace": "default",
    		   "metadata": {
    			  "${http.header.uid}": {
    				 "type": "EXACT",
    			     "value": "2"
    			  }
    		   }
    	    }],
    	    "destinations": [
         {
    		   "service": "*",
    		   "namespace": "*",
    		   "metadata": {
    			  "env": {
    			    "type": "EXACT",
    			    "value": "purple"
    			  }
    		   },
    		   "priority": 0,
    		   "weight": 100,
    		   "isolate": false
    	    }]
    	  },
    	  {
    		"sources": [
         {
    		   "service": "gray-release-gateway",
    		   "namespace": "default",
    		   "metadata": {
    			 "${http.header.uid}": {
    				"type": "EXACT",
    				"value": "1"
    		     }
    		   }
    		}],
    		"destinations": [
         {
    			"service": "*",
    			"namespace": "*",
    			"metadata": {
    				"env": {
    					"type": "EXACT",
    					"value": "green"
    				}
    			},
    			"priority": 0,
    			"weight": 100,
    			"isolate": false
    		}]
    	  },
    	  {
    		"sources": [
         {
    			"service": "gray-release-gateway",
    			"namespace": "default",
    			"metadata": {
    				"*": {
    					"type": "EXACT",
    					"value": "*"
    				}
    			}
    		}],
    		"destinations": [
         {
    			"service": "*",
    			"namespace": "*",
    			"metadata": {
    				"env": {
    					"type": "EXACT",
    					"value": "blue"
    				}
    			},
    			"priority": 0,
    			"weight": 100,
    			"isolate": false
    		}]
    	  }
    	]
    }]
    

    The route rule can be added by polaris console:

Start Front service

Start baseline environment (blue)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=blue
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-frontend application

    • Launch by IDEStart the main class GrayReleaseFrontApplication.
    • Launch by JarExecute mvn clean package to compile with jar package, then use java -jar router-grayrelease-frontend-${verion}.jar to launch application.

Start gray1 environment (green)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=green
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-frontend application (same as previous instruction)

    If port conflicted, you can specify another port by -Dserver.port

Start gray2 environment (purple)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=purple
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-frontend application (same as previous instruction)

Start effective

You can find the instances with different tags in polaris console.

Start Middle service

Start baseline environment (blue)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=blue
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-middle application

    • Launch by IDEStart the main class GrayReleaseMiddleApplication.
    • Launch by JarExecute mvn clean package to compile with jar package, then use java -jar router-grayrelease-middle-${verion}.jar to launch application.

Start gray2 environment (purple)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=purple
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-middle application (same as previous instruction)

Start Back service

Start baseline environment (blue)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=blue
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-backend application

    • Launch by IDEStart the main class GrayReleaseBackendApplication.
    • Launch by JarExecute mvn clean package to compile with jar package, then use java -jar router-grayrelease-backend-${verion}.jar to launch application.

Start gray1 environment (green)

  1. add environment variables

    • polaris server address: polaris_address=grpc://127.0.0.1:8091
    • pushgateway address: prometheus_address=127.0.0.1:9091
    • env tagSCT_METADATA_CONTENT_env=green
    • transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env
  2. start router-grayrelease-backend application (same as previous instruction)

Test

Baseline routing

curl -H'uid:0' 127.0.0.1:59100/router/gray/route_rule

Got result

gray-release-gateway -> gray-release-front[blue] -> gray-release-middle[blue] -> gray-release-back[blue]

Green routing

curl -H'uid:1' 127.0.0.1:59100/router/gray/route_rule

Got result

gray-release-gateway -> gray-release-front[green] -> gray-release-middle[blue] -> gray-release-back[green]

Purple routing

curl -H'uid:2' 127.0.0.1:59100/router/gray/route_rule

Got result

gray-release-gateway -> gray-release-front[purple] -> gray-release-middle[purple] -> gray-release-back[blue]