Skip to content

Commit

Permalink
Merge pull request #270 from eazence/issue_269
Browse files Browse the repository at this point in the history
fix: 编译加速资源上报统计数据异常 #269
  • Loading branch information
foxdd authored Sep 10, 2024
2 parents 50a0a18 + 8c6f72d commit da43513
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TbsDaySummaryDao @Autowired constructor(

val criteria = Criteria.where("day").gte(startDate).lte(endDate)
.and("user").`is`(null)
.and("total_time_with_cpu").gt(0)
.and("engine_code").ne("disttask-ue4")
.apply { if (filterPlanIdNin.isNotEmpty()) and("plan_id").nin(filterPlanIdNin) }
.apply { if (filterProjectIdNin.isNotEmpty()) and("project_id").nin(filterProjectIdNin) }
Expand Down Expand Up @@ -112,6 +113,7 @@ class TbsDaySummaryDao @Autowired constructor(
logger.info("findByDayForUE startDate: $startDate, endDate: $endDate, filterPlanIdNin: $filterPlanIdNin")
val criteria = Criteria.where("day").gte(startDate).lte(endDate)
.and("user").ne(null)
.and("total_time_with_cpu").gt(0)
.and("engine_code").`is`("disttask-ue4")
.apply {
if (filterPlanIdNin.isNotEmpty()) and("plan_id").nin(filterPlanIdNin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ interface BaseDataRepository : MongoRepository<BaseDataEntity, String> {
* 根据参数标识代码查询
*/
fun findFirstByParamCode(paramCode: String): BaseDataEntity?

/**
* 根据参数标识代码list查询
*/
fun findByParamCodeIn(paramCodeList: List<String>): List<BaseDataEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.tencent.devops.common.api.exception.code.TURBO_PARAM_INVALID
import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.util.JsonUtil
import com.tencent.devops.common.util.MathUtil
import com.tencent.devops.common.util.constants.BASE_EXCLUDED_PLAN_ID_LIST
import com.tencent.devops.common.util.constants.BASE_EXCLUDED_COMMON_PLAN_ID
import com.tencent.devops.common.util.constants.BASE_EXCLUDED_PLAN_ID_LIST_FOR_DEV_CLOUD
import com.tencent.devops.common.util.constants.BASE_EXCLUDED_PROJECT_ID_LIST
import com.tencent.devops.turbo.config.TodCostProperties
import com.tencent.devops.turbo.dao.mongotemplate.TbsDaySummaryDao
Expand Down Expand Up @@ -50,8 +51,9 @@ class ProjectResourcesService @Autowired constructor(
val pageSizeNum = pageSize?.coerceAtMost(10000) ?: 100

// 获取需要过滤掉的方案id集合
val baseDataEntity = baseDataRepository.findFirstByParamCode(BASE_EXCLUDED_PLAN_ID_LIST)
val filterPlanIds = baseDataEntity?.paramValue?.split(",")?.toSet() ?: emptySet()
val baseDataEntityList = baseDataRepository.findByParamCodeIn(listOf(BASE_EXCLUDED_PLAN_ID_LIST_FOR_DEV_CLOUD,
BASE_EXCLUDED_COMMON_PLAN_ID))
val filterPlanIds = baseDataEntityList.flatMap { it.paramValue.split(",") }.toSet() ?: emptySet()

// 获取需要过滤掉的项目id集合
val projectExcludedEntity = baseDataRepository.findFirstByParamCode(BASE_EXCLUDED_PROJECT_ID_LIST)
Expand Down Expand Up @@ -120,7 +122,7 @@ class ProjectResourcesService @Autowired constructor(
val end = endDate?.let { LocalDate.parse(it) } ?: today.withDayOfMonth(14)
this.checkDatesInMonth(month, start, end)

val filterPlanIds = getFilterIds(BASE_EXCLUDED_PLAN_ID_LIST)
val filterPlanIds = getFilterIds(BASE_EXCLUDED_COMMON_PLAN_ID)
val filterProjectIds = getFilterIds(BASE_EXCLUDED_PROJECT_ID_LIST)
val properties = SpringContextHolder.getBean<TodCostProperties>()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
api("org.quartz-scheduler:quartz")
api("org.quartz-scheduler:quartz-jobs")
api("com.novemberain:quartz-mongodb:2.2.0-rc2")
api("io.fluidsonic.mirror:quartz-mongodb:2.2.0-rc2")
api("org.springframework.boot:spring-boot-starter")
api("org.springframework:spring-context-support")
api("org.springframework:spring-tx")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ const val SYSTEM_ADMIN = "Turbo"
const val NO_ADMIN_MEMBER_MESSAGE = "无权限,请先加入项目!"

/**
* 统计数据需排除的plan id
* 统计数据需排除的plan id(DevCloud专用统计排除,服务计费不需要过滤掉)
* 微信和王者的机器资源是他们自己管理,DevCloud无需计费,咱们内部计费需要纳入统计
*/
const val BASE_EXCLUDED_PLAN_ID_LIST = "EXCLUDED_PLAN_ID_LIST"
const val BASE_EXCLUDED_PLAN_ID_LIST_FOR_DEV_CLOUD = "EXCLUDED_PLAN_ID_LIST"

/**
* 统计数据需排除的project id
*/
const val BASE_EXCLUDED_PROJECT_ID_LIST = "EXCLUDED_PROJECT_ID_LIST"

/**
* 内部测试的方案,服务计费时需要过滤掉
*/
const val BASE_EXCLUDED_COMMON_PLAN_ID = "EXCLUDED_COMMON_PLAN_ID_LIST"

0 comments on commit da43513

Please sign in to comment.