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-redis: Add the RedisTracingFilter and RedisLoggingFilter back into the default Redis Stack #866

Closed
wants to merge 3 commits into from

Conversation

rpless
Copy link
Contributor

@rpless rpless commented Jul 17, 2020

Problem

I was experimenting with the Tracing module and instrumented a Redis Client. I noticed that Redis rpc calls did not get named unlike the Http calls that were being traced. After some discussion on gitter, @mosesn pointed out that a commit where the RedisLoggingFilter and RedisTracingFilter had been ported during the move from Netty 3 -> Netty 4, but had not been added back to the stack.

Solution

I added the RedisLoggingFilter and the RedisTracingFilter to the default client stack.

Result

This will add stats and tracing back to the Redis Client by default.

I followed the mysql client for adding the role and module definitions. If there as a better way to do this let me know and I can change it.

@CLAassistant
Copy link

CLAassistant commented Jul 17, 2020

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2020

Codecov Report

Merging #866 into develop will increase coverage by 0.01%.
The diff coverage is 75.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #866      +/-   ##
===========================================
+ Coverage    78.19%   78.20%   +0.01%     
===========================================
  Files          829      829              
  Lines        24452    24468      +16     
  Branches      1580     1584       +4     
===========================================
+ Hits         19120    19135      +15     
- Misses        5332     5333       +1     
Impacted Files Coverage Δ
...tter/finagle/redis/filter/RedisLoggingFilter.scala 33.33% <62.50%> (+33.33%) ⬆️
...tter/finagle/redis/filter/RedisTracingFilter.scala 38.46% <83.33%> (+38.46%) ⬆️
...dis/src/main/scala/com/twitter/finagle/Redis.scala 32.65% <100.00%> (+2.86%) ⬆️
.../com/twitter/finagle/tracing/BroadcastTracer.scala 60.41% <0.00%> (-10.42%) ⬇️
...om/twitter/finagle/dispatch/ServerDispatcher.scala 85.10% <0.00%> (+2.12%) ⬆️
...2/transport/common/Http2StreamMessageHandler.scala 94.87% <0.00%> (+2.56%) ⬆️
...r/finagle/dispatch/GenSerialClientDispatcher.scala 82.75% <0.00%> (+3.44%) ⬆️
...rverset2/client/apache/ApacheKeeperException.scala 14.81% <0.00%> (+3.70%) ⬆️
...m/twitter/finagle/partitioning/zk/ZkMetadata.scala 95.83% <0.00%> (+4.16%) ⬆️
.../http/exp/GenStreamingSerialServerDispatcher.scala 77.08% <0.00%> (+6.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9107f6...d45d770. Read the comment docs.

@rpless
Copy link
Contributor Author

rpless commented Jul 18, 2020

Realized I pushed with an old work account which is why the CLA wasn't showing up as signed. Fixed by pushing the same commit over the original one but associated with the correct email.

if (statsParam.statsReceiver.isNull)
next
else
new RedisLoggingFilter(statsParam.statsReceiver.scope("http")).andThen(next)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect the scope isn't really supposed to be "http".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes this looks copy-paste on my part, the original commit does not seem to add a scope. I can remove it. Alternatively some modules seem to scope the receiver to the protocol name like http so I could change it to that if it makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect we want to follow what was originally there. It would normally be the job of whoever passes the stats receiver to us to define the scope, and if we need to go deeper this module would be in charge of naming that scope and passing it on.

@@ -72,6 +73,8 @@ object Redis extends Client[Command, Reply] with RedisRichClient {
private val stack: Stack[ServiceFactory[Command, Reply]] = StackClient.newStack
.insertBefore(DefaultPool.Role, RedisPool.module)
.insertAfter(StackClient.Role.prepConn, ConnectionInitCommand.module)
.replace(StackClient.Role.protoTracing, RedisTracingFilter.module)
.insertAfter(RedisLoggingFilter.role, RedisLoggingFilter.module)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the RedisLoggingFilter.role exist in the client stack already? I believe using insertAfter here will not put it into the stack, since the role doesn't exists. Maybe before the tracing filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, the role does not currently exist in the stack. Docs from insertAfter say: If no elements match the role, then an unmodified stack is returned. So looks like this is currently won't add the logging filter. I'll change it to insert before the tracing filter.

@jyanJing
Copy link
Contributor

Hi @rpless ,
@enbnt and I have been having troubles pulling in this request, we both see the following error:

error: while searching for:
import com.twitter.util.{Duration, Monitor}
import java.net.SocketAddress

import com.twitter.finagle.redis.param.{Database, Password}

trait RedisRichClient { self: Client[Command, Reply] =>

error: patch failed: finagle/finagle-redis/src/main/scala/com/twitter/finagle/Redis.scala:23
error: finagle/finagle-redis/src/main/scala/com/twitter/finagle/Redis.scala: patch does not apply
Checking patch finagle/finagle-redis/src/main/scala/com/twitter/finagle/redis/filter/RedisLoggingFilter.scala...
Checking patch finagle/finagle-redis/src/main/scala/com/twitter/finagle/redis/filter/RedisTracingFilter.scala...
Checking patch finagle/finagle-redis/src/main/scala/com/twitter/finagle/redis/filter/RedisLoggingFilter.scala...
Checking patch finagle/finagle-redis/src/main/scala/com/twitter/finagle/Redis.scala...
error: while searching for:
      .insertBefore(DefaultPool.Role, RedisPool.module)
      .insertAfter(StackClient.Role.prepConn, ConnectionInitCommand.module)
      .replace(StackClient.Role.protoTracing, RedisTracingFilter.module)
      .insertAfter(RedisLoggingFilter.role, RedisLoggingFilter.module)

    private[finagle] val hashRingStack: Stack[ServiceFactory[Command, Reply]] =
      stack.insertAfter(BindingFactory.role, RedisPartitioningService.module)

error: patch failed: finagle/finagle-redis/src/main/scala/com/twitter/finagle/Redis.scala:74
error: finagle/finagle-redis/src/main/scala/com/twitter/finagle/Redis.scala: patch does not apply

@enbnt has tried to do a merge on Github but the error persists.

Would you please do a rebase then I can try to pull it again? Thank you!

@rpless
Copy link
Contributor Author

rpless commented Sep 30, 2020

Hi @jyanJing I believe that happens because one of the commits in this PR conflicts with this commit in develop. I have rebased this Pull Request against develop. Please let me know if there are any issues.

@jyanJing
Copy link
Contributor

jyanJing commented Oct 1, 2020

Hi @rpless,

Thank you for rebasing the branch! I am able to pull it in and get the team's review. Since this change is made to the stack module with the tracing and logging filter, we are very careful with changes in that area because it might bring up latencies for services that use finagle-redis. So I am working with 2 other teams to canary the change now, to make sure we capture any behavior changes. It is not about your change, it is a critical area to be precautious about.

I wanted to let you know that it will take longer to merge this change, but I am actively working on it! Really appreciate for making this change!

Best regards,
Jing

@jyanJing
Copy link
Contributor

Hi @rpless

canaries looks good, the change is merged,

Thank you for the excellent work and your patience!

@jyanJing jyanJing closed this Oct 22, 2020
@rpless
Copy link
Contributor Author

rpless commented Oct 24, 2020

Thanks for setting up the canary to test the change @jyanJing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants