Add uploading IDE performance benchmarks to ES

This commit is contained in:
Vladimir Dolzhenko
2020-11-09 12:01:55 +01:00
parent ff7c38b2df
commit e101e6762c
5 changed files with 62 additions and 0 deletions
+1
View File
@@ -38,6 +38,7 @@ dependencies {
testImplementation(commonDep("junit:junit"))
testImplementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.+")
testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.+")
testImplementation("khttp:khttp:1.0.0")
Platform[192].orHigher {
@@ -359,6 +359,7 @@ class Stats(
var buildId: Int? = null
var agentName: String? = null
var buildBranch: String? = null
var commit: String? = null
System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")?.let { teamcityConfig ->
val buildProperties = Properties()
@@ -367,6 +368,7 @@ class Stats(
buildId = buildProperties["teamcity.build.id"]?.toString()?.toInt()
agentName = buildProperties["agent.name"]?.toString()
buildBranch = buildProperties["teamcity.build.branch"]?.toString()
commit = buildProperties["build.vcs.number"]?.toString()
}
if (perfTestRawDataMs.isNotEmpty()) {
@@ -379,6 +381,7 @@ class Stats(
val benchmark = Benchmark(
agentName = agentName,
buildBranch = buildBranch,
commit = commit,
buildId = buildId,
benchmark = name,
name = it.metricName,
@@ -389,6 +392,7 @@ class Stats(
)
benchmark.writeJson()
ESUploader.upload(benchmark)
}
} finally {
metric = null
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.perf.util
import khttp.structures.authorization.BasicAuthorization
import java.io.FileInputStream
import java.util.*
object ESUploader {
var host: String? = null
var username: String? = null
var password: String? = null
var indexName = "kotlin_ide_benchmarks"
init {
host = System.getenv("es.hostname")
username = System.getenv("es.username")
password = System.getenv("es.password")
logMessage { "initialized es details $username @ $host" }
}
fun upload(benchmark: Benchmark) {
if (host == null) {
logMessage { "ES host is not specified, ${benchmark.id()} would not be uploaded" }
return
}
val url = "$host/$indexName/_doc/${benchmark.id()}"
val auth = if (username != null && password != null) {
BasicAuthorization(username!!, password!!)
} else {
null
}
val json = kotlinJsonMapper.writeValueAsString(benchmark)
val response = khttp.put(
url = url,
auth = auth,
headers = mapOf("Content-Type" to "application/json"),
data = json
)
logMessage { "${response.statusCode} -> ${response.jsonObject}" }
if (response.statusCode != 200 && response.statusCode != 201) {
throw IllegalStateException("Error code ${response.statusCode} -> ${response.text}")
}
}
}
@@ -30,6 +30,8 @@ data class Benchmark(
var buildTimestamp: String,
@set:JsonProperty("buildBranch")
var buildBranch: String?,
@set:JsonProperty("commit")
var commit: String? = null,
@set:JsonProperty("buildId")
var buildId: Int?,
@set:JsonProperty("metricValue")
@@ -25,6 +25,7 @@ fun main(args: Array<String>) {
val warmUpBenchmark = Benchmark(
agentName = benchmark.agentName,
buildBranch = benchmark.buildBranch,
commit = benchmark.commit,
buildId = benchmark.buildId,
benchmark = benchmark.benchmark,
name = benchmark.name,
@@ -37,6 +38,7 @@ fun main(args: Array<String>) {
metrics = it.metrics ?: emptyList()
)
warmUpBenchmark.writeJson()
ESUploader.upload(warmUpBenchmark)
}
}
}
@@ -47,6 +49,7 @@ fun main(args: Array<String>) {
val geomMeanBenchmark = Benchmark(
agentName = loadBenchmark.agentName,
buildBranch = loadBenchmark.buildBranch,
commit = loadBenchmark.commit,
buildId = loadBenchmark.buildId,
benchmark = loadBenchmark.benchmark,
synthetic = true,
@@ -58,5 +61,6 @@ fun main(args: Array<String>) {
.filter { it.synthetic != true && it.warmUp != true }
.forEach { geomMeanBenchmark.merge(it) }
geomMeanBenchmark.writeJson()
ESUploader.upload(geomMeanBenchmark)
}
}