最近几次业务的上线均存在上线时间持续过长、线上暴露问题多、影响用户体验的问题,预计预发布环境建设完成后,能获取如下收益:
1)让测试老师有更多时间在线上环境验证问题,能提前暴露部分线上问题,进而提升用户的体验,
2)面对线上环境的问题,研发有更多的时间进行解决,相关方案也会更加完备,避免解决一个问题同时带来另一个问题。
主流程方案如下:
前端:通过域名进行区分,预发布环境申请新的域名
后端:前端根据用户访问的域名知道当前的环境,预发布环境中添加header后访问后端接口,后端通过header将对应环境的请求路由到对应的环境。
后端主逻辑
需要梳理预发布和线上哪些资源是需要隔离的,确认mysql、nas、oss等存储不隔离,但分支、redis(可以通过)、mq、naocs需要隔离
在k8s中创建pre环境新的pod,然后在isito的VirtualService中引用该pod的service,将预发布的流量路由到预发布环境的pod,virtualService核心配置如下:
spec:
gateways:
- abtest-gateway
hosts:
- test-api.com
http:
- corsPolicy:
allowCredentials: true
allowHeaders:
- authorization
- platform
- '*'
allowMethods:
- PUT
- GET
- POST
- DELETE
- OPTIONS
- PATCH
- TRACE
- HEAD
allowOrigins:
- prefix: h
maxAge: 24s
match:
- headers:
env:
exact: pre
retries:
attempts: 1
retryOn: retriable-status-codes
route:
- destination:
host: >-
platform-pre-test-svc.peiyou-pre.svc.cluster.local
weight: 100
- corsPolicy:
allowCredentials: true
allowHeaders:
- authorization
- platform
- '*'
allowMethods:
- PUT
- GET
- POST
- DELETE
- OPTIONS
- PATCH
- TRACE
- HEAD
allowOrigins:
- prefix: h
maxAge: 24s
retries:
attempts: 1
retryOn: retriable-status-codes
route:
- destination:
host: virtual.machine.backend.service.test-api.com
weight: 0
- destination:
host: platform-api-test-srv
weight: 100
说明:重点关注match配置