Skip to content

Commit

Permalink
feat: 检索过滤交互优化灰度开关验证 - 按用户支持灰度需求 #1010158081119856279
Browse files Browse the repository at this point in the history
  • Loading branch information
zzz833708 committed Sep 25, 2024
1 parent 84991f3 commit 59b0948
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bklog/apps/log_search/views/meta_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def get_index_settings(self, request):
"""
my_setting = copy.copy(mysetting(request))
[my_setting.pop(key) for key in FILTER_KEY_LIST]
data = get_toggle_data()
data = get_toggle_data(request)
return Response({**my_setting, **data})

@list_route(methods=["GET"], url_path="projects/mine")
Expand Down
11 changes: 10 additions & 1 deletion bklog/apps/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def array_chunk(data, size=100):
return [data[i : i + size] for i in range(0, len(data), size)]


def get_toggle_data():
def get_toggle_data(request):
toggle_list = FeatureToggleObject.toggle_list(**{"is_viewed": True})
field_analysis_config, __ = FeatureToggle.objects.get_or_create(
name=FIELD_ANALYSIS_CONFIG,
Expand All @@ -107,6 +107,15 @@ def get_toggle_data():
"biz_id_white_list": [],
},
)
# 获取用户名
username = request.user.username
for toggle in toggle_list:
config = toggle.feature_config
if isinstance(config, dict):
# 获取用户白名单
user_list = config.get("user_white_list", [])
if username in user_list:
toggle.status = "on"
data = {
# 实时日志最大长度
"REAL_TIME_LOG_MAX_LENGTH": "20000",
Expand Down
7 changes: 4 additions & 3 deletions bklog/home_application/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"""


from blueapps.account.decorators import login_exempt
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _
from blueapps.account.decorators import login_exempt

# 开发框架中通过中间件默认是需要登录态的,如有不需要登录的,可添加装饰器login_exempt
# 装饰器引入 from blueapps.account.decorators import login_exempt
Expand All @@ -38,7 +38,7 @@ def home(request):
"""
首页
"""
return render(request, settings.VUE_INDEX, get_toggle_data())
return render(request, settings.VUE_INDEX, get_toggle_data(request))


def bkdata_auth(request):
Expand Down Expand Up @@ -93,6 +93,7 @@ def healthz(request):
@login_exempt
def metrics(request):
from django_prometheus import exports

from settings import PROMETHEUS_METRICS_TOKEN

token = request.GET.get("token")
Expand Down
2 changes: 1 addition & 1 deletion bklog/log_adapter/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def external(request):
setattr(request, "COOKIES", {k: v for k, v in request.COOKIES.items() if k != "bk_token"})
else:
logger.error(f"外部用户({external_user})或空间(ID:{space_uid})不存在, request.META: {request.META}")
response = render(request, settings.VUE_INDEX, get_toggle_data())
response = render(request, settings.VUE_INDEX, get_toggle_data(request))
response.set_cookie("space_uid", space_uid)
response.set_cookie("external_user", external_user)
return response
Expand Down

0 comments on commit 59b0948

Please sign in to comment.