diff --git a/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/pojo/measure/ProjectUserOperateMetricsData.kt b/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/pojo/measure/ProjectUserOperateMetricsData.kt index f16509aa71c..6dec36f25e0 100644 --- a/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/pojo/measure/ProjectUserOperateMetricsData.kt +++ b/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/pojo/measure/ProjectUserOperateMetricsData.kt @@ -29,16 +29,4 @@ data class ProjectUserOperateMetricsData( fun getProjectUserOperateMetricsKey(): String { return "key:$projectId:$userId:$operate:$theDate" } - - override fun equals(other: Any?): Boolean { - if (other is ProjectUserOperateMetricsData) { - return other.projectId == projectId && other.userId == userId && - other.theDate == theDate && other.operate == operate - } - return super.equals(other) - } - - override fun hashCode(): Int { - return getProjectUserOperateMetricsKey().hashCode() - } } diff --git a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/dao/ProjectBuildSummaryDao.kt b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/dao/ProjectBuildSummaryDao.kt index 74ae5d61459..4867234d7f3 100644 --- a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/dao/ProjectBuildSummaryDao.kt +++ b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/dao/ProjectBuildSummaryDao.kt @@ -40,7 +40,6 @@ import org.jooq.DSLContext import org.springframework.stereotype.Repository import java.time.LocalDate import java.time.LocalDateTime -import java.util.concurrent.atomic.AtomicInteger @Repository class ProjectBuildSummaryDao { diff --git a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/listener/ProjectUserDailyOperateMetricsListener.kt b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/listener/ProjectUserDailyOperateMetricsListener.kt index 9a69f8f60ba..9093e696f2b 100644 --- a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/listener/ProjectUserDailyOperateMetricsListener.kt +++ b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/listener/ProjectUserDailyOperateMetricsListener.kt @@ -28,8 +28,6 @@ package com.tencent.devops.metrics.listener -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.event.listener.Listener import com.tencent.devops.common.event.pojo.measure.ProjectUserOperateMetricsEvent import com.tencent.devops.metrics.service.ProjectBuildSummaryService @@ -38,10 +36,9 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @Component - class ProjectUserDailyOperateMetricsListener @Autowired constructor( +class ProjectUserDailyOperateMetricsListener @Autowired constructor( private val projectBuildSummaryService: ProjectBuildSummaryService ) : Listener { - companion object { private val logger = LoggerFactory.getLogger(ProjectUserDailyOperateMetricsListener::class.java) } diff --git a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/ProjectBuildSummaryService.kt b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/ProjectBuildSummaryService.kt index d75f859c7c5..f96605cd01e 100644 --- a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/ProjectBuildSummaryService.kt +++ b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/ProjectBuildSummaryService.kt @@ -28,11 +28,9 @@ package com.tencent.devops.metrics.service -import com.tencent.devops.common.event.pojo.measure.ProjectUserOperateMetricsData import com.tencent.devops.metrics.pojo.vo.BaseQueryReqVO import com.tencent.devops.metrics.pojo.vo.ProjectUserCountV0 import java.time.LocalDate -import java.util.concurrent.atomic.AtomicInteger interface ProjectBuildSummaryService { @@ -57,7 +55,7 @@ interface ProjectBuildSummaryService { * 保存用户操作度量数据 */ fun saveProjectUserOperateMetrics( - projectUserOperateMetricsMap: Map> + projectUserOperateMetricsMap: Map/*projectUserOperateMetricsKey,count*/> ) /** diff --git a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/impl/ProjectBuildSummaryServiceImpl.kt b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/impl/ProjectBuildSummaryServiceImpl.kt index 1e5f9296182..6fe18161ef9 100644 --- a/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/impl/ProjectBuildSummaryServiceImpl.kt +++ b/src/backend/ci/core/metrics/biz-metrics/src/main/kotlin/com/tencent/devops/metrics/service/impl/ProjectBuildSummaryServiceImpl.kt @@ -28,7 +28,6 @@ package com.tencent.devops.metrics.service.impl -import com.tencent.devops.common.event.pojo.measure.ProjectUserOperateMetricsData import com.tencent.devops.common.redis.RedisLock import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.metrics.dao.ProjectBuildSummaryDao @@ -42,7 +41,6 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import java.time.LocalDate -import java.util.concurrent.atomic.AtomicInteger @Service class ProjectBuildSummaryServiceImpl @Autowired constructor( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index b7ff4d0101a..06eacc79deb 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -27,7 +27,6 @@ package com.tencent.devops.process.service.webhook -import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.util.JsonUtil @@ -81,7 +80,6 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import java.time.LocalDate -import java.util.concurrent.atomic.AtomicInteger import javax.ws.rs.core.Response @Suppress("ALL") @@ -99,8 +97,7 @@ class PipelineBuildWebhookService @Autowired constructor( private val pipelineTriggerEventService: PipelineTriggerEventService, private val measureEventDispatcher: MeasureEventDispatcher, private val pipelineBuildPermissionService: PipelineBuildPermissionService, - private val pipelineYamlService: PipelineYamlService, - private val objectMapper: ObjectMapper + private val pipelineYamlService: PipelineYamlService ) { companion object { private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java) @@ -611,25 +608,29 @@ class PipelineBuildWebhookService @Autowired constructor( projectId: String, theDate: LocalDate ) { - val projectUserOperateMetricsMap = mapOf( - projectId to mapOf( - ProjectUserOperateMetricsData( + try { + val projectUserOperateMetricsMap = mapOf( + projectId to mapOf( + ProjectUserOperateMetricsData( + projectId = projectId, + userId = userId, + operate = WEBHOOK_COMMIT_TRIGGER, + theDate = theDate + ).getProjectUserOperateMetricsKey() to 1 + ) + ) + measureEventDispatcher.dispatch( + ProjectUserDailyEvent( projectId = projectId, userId = userId, - operate = WEBHOOK_COMMIT_TRIGGER, theDate = theDate - ).getProjectUserOperateMetricsKey() to 1 - ) - ) - measureEventDispatcher.dispatch( - ProjectUserDailyEvent( - projectId = projectId, - userId = userId, - theDate = theDate - ), - ProjectUserOperateMetricsEvent( - projectUserOperateMetricsMap = projectUserOperateMetricsMap + ), + ProjectUserOperateMetricsEvent( + projectUserOperateMetricsMap = projectUserOperateMetricsMap + ) ) - ) + } catch (ignored: Exception) { + logger.error("save auth user metrics", ignored) + } } } diff --git a/support-files/sql/1001_ci_metrics_ddl_mysql.sql b/support-files/sql/1001_ci_metrics_ddl_mysql.sql index bf96aa69324..412a4021fa2 100644 --- a/support-files/sql/1001_ci_metrics_ddl_mysql.sql +++ b/support-files/sql/1001_ci_metrics_ddl_mysql.sql @@ -317,4 +317,14 @@ CREATE TABLE IF NOT EXISTS `T_PROJECT_BUILD_SUMMARY_DAILY` INDEX `IDX_PRODUCT_ID`(`PRODUCT_ID`,`THE_DATE`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='项目每日构建汇总表'; +CREATE TABLE IF NOT EXISTS `T_PROJECT_USER_OPERATE_DAILY` ( + `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', + `USER_ID` varchar(64) NOT NULL COMMENT '用户ID', + `THE_DATE` date NOT NULL COMMENT '日期', + `OPERATE` varchar(64) NOT NULL COMMENT '操作', + `OPERATE_COUNT` int(11) NOT NULL DEFAULT '0' COMMENT '操作次数', + `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`PROJECT_ID`,`USER_ID`, `THE_DATE`, `OPERATE`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目用户日常操作记录表'; + SET FOREIGN_KEY_CHECKS = 1;