From 9c5e83bfb6dba919400b15fe688e3b69474022db Mon Sep 17 00:00:00 2001 From: felixncheng Date: Wed, 24 Jul 2024 17:30:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7devops=20framework?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E5=88=B00.0.9=20#2387?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 升级devops framework框架到0.0.9 #2387 * feat: 处理循环依赖 #2387 * feat: 修改devops framework版本为0.0.9 #2387 * feat: 修改devops framework版本为0.0.9 #2387 * feat: 修改devops framework版本为0.0.9 #2387 * feat: 修改devops framework版本为0.0.9 #2387 --- .../bkrepo/analyst/metrics/ScannerMetrics.kt | 4 +- .../subtask/action/CreateSubtaskAction.kt | 2 + .../subtask/action/ReuseResultAction.kt | 2 + .../archive/core/archive/ArchiveManager.kt | 11 +- .../archive/core/compress/BDZipManager.kt | 17 ++- .../bkrepo/archive/metrics/ArchiveMetrics.kt | 32 ++++- src/backend/build.gradle.kts | 11 +- .../buildSrc/src/main/kotlin/Versions.kt | 7 +- .../TransmittableInheritableThreadLocal.kt | 2 +- .../api/thread/TransmittableThreadLocal.kt | 2 +- .../artifact/metrics/ArtifactMetrics.kt | 8 +- .../service/ServiceAutoConfiguration.kt | 2 - .../feign/CustomFeignClientsConfiguration.kt | 8 +- .../otel/mongodb/OtelMongoConfiguration.kt | 10 -- .../otel/mongodb/TraceCommandListener.kt | 130 ------------------ ...aceMongoClientSettingsBuilderCustomizer.kt | 42 ------ .../resource/OtelResourceConfiguration.kt | 50 ------- .../otel/resource/OtelResourceProperties.kt | 35 ----- .../otel/resource/OtelResourceProvider.kt | 50 ------- .../main/resources/bootstrap-ut.properties | 1 + .../test/resources/bootstrap-ut.properties | 1 + .../tencent/bkrepo/job/metrics/JobMetrics.kt | 3 +- .../migrate/MigrateFailedNodeServiceTest.kt | 2 + .../migrate/MigrateRepoStorageServiceTest.kt | 19 ++- .../job/migrate/executor/ExecutorBaseTest.kt | 2 + .../FileNotFoundAutoFixStrategyTest.kt | 2 + .../job/migrate/utils/NodeIteratorTest.kt | 2 + .../service/impl/ArchiveJobServiceImplTest.kt | 2 + .../test/resources/bootstrap-ut.properties | 3 +- .../images/backend/backend.Dockerfile | 2 +- .../kubernetes/images/backend/startup.sh | 1 + 31 files changed, 100 insertions(+), 365 deletions(-) delete mode 100644 src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceCommandListener.kt delete mode 100644 src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceMongoClientSettingsBuilderCustomizer.kt delete mode 100644 src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceConfiguration.kt delete mode 100644 src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProperties.kt delete mode 100644 src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProvider.kt diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/metrics/ScannerMetrics.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/metrics/ScannerMetrics.kt index 05db3e4e1b..40f40bdfe8 100644 --- a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/metrics/ScannerMetrics.kt +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/metrics/ScannerMetrics.kt @@ -49,13 +49,14 @@ import java.util.concurrent.ConcurrentHashMap @Component @Suppress("TooManyFunctions") class ScannerMetrics( - private val meterRegistry: MeterRegistry, private val scannerProperties: ScannerProperties, @Qualifier(SCAN_TASK_SCHEDULER_THREAD_POOL_BEAN_NAME) private val scanTaskSchedulerThreadPool: ThreadPoolTaskExecutor, private val distributedCountFactory: DistributedCountFactory ) : MeterBinder { + private lateinit var meterRegistry: MeterRegistry + /** * 记录各状态任务数量的Map,key为状态,value为任务数量 */ @@ -83,6 +84,7 @@ class ScannerMetrics( } override fun bindTo(registry: MeterRegistry) { + this.meterRegistry = registry taskGauge( scanTaskSchedulerThreadPool, { threadPoolExecutor.queue.size.toDouble() }, diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/CreateSubtaskAction.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/CreateSubtaskAction.kt index ebccae9e40..395d00141a 100644 --- a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/CreateSubtaskAction.kt +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/CreateSubtaskAction.kt @@ -48,6 +48,7 @@ import com.tencent.bkrepo.statemachine.TransitResult import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationEventPublisher +import org.springframework.context.annotation.Lazy import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @@ -63,6 +64,7 @@ class CreateSubtaskAction( ) : SubtaskAction { @Autowired + @Lazy private lateinit var self: CreateSubtaskAction override fun execute(source: String, target: String, event: Event): TransitResult { diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/ReuseResultAction.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/ReuseResultAction.kt index 89012e536c..52d2722008 100644 --- a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/ReuseResultAction.kt +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/ReuseResultAction.kt @@ -46,6 +46,7 @@ import com.tencent.bkrepo.statemachine.Event import com.tencent.bkrepo.statemachine.TransitResult import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationEventPublisher +import org.springframework.context.annotation.Lazy import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @@ -62,6 +63,7 @@ class ReuseResultAction( private val publisher: ApplicationEventPublisher ) : SubtaskAction { @Autowired + @Lazy private lateinit var self: ReuseResultAction override fun execute(source: String, target: String, event: Event): TransitResult { diff --git a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/archive/ArchiveManager.kt b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/archive/ArchiveManager.kt index 5eebe2b77b..2cd61c9812 100644 --- a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/archive/ArchiveManager.kt +++ b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/archive/ArchiveManager.kt @@ -23,6 +23,8 @@ import com.tencent.bkrepo.common.storage.monitor.Throughput import com.tencent.bkrepo.common.storage.monitor.measureThroughput import org.apache.tika.Tika import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Component import reactor.core.publisher.Mono import reactor.core.scheduler.Schedulers @@ -37,10 +39,15 @@ import java.util.function.Function class ArchiveManager( private val archiveProperties: ArchiveProperties, private val fileProvider: PriorityFileProvider, - private val archiveFileDao: ArchiveFileDao, - private val archiveFileRepository: ArchiveFileRepository, private val storageService: StorageService, ) : Function> { + @Autowired + @Lazy + private lateinit var archiveFileDao: ArchiveFileDao + + @Autowired + @Lazy + private lateinit var archiveFileRepository: ArchiveFileRepository private val tika = Tika() private val compressPool = ArchiveUtils.newFixedAndCachedThreadPool( diff --git a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/compress/BDZipManager.kt b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/compress/BDZipManager.kt index d1007a702e..55f29c148b 100644 --- a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/compress/BDZipManager.kt +++ b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/core/compress/BDZipManager.kt @@ -23,6 +23,8 @@ import com.tencent.bkrepo.common.storage.monitor.Throughput import com.tencent.bkrepo.common.storage.util.toPath import com.tencent.bkrepo.repository.api.FileReferenceClient import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Component import reactor.core.publisher.Mono import reactor.core.publisher.MonoSink @@ -39,13 +41,22 @@ import java.util.function.Function * */ @Component class BDZipManager( - private val compressFileDao: CompressFileDao, private val archiveProperties: ArchiveProperties, - private val fileReferenceClient: FileReferenceClient, - private val compressFileRepository: CompressFileRepository, private val storageService: StorageService, private val fileProvider: PriorityFileProvider, ) : Function> { + @Autowired + @Lazy + private lateinit var compressFileDao: CompressFileDao + + @Autowired + @Lazy + private lateinit var fileReferenceClient: FileReferenceClient + + @Autowired + @Lazy + private lateinit var compressFileRepository: CompressFileRepository + private val workDir = archiveProperties.gc.path.toPath() val workThreadPool = ArchiveUtils.newFixedAndCachedThreadPool( diff --git a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/metrics/ArchiveMetrics.kt b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/metrics/ArchiveMetrics.kt index 19c2f73ffe..5789abb7fd 100644 --- a/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/metrics/ArchiveMetrics.kt +++ b/src/backend/archive/biz-archive/src/main/kotlin/com/tencent/bkrepo/archive/metrics/ArchiveMetrics.kt @@ -17,6 +17,8 @@ import io.micrometer.core.instrument.Gauge import io.micrometer.core.instrument.MeterRegistry import io.micrometer.core.instrument.Timer import io.micrometer.core.instrument.binder.MeterBinder +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Lazy import org.springframework.data.mongodb.core.aggregation.Aggregation import org.springframework.data.mongodb.core.query.isEqualTo import org.springframework.data.mongodb.core.query.where @@ -29,16 +31,34 @@ import java.util.concurrent.TimeUnit * */ @Component class ArchiveMetrics( - val archiveFileRepository: ArchiveFileRepository, - val compressFileRepository: CompressFileRepository, - val bdZipManager: BDZipManager, val fileProvider: PriorityFileProvider, - val archiveManager: ArchiveManager, - private val archiveFileDao: ArchiveFileDao, - private val compressFileDao: CompressFileDao, ) : MeterBinder { lateinit var registry: MeterRegistry + @Autowired + @Lazy + private lateinit var archiveFileRepository: ArchiveFileRepository + + @Autowired + @Lazy + private lateinit var compressFileRepository: CompressFileRepository + + @Autowired + @Lazy + private lateinit var archiveManager: ArchiveManager + + @Autowired + @Lazy + private lateinit var bdZipManager: BDZipManager + + @Autowired + @Lazy + private lateinit var archiveFileDao: ArchiveFileDao + + @Autowired + @Lazy + private lateinit var compressFileDao: CompressFileDao + private var fileArchiveSizeTotal = 0L private var fileCompressSizeTotal = 0L diff --git a/src/backend/build.gradle.kts b/src/backend/build.gradle.kts index 07eab4473e..f4f74cf69a 100644 --- a/src/backend/build.gradle.kts +++ b/src/backend/build.gradle.kts @@ -39,10 +39,6 @@ allprojects { version = (System.getProperty("repo_version") ?: Release.Version) + if (System.getProperty("snapshot") == "true") "-SNAPSHOT" else "-RELEASE" - repositories { - maven(url = "https://repo.spring.io/milestone") - } - apply(plugin = "com.tencent.devops.boot") apply(plugin = "jacoco") @@ -51,6 +47,8 @@ allprojects { imports { mavenBom("org.springframework.cloud:spring-cloud-sleuth-otel-dependencies:${Versions.SleuthOtel}") + // 升级devops boot版本后,stream启动报错。参考https://github.com/spring-cloud/spring-cloud-function/issues/940 + mavenBom("org.springframework.cloud:spring-cloud-function-dependencies:${Versions.SpringCloudFunction}") } dependencies { dependency("com.github.zafarkhaja:java-semver:${Versions.JavaSemver}") @@ -80,13 +78,8 @@ allprojects { dependency("org.apache.tika:tika-core:${Versions.TiKa}") } } - ext["netty.version"] = Versions.Netty - // 2.1.2才支持配置使用信号量隔离 - ext["spring-cloud-circuitbreaker.version"] = Versions.SpringCloudCircuitbreaker configurations.all { - // io.netty:netty已替换成io.netty:netty-all - exclude(group = "io.netty", module = "netty") exclude(group = "log4j", module = "log4j") exclude(group = "org.slf4j", module = "slf4j-log4j12") exclude(group = "commons-logging", module = "commons-logging") diff --git a/src/backend/buildSrc/src/main/kotlin/Versions.kt b/src/backend/buildSrc/src/main/kotlin/Versions.kt index c4bd2d7851..5fbb7de387 100644 --- a/src/backend/buildSrc/src/main/kotlin/Versions.kt +++ b/src/backend/buildSrc/src/main/kotlin/Versions.kt @@ -31,9 +31,7 @@ object Release { } object Versions { - const val DevopsBoot = "0.0.6" - const val Netty = "4.1.77.Final" - const val SpringCloudCircuitbreaker = "2.1.2" + const val DevopsBoot = "0.0.9" const val Jersey = "2.35" const val Jsoup = "1.17.2" const val Redline = "1.2.10" @@ -60,7 +58,7 @@ object Versions { const val DockerJava = "3.2.13" const val Mockk = "1.12.2" const val Swagger = "1.6.2" - const val SleuthOtel = "1.0.0-M13" + const val SleuthOtel = "1.1.4" const val KubernetesClient = "11.0.2" const val ReactiveFeign = "3.2.6" const val Jasypt = "3.0.5" @@ -71,4 +69,5 @@ object Versions { const val FFmpegPlatform = "6.0-1.5.9" const val JavaCpp = "1.5.9" const val Notice = "1.0.0" + const val SpringCloudFunction = "3.2.11" } diff --git a/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableInheritableThreadLocal.kt b/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableInheritableThreadLocal.kt index fc762cd08f..3b09dda37e 100644 --- a/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableInheritableThreadLocal.kt +++ b/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableInheritableThreadLocal.kt @@ -9,7 +9,7 @@ open class TransmittableInheritableThreadLocal : InheritableThreadLocal() override fun set(value: T) { super.set(value) - if (!Transmitter.holder.get().contains(this)) { + if (!Transmitter.holder.get().contains(this as ThreadLocal)) { Transmitter.holder.get().add(this as ThreadLocal) } } diff --git a/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableThreadLocal.kt b/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableThreadLocal.kt index 8c09e5bdb6..5f8458c58f 100644 --- a/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableThreadLocal.kt +++ b/src/backend/common/common-api/src/main/kotlin/com/tencent/bkrepo/common/api/thread/TransmittableThreadLocal.kt @@ -11,7 +11,7 @@ open class TransmittableThreadLocal : ThreadLocal() { override fun set(value: T) { super.set(value) - if (!Transmitter.holder.get().contains(this)) { + if (!Transmitter.holder.get().contains(this as ThreadLocal)) { Transmitter.holder.get().add(this as ThreadLocal) } } diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/metrics/ArtifactMetrics.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/metrics/ArtifactMetrics.kt index 37cbe876e4..ebdd97a575 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/metrics/ArtifactMetrics.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/metrics/ArtifactMetrics.kt @@ -49,7 +49,6 @@ import java.util.concurrent.atomic.AtomicInteger class ArtifactMetrics( private val threadPoolTaskExecutor: ThreadPoolTaskExecutor, tagProvider: ArtifactTransferTagProvider, - meterRegistry: MeterRegistry, properties: ArtifactMetricsProperties ) : MeterBinder { @@ -58,13 +57,14 @@ class ArtifactMetrics( init { Companion.tagProvider = tagProvider - Companion.meterRegistry = meterRegistry Companion.properties = properties - lruMeterFilter = LruMeterFilter(METER_LIMIT_PREFIX, meterRegistry, properties.maxMeters) - meterRegistry.config().meterFilter(lruMeterFilter) + } override fun bindTo(meterRegistry: MeterRegistry) { + Companion.meterRegistry = meterRegistry + lruMeterFilter = LruMeterFilter(METER_LIMIT_PREFIX, Companion.meterRegistry, properties.maxMeters) + Companion.meterRegistry.config().meterFilter(lruMeterFilter) Gauge.builder(ARTIFACT_UPLOADING_COUNT, uploadingCount) { it.get().toDouble() } .description(ARTIFACT_UPLOADING_COUNT_DESC) .register(meterRegistry) diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/ServiceAutoConfiguration.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/ServiceAutoConfiguration.kt index 15ebb5e6fe..9126dd425c 100644 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/ServiceAutoConfiguration.kt +++ b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/ServiceAutoConfiguration.kt @@ -43,7 +43,6 @@ import com.tencent.bkrepo.common.service.log.AccessLogWebServerCustomizer import com.tencent.bkrepo.common.service.message.MessageSourceConfiguration import com.tencent.bkrepo.common.service.metrics.UndertowMetrics import com.tencent.bkrepo.common.service.otel.mongodb.OtelMongoConfiguration -import com.tencent.bkrepo.common.service.otel.resource.OtelResourceConfiguration import com.tencent.bkrepo.common.service.otel.web.OtelWebConfiguration import com.tencent.bkrepo.common.service.shutdown.ServiceShutdownConfiguration import org.springframework.boot.autoconfigure.AutoConfigureOrder @@ -72,7 +71,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert ClusterConfiguration::class, CustomFeignClientsConfiguration::class, OtelMongoConfiguration::class, - OtelResourceConfiguration::class, OtelWebConfiguration::class ) class ServiceAutoConfiguration { diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/feign/CustomFeignClientsConfiguration.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/feign/CustomFeignClientsConfiguration.kt index 48b26f097b..b1e269b4e8 100644 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/feign/CustomFeignClientsConfiguration.kt +++ b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/feign/CustomFeignClientsConfiguration.kt @@ -31,20 +31,14 @@ import com.tencent.bkrepo.common.api.constant.COMMIT_EDGE_HEADER import com.tencent.bkrepo.common.api.constant.HttpHeaders import com.tencent.bkrepo.common.service.util.HttpContextHolder import feign.RequestInterceptor -import org.springframework.boot.autoconfigure.AutoConfigureAfter -import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JAutoConfiguration import org.springframework.cloud.openfeign.FeignClientsConfiguration import org.springframework.context.annotation.Configuration import org.springframework.boot.autoconfigure.condition.ConditionalOnClass import org.springframework.context.annotation.Bean -/** - * 需要配置FeignClientsConfiguration在Resilience4JAutoConfiguration之后配置feign才会使用resilience4j进行熔断隔离 - */ @Configuration @ConditionalOnClass(FeignClientsConfiguration::class) -@AutoConfigureAfter(Resilience4JAutoConfiguration::class) -class CustomFeignClientsConfiguration : FeignClientsConfiguration() { +class CustomFeignClientsConfiguration { @Bean fun requestInterceptor(): RequestInterceptor { return RequestInterceptor { requestTemplate -> diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/OtelMongoConfiguration.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/OtelMongoConfiguration.kt index bdc65aa629..ba68822734 100644 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/OtelMongoConfiguration.kt +++ b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/OtelMongoConfiguration.kt @@ -28,10 +28,8 @@ package com.tencent.bkrepo.common.service.otel.mongodb import com.mongodb.client.internal.MongoClientImpl -import org.springframework.beans.factory.ObjectProvider import org.springframework.boot.autoconfigure.condition.ConditionalOnClass import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.cloud.sleuth.Tracer import org.springframework.cloud.sleuth.otel.bridge.OtelTracer import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -41,14 +39,6 @@ import org.springframework.context.annotation.Configuration @ConditionalOnClass(OtelTracer::class, MongoClientImpl::class) class OtelMongoConfiguration { - @Bean - fun traceMongoClientSettingsBuilderCustomizer( - tracer: Tracer, - customizers: ObjectProvider> - ): TraceMongoClientSettingsBuilderCustomizer { - return TraceMongoClientSettingsBuilderCustomizer(tracer, customizers.ifAvailable.orEmpty()) - } - @Bean fun dbMongoSpanCustomizer(): TraceMongoSpanCustomizer { return DBMongoSpanCustomizer() diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceCommandListener.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceCommandListener.kt deleted file mode 100644 index 24bf4ac6fe..0000000000 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceCommandListener.kt +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.common.service.otel.mongodb - -import com.mongodb.event.CommandFailedEvent -import com.mongodb.event.CommandListener -import com.mongodb.event.CommandStartedEvent -import com.mongodb.event.CommandSucceededEvent -import org.bson.BsonDocument -import org.bson.BsonValue -import org.springframework.cloud.sleuth.Span -import org.springframework.cloud.sleuth.Tracer -import java.util.concurrent.ConcurrentHashMap -import java.util.function.Consumer - -class TraceCommandListener( - private val tracer: Tracer, - private val customizers: List -) : CommandListener { - - private val requestContext = ConcurrentHashMap() - - override fun commandStarted(event: CommandStartedEvent) { - val databaseName = event.databaseName - if ("admin" == databaseName) { - return - } - - val parent = tracer.currentSpan() - if (parent == null) { - return - } - val childSpanBuilder = tracer.spanBuilder() - childSpanBuilder.setParent(parent.context()) - - val commandName = event.commandName - val command = event.command - val collectionName = getCollectionName(command, commandName) - - childSpanBuilder.name(getSpanName(commandName, collectionName)) - .kind(Span.Kind.CLIENT) - - if (collectionName != null) { - childSpanBuilder.tag("db.mongodb.collection", collectionName) - } - - customizers.forEach(Consumer { customizer: TraceMongoSpanCustomizer -> - customizer.customizeCommandStartSpan( - event, - childSpanBuilder - ) - }) - - val childSpan = childSpanBuilder.start() - requestContext[event.requestId] = childSpan - } - - override fun commandSucceeded(event: CommandSucceededEvent) { - val span = requestContext[event.requestId] ?: return - span.end() - requestContext.remove(event.requestId) - } - - override fun commandFailed(event: CommandFailedEvent) { - val span = requestContext[event.requestId] ?: return - span.error(event.throwable) - span.end() - requestContext.remove(event.requestId) - } - - private fun getCollectionName(command: BsonDocument, commandName: String): String? { - if (COMMANDS_WITH_COLLECTION_NAME.contains(commandName)) { - val collectionName = getNonEmptyBsonString(command[commandName]) - if (collectionName != null) { - return collectionName - } - } - // 其他的一些命令,例如getMore,包含字段 {"collection": collectionName} - return getNonEmptyBsonString(command["collection"]) - } - - private fun getNonEmptyBsonString(bsonValue: BsonValue?): String? { - if (bsonValue == null || !bsonValue.isString) { - return null - } - val stringValue = bsonValue.asString().value.trim { it <= ' ' } - return stringValue.ifEmpty { null } - } - - private fun getSpanName(commandName: String, collectionName: String?): String { - return if (collectionName == null) { - commandName - } else { - "$collectionName.$commandName" - } - } - - companion object { - val COMMANDS_WITH_COLLECTION_NAME = setOf( - "aggregate", "count", "distinct", "mapReduce", "geoSearch", "delete", "find", "findAndModify", - "insert", "update", "collMod", "compact", "convertToCapped", "create", "createIndexes", "drop", - "dropIndexes", "killCursors", "listIndexes", "reIndex" - ) - } -} diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceMongoClientSettingsBuilderCustomizer.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceMongoClientSettingsBuilderCustomizer.kt deleted file mode 100644 index de91a38fc7..0000000000 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/mongodb/TraceMongoClientSettingsBuilderCustomizer.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.common.service.otel.mongodb - -import com.mongodb.MongoClientSettings -import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer -import org.springframework.cloud.sleuth.Tracer - -class TraceMongoClientSettingsBuilderCustomizer( - private val tracer: Tracer, - private val customizers: List -): MongoClientSettingsBuilderCustomizer { - - override fun customize(clientSettingsBuilder: MongoClientSettings.Builder) { - clientSettingsBuilder.addCommandListener(TraceCommandListener(tracer, customizers)) - } -} diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceConfiguration.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceConfiguration.kt deleted file mode 100644 index e007d5cfbd..0000000000 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceConfiguration.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.common.service.otel.resource - -import io.opentelemetry.sdk.resources.Resource -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.cloud.sleuth.otel.bridge.OtelTracer -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import java.util.function.Supplier - -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(OtelResourceProperties::class) -@ConditionalOnProperty(value = ["spring.sleuth.enabled"], matchIfMissing = true) -@ConditionalOnClass(OtelTracer::class) -class OtelResourceConfiguration { - - @Bean - fun otelResourceProvider(properties: OtelResourceProperties): Supplier { - return OtelResourceProvider(properties).provide() - } - -} diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProperties.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProperties.kt deleted file mode 100644 index 27260a53b7..0000000000 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProperties.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.common.service.otel.resource - -import org.springframework.boot.context.properties.ConfigurationProperties - -@ConfigurationProperties("spring.sleuth.otel.resource") -data class OtelResourceProperties ( - var attributes: Map = mapOf() -) diff --git a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProvider.kt b/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProvider.kt deleted file mode 100644 index d7fc3f8cc6..0000000000 --- a/src/backend/common/common-service/src/main/kotlin/com/tencent/bkrepo/common/service/otel/resource/OtelResourceProvider.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.common.service.otel.resource - -import io.opentelemetry.api.common.Attributes -import io.opentelemetry.sdk.resources.Resource -import java.util.function.Supplier - -/** - * Otel自定义资源配置 - */ -class OtelResourceProvider( - private val properties: OtelResourceProperties -) { - - fun provide(): Supplier { - val attributesBuilder = Attributes.builder() - properties.attributes.forEach(attributesBuilder::put) - return Supplier { - Resource.create( - attributesBuilder.build() - ) - } - } -} diff --git a/src/backend/common/common-service/src/main/resources/bootstrap-ut.properties b/src/backend/common/common-service/src/main/resources/bootstrap-ut.properties index 4f1c277133..86716d46c6 100644 --- a/src/backend/common/common-service/src/main/resources/bootstrap-ut.properties +++ b/src/backend/common/common-service/src/main/resources/bootstrap-ut.properties @@ -31,5 +31,6 @@ spring.cloud.consul.enabled=false spring.main.lazy-initialization=true +spring.mongodb.embedded.version=4.0.2 sharding.count=1 diff --git a/src/backend/fs/boot-fs-server/src/test/resources/bootstrap-ut.properties b/src/backend/fs/boot-fs-server/src/test/resources/bootstrap-ut.properties index 4f1c277133..86716d46c6 100644 --- a/src/backend/fs/boot-fs-server/src/test/resources/bootstrap-ut.properties +++ b/src/backend/fs/boot-fs-server/src/test/resources/bootstrap-ut.properties @@ -31,5 +31,6 @@ spring.cloud.consul.enabled=false spring.main.lazy-initialization=true +spring.mongodb.embedded.version=4.0.2 sharding.count=1 diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/metrics/JobMetrics.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/metrics/JobMetrics.kt index 902d7f9c5c..affdf27b3d 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/metrics/JobMetrics.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/metrics/JobMetrics.kt @@ -53,10 +53,11 @@ import org.springframework.stereotype.Component @Component class JobMetrics( val threadPoolTaskExecutor: BlockThreadPoolTaskExecutorDecorator, - private val registry: MeterRegistry ) : MeterBinder { + private lateinit var registry: MeterRegistry override fun bindTo(registry: MeterRegistry) { + this.registry = registry Gauge.builder(JOB_ASYNC_TASK_ACTIVE_COUNT, threadPoolTaskExecutor) { it.activeCount().toDouble() } .description(JOB_ASYNC_TASK_ACTIVE_COUNT_DESC) .register(registry) diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateFailedNodeServiceTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateFailedNodeServiceTest.kt index 313dcea7b1..0ff509cc44 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateFailedNodeServiceTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateFailedNodeServiceTest.kt @@ -28,6 +28,7 @@ import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Update import org.springframework.data.mongodb.core.query.isEqualTo +import org.springframework.test.context.TestPropertySource import java.time.LocalDateTime @DisplayName("迁移失败节点服务测试") @@ -39,6 +40,7 @@ import java.time.LocalDateTime MigrateRepoStorageTaskDao::class, MigrateFailedNodeFixer::class, ) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) class MigrateFailedNodeServiceTest @Autowired constructor( private val migrateFailedNodeService: MigrateFailedNodeService, private val migrateFailedNodeDao: MigrateFailedNodeDao, diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateRepoStorageServiceTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateRepoStorageServiceTest.kt index 7b9602a52d..bbe86ec48d 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateRepoStorageServiceTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/MigrateRepoStorageServiceTest.kt @@ -75,6 +75,7 @@ import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Update import org.springframework.data.mongodb.core.query.isEqualTo +import org.springframework.test.context.TestPropertySource import java.time.LocalDateTime @DisplayName("迁移服务测试") @@ -88,6 +89,7 @@ import java.time.LocalDateTime ExecutingTaskRecorder::class, StorageProperties::class, ) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) class MigrateRepoStorageServiceTest @Autowired constructor( private val migrateRepoStorageTaskDao: MigrateRepoStorageTaskDao, private val migrateRepoStorageService: MigrateRepoStorageService, @@ -109,6 +111,9 @@ class MigrateRepoStorageServiceTest @Autowired constructor( @MockBean(name = "correctExecutor") private lateinit var mockCorrectExecutor: TaskExecutor + @Autowired + private lateinit var repositoryCommonUtils: RepositoryCommonUtils + @BeforeEach fun beforeEach() { initMock() @@ -148,7 +153,8 @@ class MigrateRepoStorageServiceTest @Autowired constructor( // 修改任务时间使其超时 val update = Update().set( - TMigrateRepoStorageTask::lastModifiedDate.name, LocalDateTime.now().minus(properties.timeout) + TMigrateRepoStorageTask::lastModifiedDate.name, + LocalDateTime.now().minus(properties.timeout), ) migrateRepoStorageTaskDao.updateFirst(Query(Criteria.where(ID).isEqualTo(task.id!!)), update) @@ -179,7 +185,7 @@ class MigrateRepoStorageServiceTest @Autowired constructor( migrateRepoStorageTaskDao.updateFirst( Query(Criteria.where(ID).isEqualTo(taskId)), Update().set(TMigrateRepoStorageTask::state.name, MIGRATE_FINISHED.name) - .set(TMigrateRepoStorageTask::startDate.name, LocalDateTime.now()) + .set(TMigrateRepoStorageTask::startDate.name, LocalDateTime.now()), ) task = migrateRepoStorageService.tryExecuteTask() assertNull(task) @@ -188,7 +194,10 @@ class MigrateRepoStorageServiceTest @Autowired constructor( // 达到时间间隔 migrateRepoStorageTaskDao.updateFirst( Query(Criteria.where(ID).isEqualTo(taskId)), - Update().set(TMigrateRepoStorageTask::startDate.name, LocalDateTime.now().minus(properties.correctInterval)) + Update().set( + TMigrateRepoStorageTask::startDate.name, + LocalDateTime.now().minus(properties.correctInterval), + ), ) task = migrateRepoStorageService.tryExecuteTask() assertNotNull(task) @@ -207,12 +216,12 @@ class MigrateRepoStorageServiceTest @Autowired constructor( private fun buildCreateRequest(dstKey: String? = UT_STORAGE_CREDENTIALS_KEY) = CreateMigrateRepoStorageTaskRequest( projectId = UT_PROJECT_ID, repoName = UT_REPO_NAME, - dstCredentialsKey = dstKey + dstCredentialsKey = dstKey, ) private fun initMock() { whenever(repositoryClient.getRepoDetail(anyString(), anyString(), anyOrNull())).thenReturn( - Response(0, "", buildRepo()) + Response(0, "", buildRepo()), ) whenever(storageCredentialsClient.findByKey(anyString())) .thenReturn(Response(0, data = FileSystemCredentials())) diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/executor/ExecutorBaseTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/executor/ExecutorBaseTest.kt index 574507e94d..5668495764 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/executor/ExecutorBaseTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/executor/ExecutorBaseTest.kt @@ -65,6 +65,7 @@ import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Update import org.springframework.data.mongodb.core.query.isEqualTo +import org.springframework.test.context.TestPropertySource import java.time.LocalDateTime @DataMongoTest @@ -78,6 +79,7 @@ import java.time.LocalDateTime StorageProperties::class, ) @ComponentScan(basePackages = ["com.tencent.bkrepo.job.migrate"]) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) open class ExecutorBaseTest { @Autowired protected lateinit var migrateRepoStorageProperties: MigrateRepoStorageProperties diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/strategy/FileNotFoundAutoFixStrategyTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/strategy/FileNotFoundAutoFixStrategyTest.kt index 50cc6f76f5..dcf3601bbd 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/strategy/FileNotFoundAutoFixStrategyTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/strategy/FileNotFoundAutoFixStrategyTest.kt @@ -38,6 +38,7 @@ import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.query.Query +import org.springframework.test.context.TestPropertySource @DisplayName("文件找不到错误自动修复策略测试") @DataMongoTest @@ -49,6 +50,7 @@ import org.springframework.data.mongodb.core.query.Query MigrateFailedNodeDao::class, ArchiveMigrateFailedNodeDao::class, ) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) class FileNotFoundAutoFixStrategyTest @Autowired constructor( private val mongoTemplate: MongoTemplate, private val strategy: FileNotFoundAutoFixStrategy, diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/utils/NodeIteratorTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/utils/NodeIteratorTest.kt index ba3141b638..40fb76b968 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/utils/NodeIteratorTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/migrate/utils/NodeIteratorTest.kt @@ -48,6 +48,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.query.Query +import org.springframework.test.context.TestPropertySource import java.time.Duration import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -55,6 +56,7 @@ import java.time.format.DateTimeFormatter @DisplayName("Node遍历工具测试") @DataMongoTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) class NodeIteratorTest @Autowired constructor( private val mongoTemplate: MongoTemplate, ) { diff --git a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/service/impl/ArchiveJobServiceImplTest.kt b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/service/impl/ArchiveJobServiceImplTest.kt index 6d8a30c758..0c2f3ca36c 100644 --- a/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/service/impl/ArchiveJobServiceImplTest.kt +++ b/src/backend/job/biz-job/src/test/kotlin/com/tencent/bkrepo/job/service/impl/ArchiveJobServiceImplTest.kt @@ -20,12 +20,14 @@ import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.query.Query +import org.springframework.test.context.TestPropertySource import java.time.LocalDateTime @DisplayName("归档任务服务测试") @DataMongoTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Import(ArchiveJobServiceImpl::class) +@TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) class ArchiveJobServiceImplTest @Autowired constructor( private val mongoTemplate: MongoTemplate, private val service: ArchiveJobServiceImpl, diff --git a/src/backend/webhook/biz-webhook/src/test/resources/bootstrap-ut.properties b/src/backend/webhook/biz-webhook/src/test/resources/bootstrap-ut.properties index 2363f10292..9790739c21 100644 --- a/src/backend/webhook/biz-webhook/src/test/resources/bootstrap-ut.properties +++ b/src/backend/webhook/biz-webhook/src/test/resources/bootstrap-ut.properties @@ -26,4 +26,5 @@ # spring.cloud.consul.enabled=false -spring.main.lazy-initialization=true \ No newline at end of file +spring.main.lazy-initialization=true +spring.mongodb.embedded.version=4.0.2 \ No newline at end of file diff --git a/support-files/kubernetes/images/backend/backend.Dockerfile b/support-files/kubernetes/images/backend/backend.Dockerfile index 8b6f26375b..60bd05309a 100644 --- a/support-files/kubernetes/images/backend/backend.Dockerfile +++ b/support-files/kubernetes/images/backend/backend.Dockerfile @@ -1,4 +1,4 @@ -FROM blueking/jdk:0.0.1 +FROM blueking/jdk:0.0.2 LABEL maintainer="Tencent BlueKing Devops" diff --git a/support-files/kubernetes/images/backend/startup.sh b/support-files/kubernetes/images/backend/startup.sh index f013a77e0b..025ec2279d 100755 --- a/support-files/kubernetes/images/backend/startup.sh +++ b/support-files/kubernetes/images/backend/startup.sh @@ -13,6 +13,7 @@ java -server \ -XX:+HeapDumpOnOutOfMemoryError \ -XX:HeapDumpPath=oom.hprof \ -XX:ErrorFile=$BK_REPO_LOGS_DIR/error_sys.log \ + -XX:+UseContainerSupport \ -Dspring.profiles.active=$BK_REPO_PROFILE \ -Dservice.prefix=$BK_REPO_SERVICE_PREFIX \ $BK_REPO_JVM_OPTION \