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

finagle-core: Use configured deadline params #937

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,34 @@ object DynamicTimeout {
* @see [[LatencyCompensation]]
*/
def perRequestModule[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
new Stack.Module3[
TimeoutFilter.Param,
param.Timer,
LatencyCompensation.Compensation,
new Stack.ModuleParams[
ServiceFactory[Req, Rep]
] {
val role: Stack.Role = TimeoutFilter.role
val description: String =
"Apply a dynamic timeout-derived deadline to request"

def make(
defaultTimeout: TimeoutFilter.Param,
timer: param.Timer,
compensation: LatencyCompensation.Compensation,
next: ServiceFactory[Req, Rep]
): ServiceFactory[Req, Rep] = {
val parameters = Seq(
implicitly[Stack.Param[TimeoutFilter.Param]],
implicitly[Stack.Param[param.Timer]],
implicitly[Stack.Param[LatencyCompensation.Compensation]],
implicitly[Stack.Param[TimeoutFilter.PropagateDeadlines]],
implicitly[Stack.Param[TimeoutFilter.PreferDeadlineOverTimeout]]
)

override def make(params: Stack.Params, next: ServiceFactory[Req, Rep]): ServiceFactory[Req, Rep] = {

val filter = new TimeoutFilter[Req, Rep](
timeoutFn(
PerRequestKey,
defaultTimeout.tunableTimeout,
params[TimeoutFilter.Param].tunableTimeout,
TimeoutFilter.Param.Default, // tunableTimeout() should always produce a value,
compensation.howlong // but we fall back on the default if not
params[LatencyCompensation.Compensation].howlong // but we fall back on the default if not
),
duration => new IndividualRequestTimeoutException(duration),
timer.timer
params[param.Timer].timer,
params[TimeoutFilter.PropagateDeadlines].enabled,
params[TimeoutFilter.PreferDeadlineOverTimeout].enabled
)
filter.andThen(next)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import com.twitter.finagle.server.StackServer
import com.twitter.finagle.util.DefaultTimer
import com.twitter.finagle.mux
import com.twitter.finagle._
import com.twitter.util.Await
import com.twitter.util.Future
import com.twitter.finagle.service.TimeoutFilter.PropagateDeadlines
import com.twitter.util.Closable.close
import com.twitter.util.{Await, Closable, Future}

import java.net.InetSocketAddress
import org.scalatest.funsuite.AnyFunSuite

import java.util.concurrent.atomic.AtomicBoolean

class MethodBuilderTest extends AnyFunSuite {

private def await[T](f: Future[T]): T = Await.result(f, 15.seconds)
Expand Down Expand Up @@ -153,4 +157,37 @@ class MethodBuilderTest extends AnyFunSuite {
mux.Request.empty,
mux.Response.empty
)

test("Methodbuilder client does not propagate Deadlines") {
val deadlinePresent = new AtomicBoolean(true)
val service = Service.mk { request: http.Request =>
deadlinePresent.set(request.headerMap.get("Finagle-Ctx-com.twitter.finagle.Deadline").isDefined)
Future.value(http.Response())
}

val server = Http.server
.serve("localhost:*", service)
val addr = server.boundAddress.asInstanceOf[InetSocketAddress]

val noPropagationClient = Http.client
.withLabel("backend-noprop")
.configured(PropagateDeadlines(false).mk())
.methodBuilder(s"${addr.getHostName}:${addr.getPort}")
.newService

val defaultClient = Http.client
.withLabel("backend")
.methodBuilder(s"${addr.getHostName}:${addr.getPort}")
.newService

await(noPropagationClient(http.Request("/")))
assert(!deadlinePresent.get())
await(defaultClient(http.Request("/")))
assert(deadlinePresent.get())

await(server.close())
await(noPropagationClient.close())
await(defaultClient.close())
}

}
Loading