Skip to content

Commit

Permalink
feat:活跃用户记录操作和次数 #10891
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Sep 4, 2024
1 parent 7a55d9f commit c40d1d3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ProjectUserOperateMetricsEvent> {

companion object {
private val logger = LoggerFactory.getLogger(ProjectUserDailyOperateMetricsListener::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -57,7 +55,7 @@ interface ProjectBuildSummaryService {
* 保存用户操作度量数据
*/
fun saveProjectUserOperateMetrics(
projectUserOperateMetricsMap: Map<String, Map<String, Int>>
projectUserOperateMetricsMap: Map<String/*projectId*/, Map<String, Int>/*projectUserOperateMetricsKey,count*/>
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand 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)
Expand Down Expand Up @@ -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)
}
}
}
10 changes: 10 additions & 0 deletions support-files/sql/1001_ci_metrics_ddl_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c40d1d3

Please sign in to comment.