diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-10-25 17:40:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-25 17:40:04 +0200 |
| commit | b4bf7268cbb6d22d3966f469a6b7721b04d91907 (patch) | |
| tree | 13756bd08650c0e41e24132b8dab0fad327ddf31 /opendc-trace/opendc-trace-azure/src/main | |
| parent | a41cd2504f15f3e3e49eb533faca390911cc5110 (diff) | |
| parent | c4ce5ebb7de6494cb8d90076cba8596aa0cbabeb (diff) | |
merge: Support conversion from Azure traces to OpenDC traces (#36)
This pull request adds support for converting Azure traces to the OpenDC trace format.
* Support GZIP files in Azure trace
* Fix timestamp retrieval for Azure trace
* Add column for CPU capacity in OpenDC format
* Support conversion from Azure trace format
Diffstat (limited to 'opendc-trace/opendc-trace-azure/src/main')
3 files changed, 14 insertions, 9 deletions
diff --git a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceStateTableReader.kt b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceStateTableReader.kt index da8181fe..94a91999 100644 --- a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceStateTableReader.kt +++ b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceStateTableReader.kt @@ -53,7 +53,7 @@ internal class AzureResourceStateTableReader(private val parser: CsvParser) : Ta when (parser.currentName) { "timestamp" -> timestamp = Instant.ofEpochSecond(parser.longValue) "vm id" -> id = parser.text - "CPU avg cpu" -> cpuUsagePct = parser.doubleValue + "CPU avg cpu" -> cpuUsagePct = (parser.doubleValue / 100.0) // Convert from % to [0, 1] } } diff --git a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceTableReader.kt b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceTableReader.kt index a6352613..6246dc35 100644 --- a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceTableReader.kt +++ b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureResourceTableReader.kt @@ -52,8 +52,8 @@ internal class AzureResourceTableReader(private val parser: CsvParser) : TableRe when (parser.currentName) { "vm id" -> id = parser.text - "vm created" -> startTime = Instant.ofEpochSecond(parser.longValue) - "vm deleted" -> stopTime = Instant.ofEpochSecond(parser.longValue) + "timestamp vm created" -> startTime = Instant.ofEpochSecond(parser.longValue) + "timestamp vm deleted" -> stopTime = Instant.ofEpochSecond(parser.longValue) "vm virtual core count" -> cpuCores = parser.intValue "vm memory" -> memCapacity = parser.doubleValue * 1e6 // GB to KB } diff --git a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt index 253c7057..c9982877 100644 --- a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt +++ b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt @@ -31,8 +31,9 @@ import org.opendc.trace.util.CompositeTableReader import java.nio.file.Files import java.nio.file.Path import java.util.stream.Collectors -import kotlin.io.path.extension -import kotlin.io.path.nameWithoutExtension +import java.util.zip.GZIPInputStream +import kotlin.io.path.inputStream +import kotlin.io.path.name /** * A format implementation for the Azure v1 format. @@ -81,7 +82,10 @@ public class AzureTraceFormat : TraceFormat { override fun newReader(path: Path, table: String): TableReader { return when (table) { - TABLE_RESOURCES -> AzureResourceTableReader(factory.createParser(path.resolve("vmtable/vmtable.csv").toFile())) + TABLE_RESOURCES -> { + val stream = GZIPInputStream(path.resolve("vmtable/vmtable.csv.gz").inputStream()) + AzureResourceTableReader(factory.createParser(stream)) + } TABLE_RESOURCE_STATES -> newResourceStateReader(path) else -> throw IllegalArgumentException("Table $table not supported") } @@ -96,8 +100,8 @@ public class AzureTraceFormat : TraceFormat { */ private fun newResourceStateReader(path: Path): TableReader { val partitions = Files.walk(path.resolve("vm_cpu_readings"), 1) - .filter { !Files.isDirectory(it) && it.extension == "csv" } - .collect(Collectors.toMap({ it.nameWithoutExtension }, { it })) + .filter { !Files.isDirectory(it) && it.name.endsWith(".csv.gz") } + .collect(Collectors.toMap({ it.name.removeSuffix(".csv.gz") }, { it })) .toSortedMap() val it = partitions.iterator() @@ -105,7 +109,8 @@ public class AzureTraceFormat : TraceFormat { override fun nextReader(): TableReader? { return if (it.hasNext()) { val (_, partPath) = it.next() - return AzureResourceStateTableReader(factory.createParser(partPath.toFile())) + val stream = GZIPInputStream(partPath.inputStream()) + return AzureResourceStateTableReader(factory.createParser(stream)) } else { null } |
