Skip to content

Commit d963409

Browse files
authored
Add @ExperimentalMiskApi (#3272)
Shamelessly cribbed from [ExperimentalOkHttpApi](https://github.com/square/okhttp/blob/54238b4c713080c3fd32fb1a070fb5d6814c9a09/okhttp/src/main/kotlin/okhttp3/ExperimentalOkHttpApi.kt), this new annotation will allow us to better communicate the unstable nature of new public classes and methods. This will allow us to more rapidly iterate on these features without worrying as much about breaking changes, which is good both for code authors and reviewers. It's also good for Misk users who will have a clearer signal about what is and isn't safe to start using. This PR also demonstrates usage of the annotation by applying it to `TaggedLogger`, a class which was created recently and is being iterated on [right now](#3270).
1 parent 54c6bef commit d963409

File tree

10 files changed

+53
-1
lines changed

10 files changed

+53
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ The Changelog consequently will not be updated regularly since releases only inc
77

88
Major and breaking changes will still be documented in the Changelog.
99

10+
Version 2024.05.22
11+
---------------------------------
12+
Breaking changes:
13+
- Added `@ExperimentalMiskApi` to `TaggedLogger`. Any code that uses this class will need to `@OptIn(ExperimentalMiskApi::class)`.
14+
1015
Version 2024.05.16
1116
---------------------------------
1217
Breaking changes:

misk-api/api/misk-api.api

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
public abstract interface annotation class misk/annotation/ExperimentalMiskApi : java/lang/annotation/Annotation {
2+
}
3+
14
public abstract interface class misk/api/HttpRequest {
25
public abstract fun getDispatchMechanism ()Lmisk/web/DispatchMechanism;
36
public abstract fun getRequestHeaders ()Lokhttp3/Headers;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package misk.annotation
2+
3+
/**
4+
* Marks declarations that are experimental and subject to change without following SemVer
5+
* conventions. Both binary and source-incompatible changes are possible, including complete removal
6+
* of the experimental API.
7+
*
8+
* Do not use these APIs in modules that may be executed using a version of Misk different from
9+
* the version the module was compiled with.
10+
*
11+
* Do not use these APIs in published libraries.
12+
*
13+
* Do not use these APIs if you aren't willing to track changes to them.
14+
*/
15+
@MustBeDocumented
16+
@Retention(value = AnnotationRetention.BINARY)
17+
@Target(
18+
AnnotationTarget.CLASS,
19+
AnnotationTarget.ANNOTATION_CLASS,
20+
AnnotationTarget.PROPERTY,
21+
AnnotationTarget.FIELD,
22+
AnnotationTarget.LOCAL_VARIABLE,
23+
AnnotationTarget.VALUE_PARAMETER,
24+
AnnotationTarget.CONSTRUCTOR,
25+
AnnotationTarget.FUNCTION,
26+
AnnotationTarget.PROPERTY_GETTER,
27+
AnnotationTarget.PROPERTY_SETTER,
28+
AnnotationTarget.TYPEALIAS,
29+
)
30+
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
31+
annotation class ExperimentalMiskApi

misk-aws/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies {
3030
implementation(libs.prometheusClient)
3131
implementation(libs.slf4jApi)
3232
implementation(libs.tracingDatadog)
33+
implementation(project(":misk-api"))
3334
implementation(project(":wisp:wisp-deployment"))
3435
implementation(project(":wisp:wisp-logging"))
3536
implementation(project(":wisp:wisp-tracing"))

misk-aws/src/main/kotlin/misk/jobqueue/sqs/SqsJobConsumer.kt

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import io.opentracing.tag.StringTag
1111
import io.opentracing.tag.Tags
1212
import jakarta.inject.Inject
1313
import jakarta.inject.Singleton
14+
import misk.annotation.ExperimentalMiskApi
1415
import misk.feature.Feature
1516
import misk.feature.FeatureFlags
1617
import misk.jobqueue.JobConsumer
@@ -182,6 +183,7 @@ internal class SqsJobConsumer @Inject internal constructor(
182183
}.join()
183184
}
184185

186+
@OptIn(ExperimentalMiskApi::class)
185187
private fun handleMessages(messages: List<SqsJob>): List<CompletableFuture<Status>> {
186188
return messages.map { message ->
187189
CompletableFuture.supplyAsync(

misk-aws/src/test/kotlin/misk/jobqueue/sqs/TaggedLoggerJobQueueTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent
55
import com.amazonaws.services.sqs.AmazonSQS
66
import com.amazonaws.services.sqs.model.CreateQueueRequest
77
import jakarta.inject.Inject
8+
import misk.annotation.ExperimentalMiskApi
89
import misk.clustering.fake.lease.FakeLeaseManager
910
import misk.inject.KAbstractModule
1011
import misk.jobqueue.JobQueue
@@ -160,6 +161,7 @@ internal class TaggedLoggerJobQueueTest {
160161
val normalLogger = getLogger<TaggedLoggerJobQueueTest>()
161162
}
162163

164+
@OptIn(ExperimentalMiskApi::class)
163165
data class SqsJobQueueTestTaggedLogger<L: Any>(val logClass: KClass<L>, val tags: Set<Tag> = emptySet()): TaggedLogger<L, SqsJobQueueTestTaggedLogger<L>>(logClass, tags),
164166
Copyable<SqsJobQueueTestTaggedLogger<L>> {
165167
fun testTag(value: String) = tag(Tag("testTag", value))

misk/src/main/kotlin/misk/web/exceptions/ExceptionHandlingInterceptor.kt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.squareup.wire.GrpcStatus
55
import com.squareup.wire.ProtoAdapter
66
import jakarta.inject.Inject
77
import misk.Action
8+
import misk.annotation.ExperimentalMiskApi
89
import misk.exceptions.UnauthenticatedException
910
import misk.exceptions.UnauthorizedException
1011
import misk.grpc.GrpcMessageSink
@@ -45,6 +46,7 @@ class ExceptionHandlingInterceptor(
4546
private val mapperResolver: ExceptionMapperResolver
4647
) : NetworkInterceptor {
4748

49+
@OptIn(ExperimentalMiskApi::class)
4850
override fun intercept(chain: NetworkChain) {
4951
try {
5052
chain.proceed(chain.httpCall)

misk/src/test/kotlin/misk/web/exceptions/TaggedLoggerExceptionHandlingInterceptorTest.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
@file:OptIn(ExperimentalMiskApi::class)
2+
13
package misk.web.exceptions
24

35
import ch.qos.logback.classic.Level
46
import com.google.common.testing.FakeTicker
57
import jakarta.inject.Inject
68
import misk.MiskTestingServiceModule
9+
import misk.annotation.ExperimentalMiskApi
710
import misk.inject.KAbstractModule
811
import misk.logging.LogCollectorModule
912
import misk.web.exceptions.TaggedLoggerExceptionHandlingInterceptorTest.LogMDCContextTestAction.LogMDCContextTestActionLogger.Companion.getTaggedLogger

wisp/wisp-logging/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ dependencies {
66
api(libs.kotlinLogging)
77
api(libs.slf4jApi)
88
api(project(":wisp:wisp-sampling"))
9+
10+
implementation(project(":misk-api"))
911

1012
testImplementation(libs.assertj)
1113
testImplementation(libs.junitApi)

wisp/wisp-logging/src/main/kotlin/wisp/logging/TaggedLogger.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package wisp.logging
22

3+
import misk.annotation.ExperimentalMiskApi
34
import mu.KLogger
45
import mu.KotlinLogging
56
import org.slf4j.MDC
@@ -74,7 +75,7 @@ import kotlin.reflect.KClass
7475
*
7576
*/
7677

77-
78+
@ExperimentalMiskApi
7879
abstract class TaggedLogger<L:Any, out R> (
7980
private val kLogger: KLogger,
8081
private val tags: Set<Tag>

0 commit comments

Comments
 (0)