Skip to content

Commit

Permalink
feat: 增加节点个数TencentBlueKing#2136
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL committed May 11, 2024
1 parent 09feb05 commit 3b1dfcd
Showing 1 changed file with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import kotlin.reflect.KClass
class ProjectMetricsReport2BkbaseJob(
val properties: ProjectMetricsReport2BkbaseJobProperties,
val messageSupplier: MessageSupplier
) : DefaultContextMongoDbJob<TProjectMetrics>(properties) {
) : DefaultContextMongoDbJob<TProjectMetrics>(properties) {
override fun collectionNames(): List<String> {
return listOf(COLLECTION_NAME_PROJECT_METRICS)
}
Expand Down Expand Up @@ -109,18 +109,30 @@ class ProjectMetricsReport2BkbaseJob(
current: TProjectMetrics, project: ProjectInfo, statTime: LocalDateTime
): ProjectMetrics {
val pipelineCapSize = filterByRepoName(current, PIPELINE)
val pipelineNodeNum = filterByRepoName(current, PIPELINE, "num")
val customCapSize = filterByRepoName(current, CUSTOM)
val customNodeNum = filterByRepoName(current, CUSTOM, "num")

val helmRepoCapSize = filterByRepoType(current, RepositoryType.HELM.name)
val helmRepoNodeNum = filterByRepoType(current, RepositoryType.HELM.name, "num")

val dockerRepoCapSize = filterByRepoType(current, RepositoryType.DOCKER.name)
val dockerRepoNodeNum = filterByRepoType(current, RepositoryType.DOCKER.name, "num")


return ProjectMetrics(
projectId = current.projectId,
nodeNum = current.nodeNum,
capSize = current.capSize,
createdDate = statTime,
pipelineCapSize = pipelineCapSize,
pipelineNodeNum = pipelineNodeNum,
customCapSize = customCapSize,
customNodeNum = customNodeNum,
helmRepoCapSize = helmRepoCapSize,
helmRepoNodeNum = helmRepoNodeNum,
dockerRepoCapSize = dockerRepoCapSize,
dockerRepoNodeNum = dockerRepoNodeNum,
bgName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_BG_NAME }?.value as? String,
deptName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_DEPT_NAME }?.value as? String,
centerName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_CENTER_NAME }?.value as? String,
Expand All @@ -131,18 +143,28 @@ class ProjectMetricsReport2BkbaseJob(
}


private fun filterByRepoName(metric: TProjectMetrics?, repoName: String): Long {
return metric?.repoMetrics?.firstOrNull { it.repoName == repoName }?.size ?: 0
private fun filterByRepoName(metric: TProjectMetrics?, repoName: String, target: String = "size"): Long {
val repoMetrics = metric?.repoMetrics?.firstOrNull { it.repoName == repoName }
return if (target == "size") {
repoMetrics?.size
} else {
repoMetrics?.num
} ?: 0
}

private fun filterByRepoType(metric: TProjectMetrics?, repoType: String): Long {
var sizeOfRepoType: Long = 0

private fun filterByRepoType(metric: TProjectMetrics?, repoType: String, target: String = "size"): Long {
var resultOfType: Long = 0
metric?.repoMetrics?.forEach { repo ->
if (repo.type == repoType) {
sizeOfRepoType += repo.size
resultOfType += if (target == "size") {
repo.size
} else {
repo.num
}
}
}
return sizeOfRepoType
return resultOfType
}

data class ProjectMetrics(
Expand All @@ -155,9 +177,13 @@ class ProjectMetricsReport2BkbaseJob(
var nodeNum: Long,
var capSize: Long,
var pipelineCapSize: Long = 0,
var pipelineNodeNum: Long = 0,
var customCapSize: Long = 0,
var customNodeNum: Long = 0,
var helmRepoCapSize: Long = 0,
var helmRepoNodeNum: Long = 0,
var dockerRepoCapSize: Long = 0,
var dockerRepoNodeNum: Long = 0,
val createdDate: LocalDateTime,
val active: Boolean = true
)
Expand Down

0 comments on commit 3b1dfcd

Please sign in to comment.