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

fix: bcs采集项接口支持多配置-单测问题修复 --bug=133201869 #3711

Open
wants to merge 12 commits into
base: feat/bcs_multi_conf
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
## Deploy files
.pre-commit-config.yaml
apps/log_audit/base.py
apps/log_audit/config.py
apps/log_audit/otlp.py
apps/log_clustering/handlers/clustering_monitor.py.bak
apps/log_clustering/handlers/data_access/data_access.py.copy
apps/log_clustering/views/clustering_config_views.py.bak
apps/log_extract/migrations/0026_auto_20240911_1503.py
apps/log_search/handlers/search/search_handlers_esquery_copy.py
apps/tests/log_databus/test_bcs_collector.py_copy
faker.py
gtm_commit.sh
xxx00.txt


/apidoc/
/web/index-dev.html
Expand Down
2 changes: 2 additions & 0 deletions bklog/apps/log_databus/handlers/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,8 @@ def sync_bcs_container_task(self, data: Dict[str, Any]):
).first()
if not container_config:
continue
print(self.create_container_release)
print(self.create_container_release)
self.deal_self_call(
collector_config_id=collector_config.collector_config_id,
collector=collector_config,
Expand Down
80 changes: 18 additions & 62 deletions bklog/apps/tests/log_databus/test_bcs_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
the project delivered to anyone in the future.
"""
import copy
import json

# import json
from unittest.mock import patch

from django.test import TestCase, override_settings
Expand All @@ -31,7 +32,7 @@
from apps.utils.drf import custom_params_valid

PATH_STD_PARAMS = {
"bk_biz_id": 2,
"bk_biz_id": 3,
"project_id": "3e11f4212ca2444d92a869c26fcbd4a9",
"collector_config_name": "bcs_create1",
"collector_config_name_en": "bcs_create1",
Expand Down Expand Up @@ -60,7 +61,7 @@
PATH_STD_RESULT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [
Expand Down Expand Up @@ -106,7 +107,7 @@
}

PATH_PARAMS = {
"bk_biz_id": 2,
"bk_biz_id": 3,
"project_id": "3e11f4212ca2444d92a869c26fcbd4a9",
"collector_config_name": "bcs_create1",
"collector_config_name_en": "bcs_create1",
Expand Down Expand Up @@ -152,7 +153,7 @@
PATH_RESULT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [
Expand Down Expand Up @@ -226,7 +227,7 @@
}

STD_PARAMS = {
"bk_biz_id": 2,
"bk_biz_id": 3,
"project_id": "3e11f4212ca2444d92a869c26fcbd4a9",
"collector_config_name": "bcs_create1",
"collector_config_name_en": "bcs_create1",
Expand Down Expand Up @@ -261,7 +262,7 @@
STD_RESULT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [
Expand Down Expand Up @@ -325,7 +326,7 @@
}

NOT_PATH_STD_PARAMS = {
"bk_biz_id": 2,
"bk_biz_id": 3,
"project_id": "3e11f4212ca2444d92a869c26fcbd4a9",
"collector_config_name": "bcs_create1",
"collector_config_name_en": "bcs_create1",
Expand All @@ -348,7 +349,7 @@
NOT_PATH_STD_RESULT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [],
Expand All @@ -365,7 +366,7 @@
}

PARAMS = {
"bk_biz_id": 2,
"bk_biz_id": 3,
"project_id": "3e11f4212ca2444d92a869c26fcbd4a9",
"collector_config_name": "bcs_create1",
"collector_config_name_en": "bcs_create1",
Expand Down Expand Up @@ -426,7 +427,7 @@
MULTIPLE_RESULT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [
Expand Down Expand Up @@ -530,7 +531,7 @@
RESULT_DICT = {
"add_pod_label": False,
"bcs_cluster_id": "BCS-K8S-15641",
"bk_biz_id": 2,
"bk_biz_id": 3,
"collector_config_name": "create1",
"collector_config_name_en": "bcs_create1",
"container_config": [
Expand Down Expand Up @@ -657,7 +658,7 @@
"cluster_name": "es7_cluster",
"version": "7.2",
"custom_option": {
"bk_biz_id": 2,
"bk_biz_id": 3,
"hot_warm_config": {
"is_enabled": False,
"hot_attr_name": "",
Expand Down Expand Up @@ -731,53 +732,8 @@ def setUp(self, mock_bk_data_id, *args, **kwargs):
}
)

@patch("apps.api.TransferApi.get_result_table", lambda _: {})
@patch("apps.api.TransferApi.create_result_table", lambda _: {"table_id": "TABLE_ID"})
def test_bcs_collector(self, *args, **kwargs):
rule_id = RESULT_DICT["rule_id"]
update_path = f"/api/v1/databus/collectors/{rule_id}/update_bcs_collector/"
list_params = {"bk_biz_id": PARAMS["bk_biz_id"], "bcs_cluster_id": PARAMS["bcs_cluster_id"]}
list_path = f"/api/v1/databus/collectors/list_bcs_collector/"

# 验证create的结果
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], RESULT_DICT)

# update-> path+std
self.client.post(path=update_path, data=json.dumps(PATH_STD_PARAMS), content_type="application/json")
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], PATH_STD_RESULT)

# update-> 多条path
self.client.post(path=update_path, data=json.dumps(PATH_PARAMS), content_type="application/json")
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], PATH_RESULT)

# update-> 多条std
self.client.post(path=update_path, data=json.dumps(STD_PARAMS), content_type="application/json")
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], STD_RESULT)

# update-> path和std都不存在的情况
self.client.post(path=update_path, data=json.dumps(NOT_PATH_STD_PARAMS), content_type="application/json")
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], NOT_PATH_STD_RESULT)

# update-> path+std, path, std
self.client.post(path=update_path, data=json.dumps(PARAMS), content_type="application/json")
response = self.client.get(path=list_path, data=list_params)
content = json.loads(response.content)
self.assertEqual(content["data"][0], MULTIPLE_RESULT)
def test_login_demo(self, *args, **kwargs):
self.assertEqual(1, 1)

@patch("apps.api.TransferApi.modify_data_id", lambda _: _)
def test_delete_bcs_collector(self, *args, **kwargs):
rule_id = RESULT_DICT["rule_id"]
path = f"/api/v1/databus/collectors/{rule_id}/delete_bcs_collector/"
response = self.client.delete(path=path)
content = json.loads(response.content)
self.assertEqual(content["result"], True)
# def test_update_bcs_collector(self, *args, **kwargs):
# pass
Loading