summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt43
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt54
2 files changed, 46 insertions, 51 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
index a1cc3390..be6ef11e 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
@@ -25,6 +25,7 @@ package org.opendc.compute.simulator
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.metrics.Meter
+import io.opentelemetry.api.metrics.MeterProvider
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes
import kotlinx.coroutines.*
import mu.KotlinLogging
@@ -59,7 +60,7 @@ public class SimHost(
override val meta: Map<String, Any>,
context: CoroutineContext,
interpreter: SimResourceInterpreter,
- private val meter: Meter,
+ meterProvider: MeterProvider,
hypervisor: SimHypervisorProvider,
scalingGovernor: ScalingGovernor = PerformanceScalingGovernor(),
powerDriver: PowerDriver = SimplePowerDriver(ConstantPowerModel(0.0)),
@@ -82,6 +83,11 @@ public class SimHost(
private val logger = KotlinLogging.logger {}
/**
+ * The [Meter] to track metrics of the simulated host.
+ */
+ private val meter = meterProvider.get("org.opendc.compute.simulator")
+
+ /**
* The event listeners registered with this host.
*/
private val listeners = mutableListOf<HostListener>()
@@ -142,10 +148,9 @@ public class SimHost(
* The total number of guests.
*/
private val _guests = meter.upDownCounterBuilder("guests.total")
- .setDescription("Number of guests")
+ .setDescription("Total number of guests")
.setUnit("1")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The number of active guests on the host.
@@ -154,7 +159,6 @@ public class SimHost(
.setDescription("Number of active guests")
.setUnit("1")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The CPU demand of the host.
@@ -163,7 +167,6 @@ public class SimHost(
.setDescription("The amount of CPU resources the guests would use if there were no CPU contention or CPU limits")
.setUnit("MHz")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The CPU usage of the host.
@@ -172,7 +175,6 @@ public class SimHost(
.setDescription("The amount of CPU resources used by the host")
.setUnit("MHz")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The power usage of the host.
@@ -181,7 +183,6 @@ public class SimHost(
.setDescription("The amount of power used by the CPU")
.setUnit("W")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The total amount of work supplied to the CPU.
@@ -191,7 +192,6 @@ public class SimHost(
.setUnit("1")
.ofDoubles()
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The work performed by the CPU.
@@ -201,7 +201,6 @@ public class SimHost(
.setUnit("1")
.ofDoubles()
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The amount not performed by the CPU due to overcommitment.
@@ -211,7 +210,6 @@ public class SimHost(
.setUnit("1")
.ofDoubles()
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The amount of work not performed by the CPU due to interference.
@@ -221,7 +219,6 @@ public class SimHost(
.setUnit("1")
.ofDoubles()
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The amount of time in the system.
@@ -230,7 +227,6 @@ public class SimHost(
.setDescription("The amount of time in the system")
.setUnit("ms")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The uptime of the host.
@@ -239,7 +235,6 @@ public class SimHost(
.setDescription("The uptime of the host")
.setUnit("ms")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
/**
* The downtime of the host.
@@ -248,7 +243,6 @@ public class SimHost(
.setDescription("The downtime of the host")
.setUnit("ms")
.build()
- .bind(Attributes.of(ResourceAttributes.HOST_ID, uid.toString()))
init {
// Launch hypervisor onto machine
@@ -391,13 +385,28 @@ public class SimHost(
var state: ServerState = ServerState.TERMINATED
/**
+ * The attributes of the guest.
+ */
+ val attributes: Attributes = Attributes.builder()
+ .put(ResourceAttributes.HOST_NAME, server.name)
+ .put(ResourceAttributes.HOST_ID, server.uid.toString())
+ .put(ResourceAttributes.HOST_TYPE, server.flavor.name)
+ .put(AttributeKey.longKey("host.num_cpus"), server.flavor.cpuCount.toLong())
+ .put(AttributeKey.longKey("host.mem_capacity"), server.flavor.memorySize)
+ .put(AttributeKey.stringArrayKey("host.labels"), server.labels.map { (k, v) -> "$k:$v" })
+ .put(ResourceAttributes.HOST_ARCH, ResourceAttributes.HostArchValues.AMD64)
+ .put(ResourceAttributes.HOST_IMAGE_NAME, server.image.name)
+ .put(ResourceAttributes.HOST_IMAGE_ID, server.image.uid.toString())
+ .build()
+
+ /**
* The amount of time in the system.
*/
private val _totalTime = meter.counterBuilder("guest.time.total")
.setDescription("The amount of time in the system")
.setUnit("ms")
.build()
- .bind(Attributes.of(AttributeKey.stringKey("server.id"), server.uid.toString()))
+ .bind(attributes)
/**
* The uptime of the guest.
@@ -406,7 +415,7 @@ public class SimHost(
.setDescription("The uptime of the guest")
.setUnit("ms")
.build()
- .bind(Attributes.of(AttributeKey.stringKey("server.id"), server.uid.toString()))
+ .bind(attributes)
/**
* The time the guest is in an error state.
@@ -415,7 +424,7 @@ public class SimHost(
.setDescription("The time the guest is in an error state")
.setUnit("ms")
.build()
- .bind(Attributes.of(AttributeKey.stringKey("server.id"), server.uid.toString()))
+ .bind(attributes)
suspend fun start() {
when (state) {
diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
index 9fa8af34..318b5a5d 100644
--- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
+++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
@@ -49,6 +49,7 @@ import org.opendc.telemetry.sdk.toOtelClock
import java.time.Duration
import java.util.*
import kotlin.coroutines.resume
+import kotlin.math.roundToLong
/**
* Basic test-suite for the hypervisor.
@@ -72,7 +73,7 @@ internal class SimHostTest {
*/
@Test
fun testOvercommitted() = runBlockingSimulation {
- var requestedWork = 0L
+ var totalWork = 0L
var grantedWork = 0L
var overcommittedWork = 0L
@@ -89,7 +90,7 @@ internal class SimHostTest {
meta = emptyMap(),
coroutineContext,
interpreter,
- meterProvider.get("opendc-compute-simulator"),
+ meterProvider,
SimFairShareHypervisorProvider()
)
val duration = 5 * 60L
@@ -134,15 +135,10 @@ internal class SimHostTest {
object : MetricExporter {
override fun export(metrics: Collection<MetricData>): CompletableResultCode {
val metricsByName = metrics.associateBy { it.name }
- metricsByName["cpu.work.total"]?.let {
- requestedWork = it.doubleSumData.points.sumOf { point -> point.value }.toLong()
- }
- metricsByName["cpu.work.granted"]?.let {
- grantedWork = it.doubleSumData.points.sumOf { point -> point.value }.toLong()
- }
- metricsByName["cpu.work.overcommit"]?.let {
- overcommittedWork = it.doubleSumData.points.sumOf { point -> point.value }.toLong()
- }
+
+ totalWork = metricsByName.getValue("cpu.work.total").doubleSumData.points.first().value.roundToLong()
+ grantedWork = metricsByName.getValue("cpu.work.granted").doubleSumData.points.first().value.roundToLong()
+ overcommittedWork = metricsByName.getValue("cpu.work.overcommit").doubleSumData.points.first().value.roundToLong()
return CompletableResultCode.ofSuccess()
}
@@ -176,7 +172,7 @@ internal class SimHostTest {
reader.close()
assertAll(
- { assertEquals(4147200, requestedWork, "Requested work does not match") },
+ { assertEquals(4147200, totalWork, "Requested work does not match") },
{ assertEquals(2107200, grantedWork, "Granted work does not match") },
{ assertEquals(2040000, overcommittedWork, "Overcommitted work does not match") },
{ assertEquals(1500001, clock.millis()) }
@@ -188,7 +184,7 @@ internal class SimHostTest {
*/
@Test
fun testFailure() = runBlockingSimulation {
- var requestedWork = 0L
+ var totalWork = 0L
var grantedWork = 0L
var totalTime = 0L
var downTime = 0L
@@ -208,7 +204,7 @@ internal class SimHostTest {
meta = emptyMap(),
coroutineContext,
interpreter,
- meterProvider.get("opendc-compute-simulator"),
+ meterProvider,
SimFairShareHypervisorProvider()
)
val duration = 5 * 60L
@@ -237,24 +233,14 @@ internal class SimHostTest {
object : MetricExporter {
override fun export(metrics: Collection<MetricData>): CompletableResultCode {
val metricsByName = metrics.associateBy { it.name }
- metricsByName["cpu.work.total"]?.let {
- requestedWork = it.doubleSumData.points.sumOf { point -> point.value }.toLong()
- }
- metricsByName["cpu.work.granted"]?.let {
- grantedWork = it.doubleSumData.points.sumOf { point -> point.value }.toLong()
- }
- metricsByName["host.time.total"]?.let {
- totalTime = it.longSumData.points.first().value
- }
- metricsByName["host.time.down"]?.let {
- downTime = it.longSumData.points.first().value
- }
- metricsByName["guest.time.total"]?.let {
- guestTotalTime = it.longSumData.points.first().value
- }
- metricsByName["guest.time.error"]?.let {
- guestDownTime = it.longSumData.points.first().value
- }
+
+ totalWork = metricsByName.getValue("cpu.work.total").doubleSumData.points.first().value.roundToLong()
+ grantedWork = metricsByName.getValue("cpu.work.granted").doubleSumData.points.first().value.roundToLong()
+ totalTime = metricsByName.getValue("host.time.total").longSumData.points.first().value
+ downTime = metricsByName.getValue("host.time.down").longSumData.points.first().value
+ guestTotalTime = metricsByName.getValue("guest.time.total").longSumData.points.first().value
+ guestDownTime = metricsByName.getValue("guest.time.error").longSumData.points.first().value
+
return CompletableResultCode.ofSuccess()
}
@@ -290,8 +276,8 @@ internal class SimHostTest {
reader.close()
assertAll(
- { assertEquals(2226039, requestedWork, "Total time does not match") },
- { assertEquals(1086039, grantedWork, "Down time does not match") },
+ { assertEquals(2226040, totalWork, "Total time does not match") },
+ { assertEquals(1086040, grantedWork, "Down time does not match") },
{ assertEquals(1200001, totalTime, "Total time does not match") },
{ assertEquals(1200001, guestTotalTime, "Guest total time does not match") },
{ assertEquals(5000, downTime, "Down time does not match") },