当前位置: 首页 > news >正文

INFINI Gateway 如何防止大跨度查询

背景

业务每天生成一个日期后缀的索引,写入当日数据。
业务查询有时会查询好多天的数据,导致负载告警。
现在想对查询进行限制–只允许查询一天的数据(不限定是哪天),如果想查询多天的数据就走申请。

技术分析

在每天一个索引的情况下,要进行多天的数据查询,有三种途径:

  1. 查询时,指定多个索引
  2. 查询时,写前缀+*号,模糊匹配多个索引
  3. 查询别名,别名关联多个索引

需求实现

我们只需用网关代理 ES 集群,并在 default_flow 中增加一段 request_path_filter 过滤器的配置,只允许查询一个索引且格式如 “xxx-2023-12-06”, “xxx.2023.12.06”, “xxx20231206” 。

      - request_path_filter:message: "Query scope exceeds limit, please contact the administrator for application."must:suffix:- _searchregex:- \/[a-z]+[-.]?\d{4}[-.]?\d{1,2}[-.]?\d{1,2}\/


如果需要指定其他格式,请自行修改 regex 的正则表达式。

创建测试索引

在 INFINI Console 开发工具中执行下列语句:

POST test-2023-12-06/_doc
{"test":"test"
}POST test-2023-12-6/_doc
{"test":"test"
}
POST test.2023.12.06/_doc
{"test":"test"
}
POST test.2023.12.6/_doc
{"test":"test"
}POST test20231206/_doc
{"test":"test"
}POST test/_doc
{"test":"test"
}

查询测试语句

#预计成功的查询
curl localhost:8000/test-2023-12-06/_search?pretty
curl localhost:8000/test-2023-12-6/_search?pretty
curl localhost:8000/test.2023.12.06/_search?pretty
curl localhost:8000/test.2023.12.6/_search?pretty
curl localhost:8000/test20231206/_search?pretty
#预计失败的查询
curl localhost:8000/test-2023-12-06,test-2023-12-6/_search?pretty
curl localhost:8000/test-2023-12*/_search?pretty
curl localhost:8000/test*/_search?pretty
curl localhost:8000/*/_search?pretty

查询结果

预计成功的查询

预计失败的查询


此外,我们在 Console 中的 Request Analysis 看板中也能看到,哪些请求被拒绝,哪些请求被“放行”。

查询多个索引(多天)

现在我们已经实现了业务只能查一个索引,即一天的数据。当业务需要查询多天的索引时,我们只需创建一个别名,关联多个索引就行了。注意别名也要符合格式要求:字母开头 + 日期格式后缀。
下面我们创建一个 test-1111-1-1 的别名,关联前面的三个测试索引。

POST /_aliases
{"actions" : [{ "add" : { "indices" : ["test-2023-12-06", "test.2023.12.06","test-2023-12-6"], "alias" : "test-1111-1-1" } }]
}

查询别名

待业务查询用完之后,删除别名即可。

POST /_aliases
{"actions" : [{ "remove": { "indices" : ["test-2023-12-06", "test.2023.12.06","test-2023-12-6"], "alias" : "test-1111-1-1" } }]
}

最后,我们只需严格控制别名的创建,就能实现我们最初的需求了。

http://www.lryc.cn/news/266039.html

相关文章:

  • 【模式识别】探秘分类奥秘:最近邻算法解密与实战
  • 【Redis】分布式锁
  • Linux访问firefox 显示Error: no DISPLAY environment variable specified
  • 线性回归简介
  • Log4net 教程
  • test-01-java 单元测试框架 junit 入门介绍
  • Linux系统中跟TCP相关的系统配置项
  • python图片批量下载多线程+超时重试
  • 冒泡排序之C++实现
  • 【Spring实战】04 Lombok集成及常用注解
  • ubuntu-22.04.3 配置
  • [工具]java_sublime的快速使用
  • 【银行测试】银行金融测试+金融项目测试点汇总...
  • 将PPT的图保持高分辨率导入到Word / WPS中
  • 如何在Spring Boot中优雅地进行参数校验
  • 图还能有数据库?一文带你了解图数据库是个什么东西!
  • 力扣思维题——寻找重复数
  • 基于Kubernetes的jenkins上线
  • 每日一题——轮转数组
  • Unity手机移动设备重力感应
  • nodejs微信小程序+python+PHP基于推荐算法的电影推荐系统-计算机毕业设计推荐django
  • Linux 配置 swap 区
  • AG16KDDF256 User Manual
  • w15初识php基础
  • powerbuilder Primary! Delete! Filter! 三个缓冲区的作用
  • Confluent 与阿里云将携手拓展亚太市场,提供消息流平台服务
  • 【一起学Rust | 框架篇 | Tauri2.0框架】Tauri2.0环境搭建与项目创建
  • 算法基础之01背包问题
  • Git的总体认知与具体实现
  • Hadoop入门学习笔记——三、使用HDFS文件系统