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

Add support for Redis caching #354

Merged
merged 17 commits into from
Nov 25, 2020

Conversation

dgzlopes
Copy link
Member

@dgzlopes dgzlopes commented Nov 19, 2020

What this PR does:
This PR adds support for Redis caching on Tempodb.

TODO:

  • Add basic client/support/config
  • Add sane defaults and more config params
  • Add tests
  • (probably) Cleanup

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@dgzlopes
Copy link
Member Author

dgzlopes commented Nov 19, 2020

Created a WIP PR with a working version... but I've a lot of things todo for this to be usable and reviewable :)

@dgzlopes dgzlopes marked this pull request as ready for review November 23, 2020 17:07
@dgzlopes dgzlopes changed the title [WIP] Add support for Redis caching Add support for Redis caching Nov 23, 2020
- Add Redis client
- Add Redis support
- Add Redis file

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Copy link
Contributor

@annanay25 annanay25 left a comment

Choose a reason for hiding this comment

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

I've left some comments @dgzlopes, thanks for your work on the redis support. Also, sorry for a late review to go a different route, but feel free to reach out on DM to discuss further :)

tempodb/backend/redis/cache.go Show resolved Hide resolved
docs/tempo/website/configuration/_index.md Show resolved Hide resolved
@@ -0,0 +1,147 @@
package redis
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a ton of code that's pretty much the same as memcached/cache.go .. This can get tough to maintain. I would suggest we split out the cache section into a separate module and pass it a Cache interface which looks something like this

type Cache interface {
    func get(ctx context.Context, key string) []byte
    func set(ctx context.Context, key string, val []byte)
}

The different cache backends can then implement this small interface instead of the entire backend.Reader / backend.Writer interfaces. It will also help to keep all the tests in one place.

Copy link
Member Author

@dgzlopes dgzlopes Nov 24, 2020

Choose a reason for hiding this comment

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

diskcache should live inside this separate module too? Probably not, I suppose 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

diskcache should also live there, but if that turns out to be tough we can always address it in a different PR :)

Comment on lines +160 to +167
if cfg.Redis != nil {
r, w, err = redis.New(r, w, cfg.Redis, logger)

if err != nil {
return nil, nil, nil, err
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This can also be addressed by the other comment ^

Also, the config section for cache is getting a little untidy, can we add a new field like we have for backend (Line 128) which indicates which cache type we are trying to use? And then we can add these in a switch case like above.

tempodb/backend/redis/cache.go Outdated Show resolved Hide resolved
tempodb/backend/redis/cache.go Outdated Show resolved Hide resolved
@dgzlopes dgzlopes changed the title Add support for Redis caching [WIP] Add support for Redis caching Nov 24, 2020
- Add Redis client
- Add Redis support
- Add Redis file

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
object: tt.readerObject,
}
mockW := &mockWriter{}
mr, _ := miniredis.Run()
Copy link
Contributor

@annanay25 annanay25 Nov 25, 2020

Choose a reason for hiding this comment

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

A simple map cache can be implemented like in memcached tests but I saw Cortex is using this too, so OK.

@annanay25 annanay25 changed the title [WIP] Add support for Redis caching Add support for Redis caching Nov 25, 2020
Copy link
Contributor

@annanay25 annanay25 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your work @dgzlopes! 🎉

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
@annanay25 annanay25 merged commit c20839c into grafana:master Nov 25, 2020
@dgzlopes dgzlopes deleted the add-redis-support-tempodb branch November 25, 2020 14:00
@achatterjee-grafana
Copy link
Contributor

One comment for the docs, even though this PR is merged.
In the redis.md file, a title is missing. Also, can we use sentence case instead of the lower case? We can work on this together on a new PR. Thanks!

@dgzlopes
Copy link
Member Author

dgzlopes commented Nov 25, 2020

Hi @achatterjee-grafana!

Maybe I'm missing something... But I see a title here: https://github.com/grafana/tempo/blob/master/docs/tempo/website/configuration/redis.md. I've to add it to some other place?

I'm happy to move everything to sentence case. I used lower case... Because I followed what we have for S3 -> https://github.com/grafana/tempo/blob/master/docs/tempo/website/configuration/s3.md 😄

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

Successfully merging this pull request may close these issues.

4 participants