当前位置:网站首页>Prometheus Cortex多租户读写的实现
Prometheus Cortex多租户读写的实现
2022-04-23 06:01:00 【洒满阳光的午后】
Cortex的所有组件会从每个请求header的X-Scope-OrgID中获取租户ID。此处的租户表示的是一组数据的拥有者,它向Cortex写入数据,并拥有该数据的查询权限。所有的Cortex组件都会无条件信任带X-Scope-OrgID的请求,因此如果希望保护Cortex免受恶意调用,需要自行添加一个保护层。
注意查询和写入请求的租户ID必须一致,否则无法查询到所需数据。
启用多租户特性
通过在配置文件中添加auth.enabled=true,或者命令行-auth.enabled=true启用多租户特性。例如:
./cortex -target=distributor -auth.enabled=true
如果希望禁用多租户,则需要向所有组件传递参数auth.enabled=false,这种情况下所有请求的X-Scope-OrgID都会被设置为"fake"。
Prometheus配置
方法一是直接在remote_write配置中添加header信息。
remote_write:
- url: http://<cortex>/prometheus/api/v1/push
headers:
X-Scope-OrgID: <org>
方法二是使用Cortex-Tenant,根据已有标签值添加header信息。
Cortex Tenant放置于Prometheus和Cortex之间,当Prometheus的写请求经过该组件时,Cortex Tenant会搜索其中的预定义标签的值,并将其作为X-Scope-OrgID的值添加到请求header中,再转发给Cortex。

详细使用方法见:
此组件为第三方组件,非Cortex团队维护。
查询侧配置
目前Cortex并没有提供多租户的前端查询页面,在使用Grafana作为查询客户端的情况下,可以按下面的方案实现多租户查询。(目前仅为构想,尚未实践和测试,理论可行)
方案一:
在Grafana与Cortex之间放置一层Nginx反向代理,Nginx添加类似如下配置:
server {
server_name prod.com
location / {
proxy_pass http://cortex;
proxy_set_header X-Scope-OrgID <prod tenant ID>;
}
}
server {
server_name ops.com
location / {
proxy_pass http://cortex;
proxy_set_header X-Scope-OrgID <ops tenant ID>;
}
}
Grafana侧将不同的租户通过Org隔离开,分别配置不同的数据源,以此实现不同租户仅能查询自身数据的目标。
方案二:
在Grafana中添加数据源的时候,配置Custom HTTP Headers。

版权声明
本文为[洒满阳光的午后]所创,转载请带上原文链接,感谢
https://zhangrongjie.blog.csdn.net/article/details/121407074
边栏推荐
猜你喜欢

LeetCode刷题|两个链表的第一个公共节点

关于 synchronized、ThreadLocal、线程池、Atomic 原子类的 JUC 面试题
![[ES6 quick start]](/img/9e/4c4be5907c1f7b3485c2f4178b9150.png)
[ES6 quick start]

Jenkins搭建与使用

Passerelle haute performance pour l'interconnexion entre VPC et IDC basée sur dpdk

SQL学习|集合运算

LeetCode刷题|368最大整除子集(动态规划)

MySQL 【读写锁+表锁+行锁+MVCC】

端口占用1

Kids and COVID: why young immune systems are still on top
随机推荐
虚拟环境中使用jupyter notebook
Get DOM element location information by offset and client
LeetCode刷题|368最大整除子集(动态规划)
TP5 使用redis
Jenkins搭建与使用
【MySQL基础篇】数据导出导入权限与local_infile参数
mysql中sum (if)_mysql 中sum (if())
TP5 uses redis
openvswitch vlan网络实践
The time format is incorrect, and an error is reported when running the SQL file
【OSS文件上传快速入门】
TypeScript(下)
JS handwriting compatibility event binding
rdma网络介绍
微信小程序
重启Oracle监听器会中断已有连接吗
【不积跬步无以至千里】MySQL报大量unauthenticated user连接错误
[step by step, even thousands of miles] MySQL reports a large number of unauthenticated user connection errors
MySQL【ACID+隔离级别+ redo log + undo log】
Concurrent optimization request