You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Gateway流程分析
作者:人生有如两个橘子
email:[email protected]
Linkis 1.3.2 流程图解
GateWay
采用的是webFlux
的响应式编程,其整个流程与spring mvc 类似流程图
Linkis 1.3.2 流程说明
其实整个流程核心为GatewayAuthorizationFilter的filter过程,其余的好理解,不做概述。
从功能上大致总结有三个阶段
简化流程为:
认证
从功能上单独把认证抽出来讲,核心SecurityFilter.doFilter方法,主要一些操作有:
校验类:ip白名单,refrere校验,url白名单
认证类:用户名密码认证,token认证,SSO认证
Parse阶段
Parse阶段主要确定ApplicationName,特殊的也确定了Instance
Input:RequestURI, Output:ServiceInstance
实现原理:RequestURI通过正则匹配分发到不同的parse实现类
特别注意:所有parse是串行执行,不会中断,因此parse之间的正则需要具有互斥性。
自定义Parse处理
我个人更愿意理解为Entrance的post类请求解析器,主要针对execute,submit等提交方法,需要校验requestBody,没有其他操作,直接返回ServiceInstance(linkis-cg-entrance, null)
我个人更愿意理解为Entrance的get类请求解析器,主要针对status,progress,log,metric等查询方法,无需校验requestBody,主要根据RequestURI路径不同进行不同处理,解析出Instance(这里比较特殊,在parse阶段确定了Instance)
通用Parse处理
调用了自定义parse类处理后,同时也做了通用处理,当没有ServiceInstance时,会根据RequestURI匹配通用规则的ServiceInstance(publicservice,metadataquery等),或者也可以理解为,单独写parse实现的,都是需要特殊处理的服务。
Route阶段
Route阶段主要确定Instance
Input:ServiceInstance(applicationName, null), Output:ServiceInstance(applicationName, instance)
也有特殊的,在parse阶段就确定instance
Route处理
DefaultLabelGatewayRouter(AbstractLabelGatewayRouter)
Route server白名单校验:可以通过配置ROUTER_SERVER_LIST实现,目前只有entrance服务
ServiceInstance实例选择逻辑:
首先从参数解析出routeLabel标签
case 1. 如果没有routeLabel, 则走默认逻辑获取可用的ServiceInstance列表,逻辑为:
1) 从eureka获取所有applicationName实例, 记为a
2) 从数据库获取有任意标签的applicationName实例, 记为b
3)a - b 做差集获取到可用(无标签)实例列表
case 2. 如果有routeLabel,从数据库获取实例列表
RouteLabel作用:用于做服务的租户隔离,当请求中带有routeLabel只会将对应的请求转发到对应打上了标签的服务。主要作用:1. 服务的租户隔离 2. 优雅下线:可以让服务快速被隔离,不会被路由到。
特别注意:
case 1. 可以保证获取的是指定applicationName的实例
case 2. 获取的实例可以是不同applicationName的实例
1)如果GatewayRoute.getServiceInstance中有指定applicationName,则需要待选实例列表进行过滤
2)待选实例与eureka过滤出存活(注册)的实例列表
3)从存活(注册)的实例列表随机选择一个
ServiceInstance校验
以eureka为例,主要服务名校验,实例校验
Route转换
利用ServiceInstance,从gateway转换到目标服务Route
例如:
Route{id='api', uri=lb://linkis-mg-gateway} -> Route{id='api', uri=lb://merge-gw-18linkis-cg-entrance192--168--1--1---9104}
Route{id='api', uri=lb://linkis-mg-gateway} -> Route{id='api', uri=lb://linkis-ps-publicservice}
知识小点
Beta Was this translation helpful? Give feedback.
All reactions