Skip to content

Commit

Permalink
feat: 升级devops framework框架到0.0.9 TencentBlueKing#2387
Browse files Browse the repository at this point in the history
* feat: 升级devops framework框架到0.0.9 TencentBlueKing#2387

* feat: 处理循环依赖 TencentBlueKing#2387

* feat: 修改devops framework版本为0.0.9 TencentBlueKing#2387

* feat: 修改devops framework版本为0.0.9 TencentBlueKing#2387

* feat: 修改devops framework版本为0.0.9 TencentBlueKing#2387

* feat: 修改devops framework版本为0.0.9 TencentBlueKing#2387
  • Loading branch information
felixncheng authored Jul 24, 2024
1 parent e244369 commit 9c5e83b
Show file tree
Hide file tree
Showing 31 changed files with 100 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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为任务数量
*/
Expand Down Expand Up @@ -83,6 +84,7 @@ class ScannerMetrics(
}

override fun bindTo(registry: MeterRegistry) {
this.meterRegistry = registry
taskGauge(
scanTaskSchedulerThreadPool,
{ threadPoolExecutor.queue.size.toDouble() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -63,6 +64,7 @@ class CreateSubtaskAction(
) : SubtaskAction {

@Autowired
@Lazy
private lateinit var self: CreateSubtaskAction

override fun execute(source: String, target: String, event: Event): TransitResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TArchiveFile, Mono<TaskResult>> {
@Autowired
@Lazy
private lateinit var archiveFileDao: ArchiveFileDao

@Autowired
@Lazy
private lateinit var archiveFileRepository: ArchiveFileRepository

private val tika = Tika()
private val compressPool = ArchiveUtils.newFixedAndCachedThreadPool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TCompressFile, Mono<TaskResult>> {
@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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 2 additions & 9 deletions src/backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}")
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions src/backend/buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open class TransmittableInheritableThreadLocal<T> : InheritableThreadLocal<T>()

override fun set(value: T) {
super.set(value)
if (!Transmitter.holder.get().contains(this)) {
if (!Transmitter.holder.get().contains(this as ThreadLocal<Any>)) {
Transmitter.holder.get().add(this as ThreadLocal<Any>)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open class TransmittableThreadLocal<T> : ThreadLocal<T>() {

override fun set(value: T) {
super.set(value)
if (!Transmitter.holder.get().contains(this)) {
if (!Transmitter.holder.get().contains(this as ThreadLocal<Any>)) {
Transmitter.holder.get().add(this as ThreadLocal<Any>)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import java.util.concurrent.atomic.AtomicInteger
class ArtifactMetrics(
private val threadPoolTaskExecutor: ThreadPoolTaskExecutor,
tagProvider: ArtifactTransferTagProvider,
meterRegistry: MeterRegistry,
properties: ArtifactMetricsProperties
) : MeterBinder {

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,7 +71,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
ClusterConfiguration::class,
CustomFeignClientsConfiguration::class,
OtelMongoConfiguration::class,
OtelResourceConfiguration::class,
OtelWebConfiguration::class
)
class ServiceAutoConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,14 +39,6 @@ import org.springframework.context.annotation.Configuration
@ConditionalOnClass(OtelTracer::class, MongoClientImpl::class)
class OtelMongoConfiguration {

@Bean
fun traceMongoClientSettingsBuilderCustomizer(
tracer: Tracer,
customizers: ObjectProvider<List<TraceMongoSpanCustomizer>>
): TraceMongoClientSettingsBuilderCustomizer {
return TraceMongoClientSettingsBuilderCustomizer(tracer, customizers.ifAvailable.orEmpty())
}

@Bean
fun dbMongoSpanCustomizer(): TraceMongoSpanCustomizer {
return DBMongoSpanCustomizer()
Expand Down
Loading

0 comments on commit 9c5e83b

Please sign in to comment.