MCPcopy
hub / github.com/grafana/tempo / createLegacyCache

Function createLegacyCache

tempodb/tempodb.go:856–900  ·  view source on GitHub ↗

createLegacyCache uses the config to return a cache and a list of roles.

(cfg *Config, logger gkLog.Logger)

Source from the content-addressed store, hash-verified

854
855// createLegacyCache uses the config to return a cache and a list of roles.
856func createLegacyCache(cfg *Config, logger gkLog.Logger) (cache.Cache, []cache.Role, error) {
857 var legacyCache cache.Cache
858 // if there's any cache configured, it always handles bloom filters and the trace id index
859 roles := []cache.Role{cache.RoleBloom, cache.RoleTraceIDIdx}
860
861 switch cfg.Cache {
862 case "redis":
863 legacyCache = redis.NewClient(cfg.Redis, cfg.BackgroundCache, "legacy", logger)
864 case "memcached":
865 legacyCache = memcached.NewClient(cfg.Memcached, cfg.BackgroundCache, "legacy", logger)
866 }
867
868 if legacyCache == nil {
869 if cfg.Search != nil &&
870 (cfg.Search.CacheControl.ColumnIndex ||
871 cfg.Search.CacheControl.Footer ||
872 cfg.Search.CacheControl.OffsetIndex) {
873 return nil, nil, errors.New("no legacy cache configured, but cache_control is enabled. Please use the new top level cache configuration")
874 }
875
876 return nil, nil, nil
877 }
878
879 // accumulate additional search roles
880 if cfg.Search != nil {
881 if cfg.Search.CacheControl.ColumnIndex {
882 roles = append(roles, cache.RoleParquetColumnIdx)
883 }
884 if cfg.Search.CacheControl.Footer {
885 roles = append(roles, cache.RoleParquetFooter)
886 }
887 if cfg.Search.CacheControl.OffsetIndex {
888 roles = append(roles, cache.RoleParquetOffsetIdx)
889 }
890 }
891
892 // log the roles
893 rolesStr := make([]string, len(roles))
894 for i, role := range roles {
895 rolesStr[i] = string(role)
896 }
897 level.Warn(logger).Log("msg", "legacy cache configured with the following roles. Please migrate to the new top level cache configuration.", "roles", rolesStr)
898
899 return legacyCache, roles, nil
900}

Callers 2

TestCreateLegacyCacheFunction · 0.85
NewFunction · 0.85

Calls 3

NewClientFunction · 0.92
NewClientFunction · 0.92
LogMethod · 0.65

Tested by 1

TestCreateLegacyCacheFunction · 0.68