Skip to content

Commit

Permalink
fix: profile文件上传过滤掉过期文件 --bug=135477789 (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxwycdh authored Jan 21, 2025
1 parent 9b4504a commit 5f736a8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bkmonitor/packages/apm_web/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.
"""
import datetime
import functools
import gzip
import hashlib
Expand Down Expand Up @@ -100,9 +101,6 @@ def upload(self, request: Request):

data = uploaded.read()
md5 = hashlib.md5(data).hexdigest()
exist_record = ProfileUploadRecord.objects.filter(bk_biz_id=validated_data["bk_biz_id"], file_md5=md5).first()
if exist_record:
raise ValueError(_(f"已上传过相同文件,名称:{exist_record.file_name}({exist_record.origin_file_name})"))

# 上传文件到 bkrepo, 上传文件失败,不记录,不执行异步任务
try:
Expand Down Expand Up @@ -155,9 +153,13 @@ def records(self, request: Request):
filter_params["app_name"] = validated_data.get("app_name")
if validated_data.get("origin_file_name"):
filter_params["origin_file_name"] = validated_data.get("origin_file_name")
if validated_data.get("service_name "):
if validated_data.get("service_name"):
filter_params["service_name"] = validated_data.get("service_name")
queryset = ProfileUploadRecord.objects.filter(**filter_params)

# 过滤掉过期的文件 (过期文件在 bkbase 中已查不到不需要显示)
datasource = api.apm_api.query_builtin_profile_datasource()
last_retention = datetime.datetime.now() - datetime.timedelta(days=datasource["retention"])
queryset = ProfileUploadRecord.objects.filter(**filter_params, uploaded_time__gte=last_retention)
return Response(data=ProfileUploadRecordSLZ(queryset, many=True).data)


Expand Down

0 comments on commit 5f736a8

Please sign in to comment.