Skip to content

Commit

Permalink
feat: 统计指标增加项目启用状态 TencentBlueKing#1833
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL authored Mar 7, 2024
1 parent 519e540 commit 42b45e0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const val DELETED_DATE = "deleted"
const val FULL_PATH = "fullPath"
const val PATH = "path"
const val LAST_MODIFIED_BY = "lastModifiedBy"
const val NAME = "name"

/**
* 缓存类型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class ProjectMetricsReport2BkbaseJob(
capSize = row[TProjectMetrics::capSize.name].toString().toLongOrNull() ?: 0,
repoMetrics = row[TProjectMetrics::repoMetrics.name]?.toJsonString()
?.readJsonString<List<TRepoMetrics>>() ?: emptyList(),
createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString())
createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString()),
active = row[TProjectMetrics::active.name].toString().toBoolean(),
projectStatus = row[TProjectMetrics::projectStatus.name]?.toString()?.toBoolean()
)
}

Expand Down Expand Up @@ -123,8 +125,8 @@ class ProjectMetricsReport2BkbaseJob(
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,
productId = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_PRODUCT_ID }?.value as? Int,
enabled = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_ENABLED }?.value as? Boolean,
active = current.active
enabled = current.projectStatus,
active = current.active,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package com.tencent.bkrepo.job.batch.stat
import com.tencent.bkrepo.common.artifact.path.PathUtils
import com.tencent.bkrepo.job.CREATED_DATE
import com.tencent.bkrepo.job.DELETED_DATE
import com.tencent.bkrepo.job.NAME
import com.tencent.bkrepo.job.PATH
import com.tencent.bkrepo.job.PROJECT
import com.tencent.bkrepo.job.REPO
Expand All @@ -42,6 +43,7 @@ import com.tencent.bkrepo.job.batch.utils.FolderUtils
import com.tencent.bkrepo.job.batch.utils.MongoShardingUtils
import com.tencent.bkrepo.job.config.properties.MongodbJobProperties
import com.tencent.bkrepo.job.pojo.project.TProjectMetrics
import com.tencent.bkrepo.repository.pojo.project.ProjectMetadata
import org.slf4j.LoggerFactory
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
Expand Down Expand Up @@ -139,9 +141,27 @@ open class ProjectRepoMetricsStatJob(
val criteria = Criteria.where(CREATED_DATE).isEqualTo(statDate).and(PROJECT).`is`(projectMetric.projectId)
mongoTemplate.remove(Query(criteria), COLLECTION_NAME_PROJECT_METRICS)
logger.info("stat project: [${projectMetric.projectId}], size: [${projectMetric.capSize}]")
projectMetric.projectStatus = getProjectEnableStatus(projectMetric.projectId)
mongoTemplate.insert(projectMetric, COLLECTION_NAME_PROJECT_METRICS)
}

private fun getProjectEnableStatus(projectId: String): Boolean? {
val query = Query.query(Criteria.where(NAME).isEqualTo(projectId))
val project = mongoTemplate.find(query, Project::class.java, COLLECTION_NAME_PROJECT)
.firstOrNull() ?: return null
return project.metadata.firstOrNull() { it.key == "enabled" }?.value as Boolean?
}

data class Project(var name: String, var metadata: List<ProjectMetadata> = emptyList()) {
constructor(map: Map<String, Any?>) : this(
map[Project::name.name].toString(),
(map[Project::metadata.name] as? List<Map<String, Any>>)?.map {
ProjectMetadata(it[ProjectMetadata::key.name].toString(), it[ProjectMetadata::value.name]!!)
} ?: emptyList(),
)
}


data class Repository(
var projectId: String,
var name: String,
Expand Down Expand Up @@ -180,5 +200,6 @@ open class ProjectRepoMetricsStatJob(
private const val COLLECTION_REPOSITORY_NAME = "repository"
private const val COLLECTION_NODE_PREFIX = "node_"
private const val COLLECTION_NAME_PROJECT_METRICS = "project_metrics"
private const val COLLECTION_NAME_PROJECT = "project"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ data class TProjectMetrics(
var capSize: Long,
val repoMetrics: List<TRepoMetrics>,
val createdDate: LocalDateTime? = LocalDateTime.now(),
val active: Boolean = true
val active: Boolean = true,
var projectStatus: Boolean? = null
)

0 comments on commit 42b45e0

Please sign in to comment.