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
Add a client_state.json admin endpoint to expose the client address set #1768
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.twitter.finagle.client.buoyant | ||
|
||
import com.twitter.finagle.{Addr, Address, Service} | ||
import com.twitter.finagle.client.ClientRegistry | ||
import com.twitter.finagle.http.{MediaType, Request, Response} | ||
import com.twitter.finagle.loadbalancer.LoadBalancerFactory | ||
import com.twitter.util.Future | ||
import io.buoyant.config.Parser | ||
|
||
class ClientStateHandler extends Service[Request, Response] { | ||
|
||
private[this] val mapper = Parser.jsonObjectMapper(Nil) | ||
|
||
override def apply(request: Request): Future[Response] = { | ||
val entries = ClientRegistry.registrants.map { entry => | ||
val LoadBalancerFactory.Dest(va) = entry.params[LoadBalancerFactory.Dest] | ||
va.changes.toFuture().map(entry.addr -> _) | ||
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. Why |
||
} | ||
Future.collect(entries.toSeq).map { entries => | ||
val clientState = entries.map { | ||
case (client, addr) => | ||
val state = addr match { | ||
case Addr.Bound(addresses, meta) => | ||
addresses.map { | ||
case Address.Inet(isa, _) => isa.getHostString | ||
case a => a.toString | ||
}.toSeq | ||
case Addr.Failed(why) => s"Failed: ${why.getMessage}" | ||
case a@Addr.Pending => a.toString | ||
case a@Addr.Neg => a.toString | ||
} | ||
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. wait what is the type of Perhaps better to have a case class that encodes e.g. |
||
client -> state | ||
}.toMap | ||
|
||
val response = Response() | ||
response.contentType = MediaType.Json + ";charset=UTF-8" | ||
response.contentString = mapper.writeValueAsString(clientState) | ||
response | ||
} | ||
} | ||
} |
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.
can we limit this to entries where entry.addr is a
Name
orPath
so that we don't encode weird things for clients that don't do name resolution?