From 776b68f2fedc6092fbd99fcaca5def3787102d72 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Fri, 26 Aug 2022 11:37:42 +0200 Subject: [PATCH] [K/N] Move aws address for perf infra from code to environment --- .../src/main/kotlin/main.kt | 32 +++++++++++-------- .../kotlin/network/aws/AWSNetworkUtils.kt | 9 ++---- .../src/main/kotlin/routes/route.kt | 12 ++----- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/kotlin-native/tools/performance-server/src/main/kotlin/main.kt b/kotlin-native/tools/performance-server/src/main/kotlin/main.kt index f6933632698..8c76e121db7 100644 --- a/kotlin-native/tools/performance-server/src/main/kotlin/main.kt +++ b/kotlin-native/tools/performance-server/src/main/kotlin/main.kt @@ -1,19 +1,10 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2022 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. */ +import org.jetbrains.network.* + external fun require(module: String): dynamic external val process: dynamic @@ -42,7 +33,20 @@ fun main(args: Array) { println("App listening on port " + port + "!") }) - app.use("/", router()) + val connector = if (process.env.LOCAL_AWS != null && process.env.LOCAL_AWS != kotlin.js.undefined) { + println("Using local aws instance") + UrlNetworkConnector("http://localhost", 9200) + } else { + val host = process.env.AWS_HOST + val region = process.env.AWS_REGION + if (host !is String) throw IllegalStateException("AWS_HOST env variable is not defined") + if (region !is String) throw IllegalStateException("AWS_REGION env variable is not defined") + AWSNetworkConnector( + host, region + ) + } + + app.use("/", router(connector)) } fun normalizePort(port: Int) = diff --git a/kotlin-native/tools/performance-server/src/main/kotlin/network/aws/AWSNetworkUtils.kt b/kotlin-native/tools/performance-server/src/main/kotlin/network/aws/AWSNetworkUtils.kt index d07750d49ae..e9893107732 100644 --- a/kotlin-native/tools/performance-server/src/main/kotlin/network/aws/AWSNetworkUtils.kt +++ b/kotlin-native/tools/performance-server/src/main/kotlin/network/aws/AWSNetworkUtils.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * Copyright 2010-2022 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.network @@ -57,10 +57,7 @@ external object AWSInstance { } // Network connector to work with AWS resources. -class AWSNetworkConnector : NetworkConnector() { - val AWSDomain = "vpc-kotlin-perf-service-5e6ldakkdv526ii5hbclzcmpny.eu-west-1.es.amazonaws.com" - val AWSRegion = "eu-west-1" - +class AWSNetworkConnector(val AWSDomain: String, val AWSRegion: String) : NetworkConnector() { override fun sendBaseRequest(method: RequestMethod, path: String, user: String?, password: String?, acceptJsonContentType: Boolean, body: String?, errorHandler: (url: String, response: dynamic) -> Nothing?): Promise { diff --git a/kotlin-native/tools/performance-server/src/main/kotlin/routes/route.kt b/kotlin-native/tools/performance-server/src/main/kotlin/routes/route.kt index 7be0f0996d0..c01283e66c0 100644 --- a/kotlin-native/tools/performance-server/src/main/kotlin/routes/route.kt +++ b/kotlin-native/tools/performance-server/src/main/kotlin/routes/route.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * Copyright 2010-2022 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. */ import org.w3c.xhr.* @@ -216,17 +216,11 @@ internal fun orderedValues(values: List, buildElement: (T) -> CompositeBu ) ) -// ElasticSearch connector for work with custom instance. -internal val localHostElasticConnector = UrlNetworkConnector("http://localhost", 9200) -// ElasticSearch connector for work with AWS instance. -internal val awsElasticConnector = AWSNetworkConnector() -internal val networkConnector = awsElasticConnector - fun urlParameterToBaseFormat(value: dynamic) = value.toString().replace("_", " ") // Routing of requests to current server. -fun router() { +fun router(networkConnector: NetworkConnector) { val express = require("express") val router = express.Router() val connector = ElasticSearchConnector(networkConnector)