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

Remove global metrics registry and global logger in cache package #2903

Merged
merged 4 commits into from
Jul 27, 2020

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Jul 20, 2020

Signed-off-by: Ben Ye [email protected]

What this PR does:

This pr removes global prometheus registries and util.logger in the cache package. This is good for reusing this package in other project like Thanos.

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]

@yeya24 yeya24 changed the title Remove global metrics registry and util in cache package WIP: Remove global metrics registry and util in cache package Jul 20, 2020
@yeya24 yeya24 force-pushed the no-global-registry-cache branch from f6f4540 to c7cd9b2 Compare July 20, 2020 23:07
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Epic job! Well done and thanks! ❤️

I left few comments, but overall the direction you're going looks good. Let's do it! 🚀

@@ -117,19 +118,20 @@ func (cfg *Config) Validate() error {
func NewStore(cfg Config, storeCfg chunk.StoreConfig, schemaCfg chunk.SchemaConfig, limits StoreLimits, reg prometheus.Registerer, cacheGenNumLoader chunk.CacheGenNumLoader) (chunk.Store, error) {
chunkMetrics := newChunkClientMetrics(reg)

indexReadCache, err := cache.New(cfg.IndexQueriesCacheConfig)
logger := log.NewNopLogger()
Copy link
Contributor

Choose a reason for hiding this comment

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

Uhm, no, we should pick it in input, not using the nop logger :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yes what I am doing here is totally wrong :(.

But the logger is initialized in the service module, I need to do some work to propagate that logger here

@yeya24
Copy link
Contributor Author

yeya24 commented Jul 22, 2020

Thanks for the review! @pracucci
One problem I meet is that we are using util.WarnExperimentalUse in the cache package, for example https://github.com/cortexproject/cortex/blob/ac796657c651e399e7e37f3e1cadbeed5777d21b/pkg/chunk/cache/redis_cache.go.

Is it possible to get rid of this? This relates to the counter metric here

var experimentalFeaturesInUse = promauto.NewCounter(

@pracucci
Copy link
Contributor

WarnExperimentalUse

I think we wanna keep it. If the problem is the logger, you could just pass the logger to it (in callers outside the pkg/chunk/cache, where logger is unavailable, you can just use util.Logger). If the problem is the metric, is it really a big deal in Thanos? Doesn't look dramatic exporting cortex_experimental_features_in_use_total.

@yeya24 yeya24 force-pushed the no-global-registry-cache branch from c7cd9b2 to 780e430 Compare July 24, 2020 03:13
@yeya24 yeya24 marked this pull request as ready for review July 24, 2020 03:14
@yeya24 yeya24 force-pushed the no-global-registry-cache branch from 780e430 to b64980a Compare July 24, 2020 03:17
@yeya24
Copy link
Contributor Author

yeya24 commented Jul 24, 2020

WarnExperimentalUse

I think we wanna keep it. If the problem is the logger, you could just pass the logger to it (in callers outside the pkg/chunk/cache, where logger is unavailable, you can just use util.Logger). If the problem is the metric, is it really a big deal in Thanos? Doesn't look dramatic exporting cortex_experimental_features_in_use_total.

Thanks. I think it is okay. Any thoughts? @bwplotka

I addressed all the comments. PTAL when you get a chance 😄 @pracucci

@yeya24 yeya24 changed the title WIP: Remove global metrics registry and util in cache package Remove global metrics registry and util in cache package Jul 27, 2020
@yeya24 yeya24 force-pushed the no-global-registry-cache branch from 2b41b66 to 8ae218c Compare July 27, 2020 02:00
@yeya24 yeya24 changed the title Remove global metrics registry and util in cache package Remove global metrics registry and global logger in cache package Jul 27, 2020
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @yeya24 for this amazing work! LGTM 🚀 @pstibrany could take a second look, please?

Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice, it looks good from my side as well 👍

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you! While I've left some nit-picking comments, nothing that would prevent from merging.

@@ -37,7 +39,7 @@ func TestFifoCacheEviction(t *testing.T) {
}

for _, test := range tests {
c := NewFifoCache(test.name, test.cfg)
c := NewFifoCache(test.name, test.cfg, prometheus.NewRegistry(), log.NewNopLogger())
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would prefer to pass nil as registerer, if we're not testing metrics.

// TODO(bwplotka): Remove globals & util packages from cache package entirely (e.g util.Logger).
func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string) *Memcached {
func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string, reg prometheus.Registerer, logger log.Logger) *Memcached {
memcacheRequestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this could be inlined.

prometheus.MustRegister(hits)
prometheus.MustRegister(valueSize)
}
requestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This can be inlined.

@pstibrany pstibrany merged commit d439006 into cortexproject:master Jul 27, 2020
@yeya24 yeya24 deleted the no-global-registry-cache branch July 27, 2020 13:27
@bboreham bboreham mentioned this pull request Sep 6, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants