Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 项目指标获取时间调整 #1314 #1319

Merged
merged 15 commits into from
Oct 27, 2023
Merged
1 change: 1 addition & 0 deletions src/backend/opdata/api-opdata/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
dependencies {
implementation(project(":common:common-api"))
implementation(project(":common:common-operate:operate-annotation"))
api("com.alibaba:easyexcel:3.1.1")
compileOnly("org.springframework.cloud:spring-cloud-openfeign-core")
testImplementation(project(":common:common-operate:operate-service"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const val OPDATA_PIPELINE_SIZE = "pipelineSize"

const val OPDATA_PROJECT_NUM = "ProjectNum"
const val OPDATA_CAP_SIZE = "CapSize"
const val OPDATA_DOCKER_CAP_SIZE = "DockerCapSize"
const val OPDATA_GENERIC_CAP_SIZE = "GenericCapSize"
const val OPDATA_NODE_NUM = "NodeNum"

const val OPDATA_PROJECT = "project"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 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.opdata.pojo

import com.alibaba.excel.annotation.ExcelProperty
import com.alibaba.excel.annotation.write.style.ColumnWidth
import java.time.LocalDateTime

data class ProjectMetrics(
@ColumnWidth(30)
@ExcelProperty(value = ["项目ID"], order = 0)
var projectId: String,
@ColumnWidth(20)
@ExcelProperty(value = ["节点个数"], order = 1)
var nodeNum: Long,
@ColumnWidth(20)
@ExcelProperty(value = ["项目大小(GB)"], order = 2)
var capSize: Long,
@ColumnWidth(20)
@ExcelProperty(value = ["统计时间"], order = 3)
val createdDate: LocalDateTime? = LocalDateTime.now()
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ data class ProjectMetricsOption(
var projectId: String? = null,
val pageNumber: Int = DEFAULT_PAGE_NUMBER,
val pageSize: Int = DEFAULT_PAGE_SIZE,
val createdDate: LocalDateTime = LocalDate.now().atStartOfDay()
val createdDate: LocalDateTime = LocalDate.now().minusDays(1).atStartOfDay()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 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.opdata.pojo

data class ProjectMetricsRequest(
val limitSize: Long = 1024 * 1024 * 1024L,
val minusDay: Long = 1,
val default: Boolean = true,
val type: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ data class RepoMetrics(
@ApiModelProperty("size")
var size: Long,
@ApiModelProperty("num")
val num: Long
val num: Long,
@ApiModelProperty("type")
val type: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ enum class Metrics {
NODECOLLECTION,
REPONODENUM,
REPONODESIZE,
GENERICREPOSIZEINPROJECT,
DOCKERREPOSIZEINPROJECT,
DOCKERCAPSIZE,
GENERICCAPSIZE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import com.tencent.bkrepo.common.security.permission.Principal
import com.tencent.bkrepo.common.security.permission.PrincipalType
import com.tencent.bkrepo.common.service.util.ResponseBuilder
import com.tencent.bkrepo.opdata.model.TProjectMetrics
import com.tencent.bkrepo.opdata.pojo.ProjectMetrics
import com.tencent.bkrepo.opdata.pojo.ProjectMetricsOption
import com.tencent.bkrepo.opdata.pojo.ProjectMetricsRequest
import com.tencent.bkrepo.opdata.service.ProjectMetricsService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -55,4 +57,23 @@ class ProjectController(
): Response<Page<TProjectMetrics>> {
return ResponseBuilder.success(projectMetricsService.page(option))
}

/**
* 获取项目的统计数据
*/
@GetMapping("/list/project/capSize")
fun getProjectCapSizeMetrics(
metricsRequest: ProjectMetricsRequest
): Response<List<ProjectMetrics>> {
return ResponseBuilder.success(projectMetricsService.list(metricsRequest))
}
/**
* 获取项目的统计数据
*/
@GetMapping("/list/project/capSize/download")
fun downloadProjectCapSizeMetrics(
metricsRequest: ProjectMetricsRequest
) {
projectMetricsService.download(metricsRequest)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 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.opdata.handler.impl

import com.tencent.bkrepo.opdata.constant.OPDATA_CAP_SIZE
import com.tencent.bkrepo.opdata.constant.OPDATA_GRAFANA_NUMBER
import com.tencent.bkrepo.opdata.constant.TO_GIGABYTE
import com.tencent.bkrepo.opdata.handler.QueryHandler
import com.tencent.bkrepo.opdata.model.StatDateModel
import com.tencent.bkrepo.opdata.pojo.Columns
import com.tencent.bkrepo.opdata.pojo.QueryResult
import com.tencent.bkrepo.opdata.pojo.Target
import com.tencent.bkrepo.opdata.pojo.enums.Metrics
import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository

open class BaseCapSizeHandler(
private val projectMetricsRepository: ProjectMetricsRepository,
private val statDateModel: StatDateModel
) : QueryHandler {

override val metric: Metrics get() = Metrics.DEFAULT

open val repoType: List<String> = emptyList()

open val columnsText: String = OPDATA_CAP_SIZE

override fun handle(target: Target, result: MutableList<Any>) {
var size = 0L
val projects = projectMetricsRepository.findAllByCreatedDate(statDateModel.getShedLockInfo())
if (repoType.isEmpty()) {
projects.forEach {
size += it.capSize
}
} else {
projects.forEach { project ->
project.repoMetrics.filter { !it.type.isNullOrEmpty() && it.type in repoType }.forEach { repo ->
size += repo.size
}
}
}
val column = Columns(columnsText, OPDATA_GRAFANA_NUMBER)
val row = listOf(size / TO_GIGABYTE)
val data = QueryResult(listOf(column), listOf(row), target.type)
result.add(data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@

package com.tencent.bkrepo.opdata.handler.impl

import com.tencent.bkrepo.opdata.constant.OPDATA_CAP_SIZE
import com.tencent.bkrepo.opdata.constant.OPDATA_GRAFANA_NUMBER
import com.tencent.bkrepo.opdata.constant.TO_GIGABYTE
import com.tencent.bkrepo.opdata.handler.QueryHandler
import com.tencent.bkrepo.opdata.pojo.Columns
import com.tencent.bkrepo.opdata.pojo.QueryResult
import com.tencent.bkrepo.opdata.pojo.Target
import com.tencent.bkrepo.opdata.model.StatDateModel
import com.tencent.bkrepo.opdata.pojo.enums.Metrics
import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository
import org.springframework.stereotype.Component
Expand All @@ -47,20 +41,9 @@ import org.springframework.stereotype.Component
*/
@Component
class CapSizeHandler(
private val projectMetricsRepository: ProjectMetricsRepository
) : QueryHandler {
projectMetricsRepository: ProjectMetricsRepository,
statDateModel: StatDateModel
) : BaseCapSizeHandler(projectMetricsRepository, statDateModel) {

override val metric: Metrics get() = Metrics.CAPSIZE

override fun handle(target: Target, result: MutableList<Any>) {
var size = 0L
val projects = projectMetricsRepository.findAllByCreatedDate()
projects.forEach {
size += it.capSize
}
val column = Columns(OPDATA_CAP_SIZE, OPDATA_GRAFANA_NUMBER)
val row = listOf(size / TO_GIGABYTE)
val data = QueryResult(listOf(column), listOf(row), target.type)
result.add(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 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.opdata.handler.impl

import com.tencent.bkrepo.opdata.constant.OPDATA_DOCKER_CAP_SIZE
import com.tencent.bkrepo.opdata.model.StatDateModel
import com.tencent.bkrepo.opdata.pojo.enums.Metrics
import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository
import org.springframework.stereotype.Component

/**
* DOCKER 仓库总容量统计
*/
@Component
class DockerCapSizeHandler(
projectMetricsRepository: ProjectMetricsRepository,
statDateModel: StatDateModel
) : BaseCapSizeHandler(projectMetricsRepository, statDateModel) {

override val metric: Metrics get() = Metrics.DOCKERCAPSIZE

override val columnsText: String = OPDATA_DOCKER_CAP_SIZE

override val repoType: List<String>
get() = DOCKER_TYPES

companion object {
private val DOCKER_TYPES = listOf("DOCKER", "OCI")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 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.opdata.handler.impl

import com.tencent.bkrepo.opdata.model.StatDateModel
import com.tencent.bkrepo.opdata.pojo.enums.Metrics
import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository
import org.springframework.stereotype.Component

/**
* 项目中镜像仓库总大小
*/
@Component
class DockerRepoSizeInProject(
projectMetricsRepository: ProjectMetricsRepository,
statDateModel: StatDateModel
) : RepoSizeInProject(projectMetricsRepository, statDateModel) {

override val metric: Metrics
get() = Metrics.DOCKERREPOSIZEINPROJECT
override val repoType: List<String>
get() = DOCKER_TYPES

companion object {
private val DOCKER_TYPES = listOf("DOCKER", "OCI")
}
}
Loading
Loading