OpenApi
上游
查询列表
查询详情
新增
{
"name": "jg_upstream",
"driver": "http",
"description": "通过postman添加上游",
"scheme": "HTTPS",
"retry":"1",
"timeout": 1000,
"nodes": [
"127.0.0.1:80 weight=1"
],
"balance": "round-robin",
"pass_host": "node"
}
修改
如果名称或者id不存在则创建
{
"driver": "http",
"description": "修改通过postman添加上游",
"scheme": "HTTPS",
"retry":"3",
"timeout": 2000,
"nodes": [
"127.0.0.2:80 weight=1"
],
"balance": "round-robin",
"pass_host": "node"
}
删除
根据名字或者id
应用
查询列表
查询详情
新增
{
"additional": [],
"anonymous": false,
"auth": [
{
"config": {
"expire": 0,
"password": "jg_app",
"username": "jg_app"
},
"position": "header",
"token_name": "Authorization",
"type": "basic",
"users": [
{
"expire": 0,
"hide_credential": false,
"pattern": {
"password": "jg_app",
"username": "jg_app"
}
}
]
}
],
"description": "postman新增应用",
"driver": "app",
"id": "jg_app@app",
"labels": {},
"name": "jg_app"
}
修改
{
"additional": [],
"anonymous": false,
"auth": [
{
"config": {
"expire": 0,
"password": "jg_app1",
"username": "jg_app1"
},
"position": "header",
"token_name": "Authorization",
"type": "basic",
"users": [
{
"expire": 0,
"hide_credential": false,
"pattern": {
"password": "jg_app1",
"username": "jg_app1"
}
}
]
}
],
"description": "修改postman新增应用",
"driver": "app",
"labels": {},
"name":"修改了名字"
}
删除
API
查询列表
http://172.30.4.85:9400/api/router
查询详情
新增
#当http请求同时满足以下条件时才能匹配这个路由
#method为GET或者POST
#请求头内host的值后缀为.com
#请求路径uri为/demo
#头部存在name这个key,且对应值不为空值
#请求参数里包含key为id,且值不为123
{
"name": "complex_router",
"driver": "http",
"description": "一个匹配规则较复杂的路由",
"listen": 8099,
"method": [
"GET",
"POST"
],
"location": "/demo",
"host": ["*.com"],
"rules": [
{
"type":"header",
"name":"user",
"value":"apinto"
}
],
"service": "anonymous_service@service",
"template": ""
}
Plugin:自定义的插件
proxy_rewrite:重定向
{
"description": "新增api",
"disable": false,
"driver": "http",
"host": [],
"listen": 0,
"location": "/jg/delete",
"method": [
"DELETE"
],
"name": "jg_api",
"plugins": {
"proxy_rewrite": {
"config": {
"headers": {},
"host_rewrite": false,
"not_match_err": true,
"path_type": "prefix",
"prefix_path": [
{
"prefix_path_match": "/test",
"prefix_path_replace": "/test"
}
]
},
"disable": false
}
},
"profession": "router",
"retry": 0,
"rules": [],
"service": "upstream_test@service",
"template": "",
"time_out": 10000,
"websocket": false
}
修改
{
"description": "新增api",
"disable": false,
"driver": "http",
"host": [],
"listen": 0,
"location": "/delete",
"method": [
"DELETE"
],
"name": "jg_api",
"plugins": {
"proxy_rewrite": {
"config": {
"headers": {},
"host_rewrite": false,
"not_match_err": true,
"path_type": "prefix",
"prefix_path": [
{
"prefix_path_match": "/delete", //代理path
"prefix_path_replace": "/test" //数据源地址
}
]
},
"disable": false
}
},
"profession": "router",
"retry": 0,
"rules": [],
"service": "upstream_test@service",
"template": "",
"time_out": 10000,
"websocket": false
}
删除
策略
查询列表类型
查询策略列表
http://172.30.4.85:9400/api/strategy
查询策略详情
删除
访问策略
筛选的是所有的10.11.55.82服务器发送的get方法,
新增
过滤规则和生效规则,可以理解为什么可以做或不能做什么
如拒绝82服务发起的get请求,生效范围是所有请求
{
"description": "拒绝策略",
"driver": "visit",
"filters": {
"ip": [
"10.11.55.82"
],
"method": [
"GET"
]
},
"name": "ip_get",
"priority": 1,
"profession": "strategy",
"stop": false,
"visit": {
"continue": false,
"influence_sphere": {
"api": [
"ALL"
]
},
"visit_rule": "refuse"
}
}
修改
流量限制
新增
{
"description": "",
"driver": "limiting",
"filters": {
"method": [
"ALL"
]
},
"limiting": {
"metrics": [
"{api}"
],
"query": {
"hour": 10000,
"minute": 1000,
"second": 100
},
"response": {
"body": "{ \"msg\":\"很抱歉,$api 暂停服务,请稍候再试!,被流控了1111\"}",
"charset": "UTF-8",
"content_type": "application/json",
"status_code": 200
},
"traffic": {
"hour": 10000,
"minute": 1000,
"second": 100
}
},
"name": "jg_limite",
"priority": 1,
"profession": "strategy",
"stop": false
}
修改
{
"description": "修改流控",
"driver": "limiting",
"filters": {
"method": [
"ALL"
]
},
"limiting": {
"metrics": [
"{api}"
],
"query": {
"hour": 10000,
"minute": 1000,
"second": 100
},
"response": {
"body": "{ \"msg\":\"很抱歉,$api 暂停服务,请稍候再试!,被流控了1111\"}",
"charset": "UTF-8",
"content_type": "application/json",
"status_code": 200
},
"traffic": {
"hour": 10000,
"minute": 1000,
"second": 100
}
},
"name": "jg_limite",
"priority": 1,
"profession": "strategy",
"stop": false
}
灰度发布
一部分用户继续用产品特性A,一部分用户开始用产品特性B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B上面来。
新增
{
"description": "新增灰度",
"driver": "grey",
"filters": {},
"grey": {
"distribution": "percent",
"keep_session": false,
"matching": [],
"nodes": [
"172.30.4.81:4561"
],
"percent": 4800
},
"name": "jg_huidu",
"priority": 1,
"profession": "strategy",
"stop": false
}
修改
测试结果
5000代表50%,一次执行api本来地址,一次执行配置的新地址。
熔断
简单来说,用API的“出错比例”来表示这个API的健康状态,当这个比例值高于设定的阈值,API自动抛出异常,终止服务,这个过程就叫做自动熔断
Api有三种状态,健康期、观察期、熔断期
健康期正常转发到后端
熔断期直接返回预定的值
观察期允许转发到后端,失败达到阈值转入熔断期,成功达到预定阈值转入健康期
比如访问服务每秒失败三次进入熔断期,设置熔断持续时间2(2秒为基准,乘以连续熔断次数,第1次熔断时间为2秒,连续第2次熔断时间为2秒乘以2为4秒),达到熔断时间进入观察期,可以正常请求后端,请求成功达到每秒3次进入健康期,请求失败达到每秒2次则再次进入熔断,随着连续熔断次数增多,熔断时间会越来越大,设置最大熔断持续时间500。设置熔断响应内容
新增
{
"description": "新增熔断",
"driver": "fuse",
"filters": {
"api": [
"659bbf16-9c59-5414-8247-fde143eb783b"
],
"method": [
"GET"
]
},
"fuse": {
"fuse_condition": {
"count": 1,
"status_codes": [
500
]
},
"fuse_time": {
"max_time": 300,
"time": 2
},
"metric": "{service}",
"recover_condition": {
"count": 3,
"status_codes": [
200
]
},
"response": {
"body": "{ \"msg\":\"很抱歉,$api 暂停服务,请稍候再试!,被熔断了\"}",
"charset": "UTF-8",
"content_type": "application/json",
"status_code": 200
}
},
"name": "jg_rongduan",
"priority": 1,
"profession": "strategy",
"stop": false
}
修改
{
"description": "修改熔断",
"driver": "fuse",
"filters": {
"api": [
"659bbf16-9c59-5414-8247-fde143eb783b"
],
"method": [
"ALL"
]
},
"fuse": {
"fuse_condition": {
"count": 5,
"status_codes": [
500
]
},
"fuse_time": {
"max_time": 200,
"time": 2
},
"metric": "{service}",
"recover_condition": {
"count": 4,
"status_codes": [
200
]
},
"response": {
"body": "{ \"msg\":\"很抱歉,$api 暂停服务,请稍候再试!,被熔断了\"}",
"charset": "UTF-8",
"content_type": "application/json",
"status_code": 200
}
},
"name": "jg_rongduan",
"priority": 1,
"profession": "strategy",
"stop": false
}
服务发现
新增
http://172.30.4.85:9400/api/discovery
{
"config": {
"address": [
"http://172.30.3.113:8848"
],
"address_static": [
"http://172.30.3.113:8848"
],
"params": {
"password": "nacos ",
"username": "nacos"
}
},
"description": "nacos服务发现22222222",
"driver": "nacos",
"name": "nacos_dis",
"profession": "discovery"
}
修改
所有查询
172.30.4.84:9400/api/discovery
查询详情
172.30.4.85:9400/api/discovery/nacos_dis@discovery
上游服务绑定服务发现
http://172.30.4.84:9400/api/service
{
"name": "nacos_up_postman",
"driver": "http",
"description": "postman新增nacos上游",
"timeout": 1000,
"retry": 3,
"discovery": "nacos_dis@discovery",
"service": "esb-console-biz",
"balance": "round-robin",
"pass_host": "node",
"profession": "service",
"scheme": "HTTP",
"use_discovery": true
}
创建一个api绑定nacos服务发现
http://172.30.4.85:9400/api/router/
{
"description": "post添加api通过nacos发现服务",
"disable": false,
"driver": "http",
"host": [],
"listen": 0,
"location": "/console/v1/businesstagconfig",
"method": [
"GET"
],
"name": "postman_api_nacos",
"plugins": {
"proxy_rewrite": {
"config": {
"headers": {},
"host_rewrite": false,
"not_match_err": true,
"path_type": "prefix",
"prefix_path": [
{
"prefix_path_match": "/console/v1/businesstagconfig",
"prefix_path_replace": "/console/v1/businesstagconfig"
}
]
},
"disable": false
}
},
"profession": "router",
"retry": 0,
"rules": [
{
"type": "header",
"name": "ss",
"value": "dd"
}
],
"service": "nacos_up_postman@service",
"template": "",
"time_out": 10000,
"websocket": false
}
插件
查询
172.30.4.85:9400/api/template/
查询详情
172.30.4.85:9400/api/template/cc4538eb-abb8-4f09-2d2d-7e4d35f9e3db@template
新增
172.30.4.85:9400/api/template
{
"description": "postam 新增插件添加额外参数",
"driver": "plugin_template",
"name": "postman_plugin",
"plugins": {
"extra_params": {
"config": {
"error_type": "text",
"params": [
{
"conflict": "origin",
"name": "addparamter",
"position": "header",
"value": "paramtervalue"
}
]
},
"disable": false
}
},
"profession": "template"
}
API绑定插件
172.30.4.85:9400/api/router/
{
"description": "新增api绑定插件模板",
"disable": false,
"driver": "http",
"host": [],
"listen": 0,
"location": "/single/delete",
"method": [
"DELETE"
],
"name": "template_api",
"plugins": {
"proxy_rewrite": {
"config": {
"headers": {},
"host_rewrite": false,
"not_match_err": true,
"path_type": "prefix",
"prefix_path": [
{
"prefix_path_match": "/single",
"prefix_path_replace": "/single"
}
]
},
"disable": false
}
},
"profession": "router",
"retry": 0,
"rules": [],
"service": "test@service",
"time_out": 10000,
"template":” postman_plugin@template",
"websocket": false
}
日志
Kafka日志
查询
172.30.4.85:9400/api/output
查询详情
172.30.4.85:9400/api/output/kafka_access@output
新增
172.30.4.85:9400/api/output/
{
"address": "127.0.0.1",
"content_resize": [
{
"size": 11,
"suffix": "log"
}
],
"description": "postman_kafaka日志",
"driver": "kafka_output",
"formatter": {
"fields": [
"$request_id",
"$request",
"$status",
"@time",
"@proxy",
"$response_time"
],
"proxy": [
"$proxy_uri",
"$proxy_scheme",
"$proxy_addr"
],
"time": [
"$msec",
"$time_iso8601",
"$time_local"
]
},
"kafka_version": "3.1.0",
"name": "kafka_access_postman",
"partition_type": "hash",
"profession": "output",
"scopes": [
"access_log"
],
"timeout": 10,
"topic": "ddd",
"type": "json"
}
新增文件日志
{
"content_resize": [
{
"size": 3,
"suffix": "log"
}
],
"description": "postman 添加文件日志",
"dir": "/var/log/apinto",
"driver": "file",
"expore": "3",
"file": "access",
"formatter": {
"fields": [
"$time_iso8601",
"$request_id",
"@request",
"@proxy",
"@response",
"@status_code",
"@time"
],
"proxy": [
"$proxy_method",
"$proxy_scheme",
"$proxy_uri",
"$proxy_host",
"$proxy_header",
"$proxy_addr"
],
"request": [
"$request_method",
"$scheme",
"$request_uri",
"$host",
"$header",
"$remote_addr"
],
"response": [
"$response_header"
],
"status_code": [
"$status",
"$proxy_status"
],
"time": [
"$request_time",
"$response_time"
]
},
"name": "postman_access",
"period": "day",
"profession": "output",
"scopes": [
"access_log"
],
"type": "json"
}