-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor metrics * Make actuator optional * Use release version
- Loading branch information
Showing
31 changed files
with
161 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
...-server-starter/src/main/kotlin/com/bybutter/sisyphus/starter/grpc/MicrometerRegistrar.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...arter/src/main/kotlin/com/bybutter/sisyphus/starter/grpc/support/MicrometerInterceptor.kt
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
...server-starter/src/main/kotlin/com/bybutter/sisyphus/starter/grpc/support/RpcBinaryLog.kt
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...n/kotlin/com/bybutter/sisyphus/starter/grpc/support/metrics/MicrometerTimerInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.bybutter.sisyphus.starter.grpc.support.metrics | ||
|
||
import com.bybutter.sisyphus.starter.grpc.support.REQUEST_TIMESTAMP_CONTEXT_KEY | ||
import io.grpc.Context | ||
import io.grpc.Contexts | ||
import io.grpc.ForwardingServerCall | ||
import io.grpc.Metadata | ||
import io.grpc.ServerCall | ||
import io.grpc.ServerCallHandler | ||
import io.grpc.ServerInterceptor | ||
import io.grpc.Status | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import java.time.Duration | ||
|
||
/** | ||
* ServerInterceptor for micrometer timers, it will create two times for sisyphus, | ||
* 'sisyphus_grpc_requests' will statistics all requests, | ||
* 'sisyphus_grpc_incoming_requests' will statistics all incoming requests which has 'host' header and not be 'localhost'. | ||
*/ | ||
class MicrometerTimerInterceptor(private val registry: MeterRegistry) : ServerInterceptor { | ||
override fun <ReqT : Any, RespT : Any> interceptCall(call: ServerCall<ReqT, RespT>, headers: Metadata, next: ServerCallHandler<ReqT, RespT>): ServerCall.Listener<ReqT> { | ||
val host = headers.get(Metadata.Key.of("host", Metadata.ASCII_STRING_MARSHALLER))?.toString() | ||
return Contexts.interceptCall(Context.current(), ServerMicrometerCall(call, registry, host), headers, next) | ||
} | ||
|
||
private class ServerMicrometerCall<ReqT : Any, RespT : Any>(call: ServerCall<ReqT, RespT>, private val registry: MeterRegistry, private val host: String?) : ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) { | ||
override fun close(status: Status, trailers: Metadata) { | ||
val costDuration = Duration.ofNanos(System.nanoTime() - REQUEST_TIMESTAMP_CONTEXT_KEY.get()) | ||
|
||
registry.timer("sisyphus_grpc_requests", | ||
"service", delegate().methodDescriptor.serviceName, | ||
"method", delegate().methodDescriptor.fullMethodName, | ||
"status", status.code.name, | ||
"exception", status.cause?.javaClass?.name ?: "None" | ||
).record(costDuration) | ||
|
||
if (host != null && !host.startsWith("localhost")) { | ||
registry.timer("sisyphus_grpc_incoming_requests", | ||
"service", delegate().methodDescriptor.serviceName, | ||
"method", delegate().methodDescriptor.fullMethodName, | ||
"status", status.code.name, | ||
"exception", status.cause?.javaClass?.name ?: "None" | ||
).record(costDuration) | ||
} | ||
|
||
super.close(status, trailers) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...in/com/bybutter/sisyphus/starter/grpc/support/metrics/SisyphusMetricsAutoConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bybutter.sisyphus.starter.grpc.support.metrics | ||
|
||
import io.micrometer.core.instrument.MeterRegistry | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass | ||
import org.springframework.context.annotation.Bean | ||
|
||
@AutoConfigureAfter(name = [ | ||
"org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration", | ||
"org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration" | ||
]) | ||
@AutoConfigureBefore(name = ["org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration"]) | ||
@ConditionalOnClass(name = ["io.micrometer.core.instrument.MeterRegistry"]) | ||
class SisyphusMetricsAutoConfiguration { | ||
@Bean | ||
fun micrometerInterceptor(registry: MeterRegistry): MicrometerTimerInterceptor { | ||
return MicrometerTimerInterceptor(registry) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...starter/grpc/support/ReflectionService.kt → ...c/support/reflection/ReflectionService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/grpc/support/ReflectionServiceAlpha.kt → ...port/reflection/ReflectionServiceAlpha.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
starter/sisyphus-grpc-server-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
com.bybutter.sisyphus.starter.grpc.SisyphusGrpcServerAutoConfiguration | ||
com.bybutter.sisyphus.starter.grpc.SisyphusGrpcServerAutoConfiguration,\ | ||
com.bybutter.sisyphus.starter.grpc.support.metrics.SisyphusMetricsAutoConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/kotlin/com/bybutter/sisyphus/starter/grpc/transcoding/EnableHttpToGrpcTranscoding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...r/src/main/kotlin/com/bybutter/sisyphus/starter/grpc/transcoding/GrpcTranscodingConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...yphus/starter/grpc/transcoding/support/metrics/GrpcTranscodingMetricsAutoConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.bybutter.sisyphus.starter.grpc.transcoding.support.metrics | ||
|
||
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass | ||
import org.springframework.context.annotation.Bean | ||
|
||
@AutoConfigureAfter(name = [ | ||
"org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration", | ||
"org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration" | ||
]) | ||
@AutoConfigureBefore(name = ["org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration"]) | ||
@ConditionalOnClass(name = [ | ||
"org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor" | ||
]) | ||
class GrpcTranscodingMetricsAutoConfiguration { | ||
@Bean | ||
fun grpcTranscodingWebFluxTagsContributor(): WebFluxTagsContributor { | ||
return GrpcTranscodingWebFluxTagsContributor() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...isyphus/starter/grpc/transcoding/support/metrics/GrpcTranscodingWebFluxTagsContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.bybutter.sisyphus.starter.grpc.transcoding.support.metrics | ||
|
||
import com.bybutter.sisyphus.api.resource.PathTemplate | ||
import com.bybutter.sisyphus.starter.grpc.transcoding.TranscodingFunctions | ||
import io.grpc.MethodDescriptor | ||
import io.micrometer.core.instrument.Tag | ||
import io.micrometer.core.instrument.Tags | ||
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor | ||
import org.springframework.web.server.ServerWebExchange | ||
|
||
class GrpcTranscodingWebFluxTagsContributor : WebFluxTagsContributor { | ||
override fun httpRequestTags(exchange: ServerWebExchange, ex: Throwable?): MutableIterable<Tag> { | ||
val methodDescriptor = exchange.getAttribute<MethodDescriptor<*, *>>(TranscodingFunctions.METHOD_DESCRIPTOR_ATTRIBUTE) | ||
val pathTemplate = exchange.getAttribute<PathTemplate>(TranscodingFunctions.MATCHING_PATH_TEMPLATE_ATTRIBUTE) | ||
|
||
if (methodDescriptor == null || pathTemplate == null) { | ||
return Tags.of( | ||
"grpc_method", "None", | ||
"grpc_service", "None" | ||
) | ||
} | ||
|
||
return Tags.of( | ||
"grpc_method", methodDescriptor.fullMethodName, | ||
"grpc_service", methodDescriptor.serviceName, | ||
"uri", pathTemplate.toString() | ||
) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../SwaggerConfigArtifactPropertyExporter.kt → .../SwaggerConfigArtifactPropertyExporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pc/transcoding/swagger/SwaggerProperty.kt → ...coding/support/swagger/SwaggerProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
...nscoding/swagger/SwaggerRouterFunction.kt → .../support/swagger/SwaggerRouterFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../authentication/DefaultSwaggerValidate.kt → .../authentication/DefaultSwaggerValidate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...swagger/authentication/SwaggerValidate.kt → ...swagger/authentication/SwaggerValidate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oding/swagger/utils/SwaggerDescription.kt → ...pport/swagger/utils/SwaggerDescription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.