-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downgrade to OkHttp 4.11.0 #4582
Changes from all commits
c790b47
6f61874
4be5f78
6c8aeb1
7993ce7
81aca1c
e111c98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.jvm" version "1.7.22" | ||
alias(libs.plugins.kotlin17) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will continue using the same Kotlin plugin version. We don't want to upgrade the minor version in a maintenance release. |
||
id 'me.champeau.mrjar' version "0.1.1" | ||
} | ||
|
||
|
@@ -82,6 +82,7 @@ dependencies { | |
optionalApi 'io.micrometer:context-propagation' | ||
|
||
// kotlin | ||
optionalApi enforcedPlatform('org.jetbrains.kotlin:kotlin-bom') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistently enforces the kotlin library versions match the plugin version. Without |
||
optionalApi 'org.jetbrains.kotlin:kotlin-reflect' | ||
optionalApi 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' | ||
optionalApi 'org.jetbrains.kotlinx:kotlinx-coroutines-core' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
// test with the highest version of Kotlin supported because we compile with oldest version supported | ||
alias(libs.plugins.kotlin19) | ||
} | ||
|
||
dependencies { | ||
// libraries that have Kotlin dependencies | ||
implementation project(":micrometer-core") | ||
implementation libs.kotlinxCoroutines | ||
// force the stdlib versions to match the plugin version for this sample | ||
implementation enforcedPlatform('org.jetbrains.kotlin:kotlin-bom') | ||
implementation libs.okhttp | ||
|
||
testRuntimeOnly libs.contextPropagation | ||
|
||
testImplementation libs.junitJupiter | ||
testImplementation libs.assertj | ||
testImplementation project(":micrometer-test") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 VMware, Inc. | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
package io.micrometer.samples.kotlin | ||
|
||
import io.micrometer.core.instrument.kotlin.asContextElement | ||
import io.micrometer.core.instrument.kotlin.currentObservation | ||
import io.micrometer.observation.Observation | ||
import io.micrometer.observation.ObservationRegistry | ||
import kotlinx.coroutines.* | ||
import org.assertj.core.api.BDDAssertions | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class KotlinCoroutinesTests { | ||
|
||
val observationRegistry = ObservationRegistry.create() | ||
|
||
@Test | ||
fun `should return current observation from context`(): Unit = runBlocking { | ||
observationRegistry.observationConfig().observationHandler { true } | ||
val nextObservation = Observation.start("name", observationRegistry) | ||
val inScope = nextObservation.openScope() | ||
var observationInGlobalScopeLaunch: Observation? = null | ||
var observationInGlobalScopeAsync: Observation? = null | ||
val asContextElement = observationRegistry.asContextElement() | ||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
GlobalScope.launch(asContextElement) { | ||
observationInGlobalScopeLaunch = coroutineContext.currentObservation() | ||
} | ||
@OptIn(DelicateCoroutinesApi::class) | ||
GlobalScope.async(asContextElement) { | ||
observationInGlobalScopeAsync = coroutineContext.currentObservation() | ||
}.await() | ||
|
||
inScope.close() | ||
|
||
BDDAssertions.then(observationInGlobalScopeLaunch).isSameAs(nextObservation) | ||
BDDAssertions.then(observationInGlobalScopeAsync).isSameAs(nextObservation) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 VMware, Inc. | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
package io.micrometer.samples.kotlin | ||
|
||
import io.micrometer.core.instrument.HttpClientTimingInstrumentationVerificationTests | ||
import io.micrometer.core.instrument.binder.okhttp3.OkHttpMetricsEventListener | ||
import io.micrometer.core.instrument.binder.okhttp3.OkHttpObservationDocumentation | ||
import io.micrometer.core.instrument.binder.okhttp3.OkHttpObservationInterceptor | ||
import io.micrometer.observation.docs.ObservationDocumentation | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import java.io.IOException | ||
import java.net.URI | ||
|
||
internal class OkHttpClientTimingInstrumentationVerificationTests : | ||
HttpClientTimingInstrumentationVerificationTests<OkHttpClient>() { | ||
|
||
override fun sendHttpRequest( | ||
instrumentedClient: OkHttpClient, | ||
method: HttpMethod, | ||
body: ByteArray?, | ||
baseUri: URI, | ||
templatedPath: String, | ||
vararg pathVariables: String?, | ||
) { | ||
val request: Request = Request.Builder().method(method.name, body?.toRequestBody()) | ||
.url(baseUri.toString() + substitutePathVariables(templatedPath, *pathVariables)) | ||
.header(OkHttpMetricsEventListener.URI_PATTERN, templatedPath) | ||
.build() | ||
try { | ||
instrumentedClient.newCall(request).execute().use { } | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun clientInstrumentedWithMetrics(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.eventListener(OkHttpMetricsEventListener.builder(registry, timerName()).build()) | ||
.build() | ||
} | ||
|
||
override fun clientInstrumentedWithObservations(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.addInterceptor(OkHttpObservationInterceptor.builder(observationRegistry, timerName()).build()) | ||
.build() | ||
} | ||
|
||
override fun observationDocumentation(): ObservationDocumentation { | ||
return OkHttpObservationDocumentation.DEFAULT | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downgraded from 4.12.0 to 4.11.0. This better matches the 5.0 alpha we were compiling against in terms of Kotlin dependencies.