Skip to content

Commit 8579ebc

Browse files
michel-guillonjreynard-code
authored andcommitted
Add two new scenariorun metric labels
1 parent 27a2df6 commit 8579ebc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/metrics/ScenarioRunMetrics.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import com.cosmotech.api.events.ScenarioRunStartedForScenario
99
import com.cosmotech.api.metrics.DownSamplingAggregationType
1010
import com.cosmotech.api.metrics.PersistentMetric
1111
import com.cosmotech.api.metrics.PersitentMetricType
12+
import com.cosmotech.api.utils.getCurrentAuthenticatedUserName
13+
import com.cosmotech.api.utils.getLocalDateNow
1214
import com.cosmotech.scenariorun.WORKFLOW_TYPE_LABEL
1315
import com.cosmotech.scenariorun.service.WORKFLOW_TYPE_SCENARIO_RUN
1416
import com.cosmotech.scenariorun.workflow.WorkflowContextData
1517
import com.cosmotech.scenariorun.workflow.WorkflowService
18+
import java.time.LocalDate
19+
import java.time.format.DateTimeFormatter
1620
import org.springframework.context.event.EventListener
1721
import org.springframework.scheduling.annotation.Scheduled
1822
import org.springframework.stereotype.Service
@@ -24,6 +28,8 @@ private const val SERVICE_NAME = "scenariorun"
2428
private const val ORGANIZATION_ID_LABEL = "organizationId"
2529
private const val WORKSPACE_ID_LABEL = "workspaceId"
2630
private const val SCENARIO_ID_LABEL = "scenarioId"
31+
private const val DATE_LABEL = "date"
32+
private const val USER_ID_LABEL = "userId"
2733

2834
private const val DEFAULT_EMPTY_WORKFLOW_LABEL = "none"
2935
private const val TOTAL_QUALIFIER = "total"
@@ -87,6 +93,20 @@ internal class ScenarioRunMetrics(
8793
labels[SCENARIO_ID_LABEL] = scenarioId
8894
name += ":$scenarioId"
8995
publishRunStartLabeledMetric(name, labels)
96+
97+
// By Date
98+
val pattern = "yyyy/MM/dd"
99+
LocalDate.now().format(DateTimeFormatter.ofPattern(pattern))
100+
val date = getLocalDateNow(pattern)
101+
name += ":$date"
102+
labels[DATE_LABEL] = date
103+
publishRunStartLabeledMetric(name, labels)
104+
105+
// By user Id
106+
val userId = getCurrentAuthenticatedUserName(csmPlatformProperties)
107+
name += ":$userId"
108+
labels[USER_ID_LABEL] = userId
109+
publishRunStartLabeledMetric(name, labels)
90110
}
91111

92112
private fun getRunningWorkflowsCount(): Map<WorkflowContextData?, Int> {

0 commit comments

Comments
 (0)