From 0640ea74307fa0d1198bb5f4988f75f50f9a118c Mon Sep 17 00:00:00 2001 From: durant <826035498@qq.com> Date: Sat, 28 Oct 2023 10:33:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E8=BD=AE=E5=80=BC=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=A4=84=E7=90=86=20#1553?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_monitor/models/alarm.py | 5 +++++ dbm-ui/backend/db_monitor/views/duty_rule.py | 10 ++++++++++ dbm-ui/backend/db_monitor/views/notice_group.py | 5 +++-- helm-charts/bk-dbm/charts/dbm/Chart.yaml | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dbm-ui/backend/db_monitor/models/alarm.py b/dbm-ui/backend/db_monitor/models/alarm.py index 2114d4dd74..7c9a976740 100644 --- a/dbm-ui/backend/db_monitor/models/alarm.py +++ b/dbm-ui/backend/db_monitor/models/alarm.py @@ -15,6 +15,7 @@ from collections import defaultdict from django.db import models +from django.db.models import Count from django.utils.translation import gettext_lazy as _ from backend import env @@ -294,6 +295,10 @@ def delete(self, using=None, keep_parents=False): BKMonitorV3Api.delete_duty_rules({"ids": [self.monitor_duty_rule_id], "bk_biz_ids": [env.DBA_APP_BK_BIZ_ID]}) super().delete() + @classmethod + def priority_distinct(cls) -> list: + return list(cls.objects.values_list("priority", flat=True).distinct().order_by("-priority")) + class Meta: verbose_name_plural = verbose_name = _("轮值规则") diff --git a/dbm-ui/backend/db_monitor/views/duty_rule.py b/dbm-ui/backend/db_monitor/views/duty_rule.py index 8893a29850..eb1c6c0bb7 100644 --- a/dbm-ui/backend/db_monitor/views/duty_rule.py +++ b/dbm-ui/backend/db_monitor/views/duty_rule.py @@ -8,10 +8,14 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ +from django.db.models import Count from django.utils.decorators import method_decorator from django.utils.translation import ugettext_lazy as _ +from rest_framework.decorators import action +from rest_framework.response import Response from backend.bk_web import viewsets +from backend.bk_web.pagination import AuditedLimitOffsetPagination from backend.bk_web.swagger import common_swagger_auto_schema from backend.db_monitor import serializers from backend.db_monitor.models.alarm import DutyRule @@ -58,7 +62,13 @@ class MonitorDutyRuleViewSet(viewsets.AuditedModelViewSet): queryset = DutyRule.objects.all() serializer_class = DutyRuleSerializer + pagination_class = AuditedLimitOffsetPagination filter_fields = {"db_type": ["exact"]} def _get_custom_permissions(self): return [GlobalManageIAMPermission()] + + @common_swagger_auto_schema(operation_summary=_("轮值规则优先级统计"), tags=[SWAGGER_TAG]) + @action(methods=["GET"], detail=False) + def priority_distinct(self, request, *args, **kwargs): + return Response(DutyRule.priority_distinct()) diff --git a/dbm-ui/backend/db_monitor/views/notice_group.py b/dbm-ui/backend/db_monitor/views/notice_group.py index e6491bad28..d017947719 100644 --- a/dbm-ui/backend/db_monitor/views/notice_group.py +++ b/dbm-ui/backend/db_monitor/views/notice_group.py @@ -14,13 +14,13 @@ from django.db.models import Q from django.utils.decorators import method_decorator from django.utils.translation import ugettext_lazy as _ -from rest_framework import status from rest_framework.decorators import action from rest_framework.response import Response from backend.bk_web import viewsets +from backend.bk_web.pagination import AuditedLimitOffsetPagination from backend.bk_web.swagger import common_swagger_auto_schema -from backend.components import CCApi, CmsiApi +from backend.components import CmsiApi from backend.configuration.constants import PLAT_BIZ_ID from backend.db_monitor import serializers from backend.db_monitor.models import MonitorPolicy, NoticeGroup @@ -83,6 +83,7 @@ class MonitorNoticeGroupViewSet(viewsets.AuditedModelViewSet): queryset = NoticeGroup.objects.all() serializer_class = NoticeGroupSerializer + pagination_class = AuditedLimitOffsetPagination filter_class = MonitorPolicyListFilter def _get_custom_permissions(self): diff --git a/helm-charts/bk-dbm/charts/dbm/Chart.yaml b/helm-charts/bk-dbm/charts/dbm/Chart.yaml index 586fc43248..04df5d1bd6 100644 --- a/helm-charts/bk-dbm/charts/dbm/Chart.yaml +++ b/helm-charts/bk-dbm/charts/dbm/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -appVersion: 1.2.0-alpha.412 +appVersion: 1.2.0-alpha.418 description: A Helm chart for dbm name: dbm type: application