Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/at/ac/uibk/dps/cirrina/Runtime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ constructor(
@Main main: URI,
persistentContext: Context?,
stateMachineFactory: StateMachine.Factory,
meterRegistry: MeterRegistry,
val meterRegistry: MeterRegistry,
) {
val eventHandler = EventHandler()
val extent = persistentContext?.let { Extent.of(it) } ?: Extent.of()
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/at/ac/uibk/dps/cirrina/execution/object/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ sealed interface Action {

is LogDescription -> LogAction(Expression.create(description.message))

is IncrCtrDescription ->
IncrCtrAction(
description.counter,
description.by ?: "1.0",
description.tags?.mapValues { (_, v) -> Expression.create(v) } ?: emptyMap(),
)

else -> error("unknown action type: ${description.javaClass.simpleName}")
}

Expand Down Expand Up @@ -107,3 +114,9 @@ class TimeoutResetAction internal constructor(val action: String) : Action {
}

class LogAction internal constructor(val message: Expression) : Action

class IncrCtrAction
internal constructor(val counter: String, val by: String, val tag: Map<String, Expression>) :
Action {
override fun toString() = "IncrCtrAction(metric='$counter', by='$by', tag='$tag')"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package at.ac.uibk.dps.cirrina.execution.`object`

import at.ac.uibk.dps.cirrina.csm.Csml.EventChannel
import at.ac.uibk.dps.cirrina.execution.service.ServiceImplementationSelector
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Tag
import io.micrometer.core.instrument.Tags
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import mu.KotlinLogging
Expand All @@ -16,6 +19,7 @@ class ActionExecutor(
private val selector: ServiceImplementationSelector,
private val eventHandler: StateMachine.StateMachineEventHandler,
private val coroutineScope: CoroutineScope,
private val meterRegistry: MeterRegistry,
) {
fun execute(action: Action, scope: Scope): List<Action> =
when (action) {
Expand All @@ -26,6 +30,7 @@ class ActionExecutor(
is TimeoutAction -> listOf(action.triggers)
is TimeoutResetAction -> emptyList()
is LogAction -> executeLog(action, scope)
is IncrCtrAction -> executeIncrCtr(action, scope)
else -> error("unknown action type: ${action::class.simpleName}")
}

Expand Down Expand Up @@ -84,4 +89,13 @@ class ActionExecutor(
action.message.execute(scope.extent).toString().also { logger.info(it) }
return emptyList()
}

private fun executeIncrCtr(action: IncrCtrAction, scope: Scope): List<Action> {
val tags =
Tags.of(
action.tag.map { (key, value) -> Tag.of(key, value.execute(scope.extent).toString()) }
)
meterRegistry.counter(action.counter, tags).increment(action.by.toDouble())
return emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ internal constructor(
private val timeoutActionManager = TimeoutActionManager(coroutineScope)
private val stateMachineEventHandler = StateMachineEventHandler(runtime.eventHandler)
private val actionExecutor =
ActionExecutor(runtime.selector, stateMachineEventHandler, coroutineScope)
ActionExecutor(
runtime.selector,
stateMachineEventHandler,
coroutineScope,
runtime.meterRegistry,
)

private val stateInstances =
specification.vertexSet().associate { it.name to stateFactory.create(it, this) }
Expand Down
14 changes: 10 additions & 4 deletions src/main/resources/pkl/csm/csml.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class EvalDescription extends ActionDescription {
expression: Expression
}


class EmitDescription extends ActionDescription {
event: EventDescription
target: Expression?
Expand All @@ -114,12 +113,10 @@ class TimeoutDescription extends ActionDescription {
triggers: EmitDescription
}


class ResetDescription extends ActionDescription {
name: TimeoutName
}


class CaseDescription {
of: Expression
yields: Listing<ActionDescription>
Expand Down Expand Up @@ -192,4 +189,13 @@ typealias Log = LogDescription

// Event aliases
typealias Event = EventDescription
typealias Internal = InternalDescription
typealias Internal = InternalDescription

// Private API - not meant for production use
class IncrCtrDescription extends ActionDescription {
counter: String
by: String?
tags: Mapping<String, Expression>?
}

typealias IncrCtr = IncrCtrDescription