Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

任务历史支持IP过滤 #1631

Closed
Xmandon opened this issue Jun 20, 2023 · 4 comments
Closed

任务历史支持IP过滤 #1631

Xmandon opened this issue Jun 20, 2023 · 4 comments
Assignees
Labels
done 已上线到正式环境并验收通过

Comments

@Xmandon
Copy link
Collaborator

Xmandon commented Jun 20, 2023

image

支持通过多个IP搜索任务历史

@neko12583
Copy link
Collaborator

neko12583 commented Jul 5, 2023

方案

接口

查询任务列表:api/job/job_list/

增加参数 inner_ip,为列表类型:

inner_ip = ["127.0.0.1", "::1"]

针对 ip 进行筛选

如果携带 inner_ip 参数

在该接口原查询逻辑结束、分页前,对 node_man_job 表数据中所有 task_id_list 提取为 all_task_id_list,同时构建字典用于后面查询:

{
    "job_id": [task_id_list]
}

判断每个 ipIPv4 还是 IPv6 分开组合成查询 node_man_host 条件

node_man_host 查出 IPv4 in inner_ipIPv6 in inner_ipv6bk_host_id、bk_cloud_id

根据信息生成 instance_id 查询范围 instance_id_list,两种形式:host|instance|host|{bk_host_id}host|instance|host|{ip}-{bk_cloud_id}-{constants.DEFAULT_SUPPLIER_ID=0}

node_man_subscriptioninstancerecord 中查询 task_id in all_task_id_listinstance_id in instance_id_list

其他

在联调环境:https://paas-dev.bktencent.com/ 中,node_man_subscriptioninstancerecord 表数据量为:15461906

联调环境实例记录表数据量
直接查询 instance_id 字段值模糊搜索包含指定 ip 耗时为:15s
联调环境实例记录表模糊搜索
查询时指定 instance_id 字段区间耗时为:0.03s
联调环境指定实例id区间
查询时同时指定 instance_id 字段区间与 task_id 区间耗时为:0.01s
联调环境指定任务id和实例id

@neko12583
Copy link
Collaborator

neko12583 commented Jul 10, 2023

方案更改

node_man_subscriptioninstancerecord 表中根据 instance_id in instance_id_list 以及 create_time > start_time 两个条件进行筛选

理由

node_man_subscriptioninstancerecord 表中有 1546w 条数据

image

大致估算 node_man_job 表每月新增 3w 条数据

分别以 task_id & instance_id 与 create_time & instance_id 两种方式进行查询,对比时间消耗

方式 1:task_id & instance_id

from apps.node_man import models
task_id = models.SubscriptionInstanceRecord.objects.filter(id__lt=120000).values_list("task_id", flat=True)
task_id = list(set(task_id))
print(len(task_id))

image

import time
def test_time(params):
    print(time.time())
    data = models.SubscriptionInstanceRecord.objects.filter(**params)
    print(time.time())
    print(len(data))
    return data

params = {"task_id__in": task_id, "instance_id": "host|instance|host|10.0.1.59-0-0"}
data = test_time(params)

image

多组数据平均时间为 0.06s

方式 2:create_time & instance_id

target_date = datetime(2023, 6, 10)
params = {"create_time__gt": target_date, "instance_id": "host|instance|host|10.0.1.59-0-0"}
data = test_time(params)

image

多组数据平均时间接近 0.001s

neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 12, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 12, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 12, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 12, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 18, 2023
@neko12583
Copy link
Collaborator

自测截图

1、页面显示 ip 搜索条件

页面显示ip条件

2、查询指定 ip 任务

查询ip

3、单个 ip 的任务

任务详情92

4、 多个 ip 的任务

任务详情多个ip

5、job 表5000条数据时,且4900都有指定 ip 时,查询shi时间

数据量5000时响应时间

neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 18, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 18, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 18, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 18, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 19, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 19, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 25, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 25, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 25, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 25, 2023
@ZhuoZhuoCrayon ZhuoZhuoCrayon added backlog 需求初始状态,等待产品进行评估 todo 进入开发排期的状态,纳入了最近的迭代 doing 已经接受处理,正在开发实验 and removed backlog 需求初始状态,等待产品进行评估 todo 进入开发排期的状态,纳入了最近的迭代 labels Jul 26, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 26, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 26, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 27, 2023
neko12583 added a commit to neko12583/bk-nodeman that referenced this issue Jul 27, 2023
@ZhuoZhuoCrayon ZhuoZhuoCrayon added for test 可以在测试环境进行验收 and removed doing 已经接受处理,正在开发实验 labels Aug 3, 2023
@wyyalt wyyalt added tested 已经在测试环境验收通过 and removed for test 可以在测试环境进行验收 labels Aug 10, 2023
@neko12583
Copy link
Collaborator

问题修复

问题复现

当用户不具备全部业务、查询所有业务的历史任务时,会出现报错:
页面
报错

问题修复

修复验证

@wyyalt wyyalt added done 已上线到正式环境并验收通过 and removed tested 已经在测试环境验收通过 labels Aug 14, 2023
@wyyalt wyyalt reopened this Aug 25, 2023
@wyyalt wyyalt closed this as completed Aug 25, 2023
@wyyalt wyyalt added tested 已经在测试环境验收通过 and removed tested 已经在测试环境验收通过 labels Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done 已上线到正式环境并验收通过
Projects
Status: To do
Development

No branches or pull requests

5 participants