diff --git a/idea/performanceTests/build.gradle.kts b/idea/performanceTests/build.gradle.kts index ccc48bb2004..ffd90e07e36 100644 --- a/idea/performanceTests/build.gradle.kts +++ b/idea/performanceTests/build.gradle.kts @@ -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 { diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/Stats.kt b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/Stats.kt index be9d0fe8653..01d9dda1b44 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/Stats.kt +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/Stats.kt @@ -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 diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/ESUploader.kt b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/ESUploader.kt new file mode 100644 index 00000000000..fb5b24055f6 --- /dev/null +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/ESUploader.kt @@ -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}") + } + } +} \ No newline at end of file diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/Metric.kt b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/Metric.kt index e708c3130a1..569259addc5 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/Metric.kt +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/Metric.kt @@ -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") diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/aggregateResults.kt b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/aggregateResults.kt index 9ad67448fe7..7a23ee84d26 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/aggregateResults.kt +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/util/aggregateResults.kt @@ -25,6 +25,7 @@ fun main(args: Array) { 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) { metrics = it.metrics ?: emptyList() ) warmUpBenchmark.writeJson() + ESUploader.upload(warmUpBenchmark) } } } @@ -47,6 +49,7 @@ fun main(args: Array) { 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) { .filter { it.synthetic != true && it.warmUp != true } .forEach { geomMeanBenchmark.merge(it) } geomMeanBenchmark.writeJson() + ESUploader.upload(geomMeanBenchmark) } } \ No newline at end of file