Skip to content

Commit

Permalink
feat: 支持更新存储凭据最大缓存大小 #1919
Browse files Browse the repository at this point in the history
* feat: 修复缓存索引淘汰任务配置类错误 #1919

* feat: 支持更新存储凭据最大缓存大小 #1919

* feat: 支持更新存储凭据最大缓存大小 #1919
  • Loading branch information
cnlkl authored Mar 21, 2024
1 parent c0d9226 commit a83fd0f
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.tencent.bkrepo.common.storage.core.StorageProperties
import com.tencent.bkrepo.common.storage.core.cache.indexer.StorageCacheIndexerManager
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.job.config.properties.StorageCacheIndexEvictJobProperties
import com.tencent.bkrepo.job.config.properties.StorageCacheIndexSyncJobProperties
import org.springframework.beans.factory.ObjectProvider
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.data.mongodb.core.MongoTemplate
Expand All @@ -45,7 +44,7 @@ import org.springframework.stereotype.Component
@Component
@EnableConfigurationProperties(StorageCacheIndexEvictJobProperties::class)
class StorageCacheIndexEvictJob(
properties: StorageCacheIndexSyncJobProperties,
properties: StorageCacheIndexEvictJobProperties,
storageProperties: StorageProperties,
clusterProperties: ClusterProperties,
mongoTemplate: MongoTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import com.tencent.bkrepo.common.storage.core.cache.indexer.StorageCacheIndexerM
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.job.batch.base.DefaultContextJob
import com.tencent.bkrepo.job.batch.base.JobContext
import com.tencent.bkrepo.job.config.properties.StorageCacheIndexSyncJobProperties
import com.tencent.bkrepo.job.config.properties.StorageCacheIndexJobProperties
import org.springframework.beans.factory.ObjectProvider
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.Query
import java.time.Duration

abstract class StorageCacheIndexJob(
private val properties: StorageCacheIndexSyncJobProperties,
private val properties: StorageCacheIndexJobProperties,
private val storageProperties: StorageProperties,
private val clusterProperties: ClusterProperties,
private val mongoTemplate: MongoTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties("job.storage-cache-index-evict")
class StorageCacheIndexEvictJobProperties(
override var enabled: Boolean = false,
override var cron: String = "0 0/10 * * * ?",
/**
* 忽略的存储凭据,这些存储的缓存将不执行索引同步
*/
var ignoredStorageCredentialsKeys: Set<String> = emptySet(),
) : BatchJobProperties()
) : StorageCacheIndexJobProperties()
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.job.config.properties

/**
* 存储缓存索引相关任务配置
*/
open class StorageCacheIndexJobProperties(
override var enabled: Boolean = false,
/**
* 忽略的存储凭据
*/
var ignoredStorageCredentialsKeys: Set<String> = emptySet(),
) : BatchJobProperties()
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties("job.storage-cache-index-sync")
class StorageCacheIndexSyncJobProperties(
override var enabled: Boolean = false,
override var cron: String = "0 0 6 * * ?",
/**
* 忽略的存储凭据,这些存储的缓存将不执行索引同步
*/
var ignoredStorageCredentialsKeys: Set<String> = emptySet(),
) : BatchJobProperties()
) : StorageCacheIndexJobProperties()
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class StorageCredentialServiceImpl(
cache = cache.copy(
loadCacheFirst = request.credentials.cache.loadCacheFirst,
expireDays = request.credentials.cache.expireDays,
expireDuration = request.credentials.cache.expireDuration
expireDuration = request.credentials.cache.expireDuration,
maxSize = request.credentials.cache.maxSize,
)
upload = upload.copy(localPath = request.credentials.upload.localPath)
compress = compress.copy(
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/devops-op/src/api/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function updateCredential(key, credential, defaultCredential = false) {
const expireDaysKey = `${prefix}.${STORAGE_CACHE_CONFIG_PREFIX}.expireDays`
const expireDurationKey = `${prefix}.${STORAGE_CACHE_CONFIG_PREFIX}.expireDuration`
const loadCacheFirstKey = `${prefix}.${STORAGE_CACHE_CONFIG_PREFIX}.loadCacheFirst`
const cacheMaxSizeKey = `${prefix}.${STORAGE_CACHE_CONFIG_PREFIX}.maxSize`
const values = [
{
'key': expireDaysKey,
Expand All @@ -55,6 +56,10 @@ export function updateCredential(key, credential, defaultCredential = false) {
'key': expireDurationKey,
'value': credential.cache.expireDuration * 1000 // consul上Duration不带单位时默认是毫秒
},
{
'key': cacheMaxSizeKey,
'value': credential.cache.maxSize
},
{
'key': loadCacheFirstKey,
'value': credential.cache.loadCacheFirst
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/devops-op/src/views/storage/Credential.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<span>{{ formatSeconds(scope.row.cache.expireDuration) }}</span>
</template>
</el-table-column>
<el-table-column label="最大缓存大小" width="180">
<template v-if="scope.row.cache.enabled" slot-scope="scope">
<span>{{ maxSize(scope.row.cache.maxSize) }}</span>
</template>
</el-table-column>
<el-table-column
label="优先读缓存"
width="180"
Expand Down Expand Up @@ -82,6 +87,7 @@
<script>
import { credentials, defaultCredential, deleteCredential } from '@/api/storage'
import CreateOrUpdateCredentialDialog from '@/views/storage/components/CreateOrUpdateCredentialDialog'
import { convertFileSize } from '@/utils/file'
export default {
name: 'Credential',
Expand Down Expand Up @@ -151,6 +157,9 @@ export default {
expireDays(expireDays) {
return parseInt(expireDays) <= 0 ? '永久' : expireDays
},
maxSize(maxSize) {
return maxSize <= 0 ? '无限制' : convertFileSize(maxSize)
},
formatSeconds(seconds) {
if (seconds <= 0) {
return '永久'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<el-form-item v-if="credential.cache.enabled" label="缓存时间(秒)" prop="cache.expireDuration">
<el-input-number v-model="credential.cache.expireDuration" controls-position="right" :min="0" />
</el-form-item>
<el-form-item v-if="credential.cache.enabled" label="最大缓存大小(Byte)" prop="cache.maxSize">
<el-input-number v-model="credential.cache.maxSize" controls-position="right" :min="0" />
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="close">取 消</el-button>
Expand Down

0 comments on commit a83fd0f

Please sign in to comment.