Skip to content
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

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ subprojects {
apply plugin: 'com.diffplug.spotless'

if (project.name != 'micrometer-bom') {
if (project.name.contains('samples') || project.name.contains('benchmarks')) {
if ((project.name.contains('samples') && !project.name.contains('kotlin')) || project.name.contains('benchmarks')) {
apply plugin: 'java'
} else {
apply plugin: 'java-library'
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mockito = "5.5.0"
mongo = "4.8.2"
netty = "4.1.104.Final"
newrelic-api = "5.14.0"
okhttp = "5.0.0-alpha.11" # TODO is compiling against an alpha version intentional?
okhttp = "4.11.0"
Copy link
Member

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.

postgre = "42.5.4"
prometheus = "0.16.0"
reactor = "2020.0.39"
Expand Down Expand Up @@ -198,3 +198,7 @@ plugin-javaformat = { module = "io.spring.javaformat:spring-javaformat-gradle-pl
plugin-japicmp = { module = "me.champeau.gradle:japicmp-gradle-plugin", version = "0.4.2" }
plugin-downloadTask = { module = "de.undercouch:gradle-download-task", version = "5.5.0" }
plugin-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.22.0" }

[plugins]
kotlin19 = { id = "org.jetbrains.kotlin.jvm", version = "1.9.22" }
kotlin17 = { id = "org.jetbrains.kotlin.jvm", version = "1.7.22" }
3 changes: 2 additions & 1 deletion micrometer-core/build.gradle
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)
Copy link
Member

Choose a reason for hiding this comment

The 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"
}

Expand Down Expand Up @@ -82,6 +82,7 @@ dependencies {
optionalApi 'io.micrometer:context-propagation'

// kotlin
optionalApi enforcedPlatform('org.jetbrains.kotlin:kotlin-bom')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistently enforces the kotlin library versions match the plugin version. Without enforcedPlatform, Gradle was resolving higher versions than we wanted.

optionalApi 'org.jetbrains.kotlin:kotlin-reflect'
optionalApi 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
optionalApi 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public B maximumExpectedValue(@Nullable Duration max) {
* over time to give greater weight to recent samples (exception: histogram counts are
* cumulative for those systems that expect cumulative histogram buckets). Samples are
* accumulated to such statistics in ring buffers which rotate after this expiry, with
* a buffer length of {@link #distributionStatisticBufferLength(Integer)}.
* a buffer length of {@link #distributionStatisticBufferLength(Integer)}, hence
* complete expiry happens after this expiry * buffer length.
* @param expiry The amount of time samples are accumulated to a histogram before it
* is reset and rotated.
* @return This builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public Double getMaximumExpectedValueAsDouble() {
* greater weight to recent samples (exception: histogram counts are cumulative for
* those systems that expect cumulative histogram buckets). Samples are accumulated to
* such statistics in ring buffers which rotate after this expiry, with a buffer
* length of {@link #bufferLength}.
* length of {@link #bufferLength}, hence complete expiry happens after this expiry *
* buffer length.
* @return The amount of time samples are accumulated to a histogram before it is
* reset and rotated.
*/
Expand Down Expand Up @@ -426,7 +427,8 @@ public Builder maximumExpectedValue(@Nullable Double max) {
* greater weight to recent samples (exception: histogram counts are cumulative
* for those systems that expect cumulative histogram buckets). Samples are
* accumulated to such statistics in ring buffers which rotate after this expiry,
* with a buffer length of {@link #bufferLength}.
* with a buffer length of {@link #bufferLength}, hence complete expiry happens
* after this expiry * buffer length.
* @param expiry The amount of time samples are accumulated to decaying
* distribution statistics before they are reset and rotated.
* @return This builder.
Expand Down
19 changes: 19 additions & 0 deletions samples/micrometer-samples-kotlin/build.gradle
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
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gradleEnterprise {

include 'micrometer-commons', 'micrometer-core', 'micrometer-observation'

['core', 'boot2', 'boot2-reactive', 'spring-integration', 'hazelcast', 'hazelcast3', 'javalin', 'jersey3'].each { sample ->
['core', 'boot2', 'boot2-reactive', 'spring-integration', 'hazelcast', 'hazelcast3', 'javalin', 'jersey3', 'kotlin'].each { sample ->
include "micrometer-samples-$sample"
project(":micrometer-samples-$sample").projectDir = new File(rootProject.projectDir, "samples/micrometer-samples-$sample")
}
Expand Down