github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/bucket/users.go (about) 1 package bucket 2 3 import ( 4 "context" 5 "strings" 6 7 "github.com/thanos-io/objstore" 8 ) 9 10 // PyroscopeInternalsPrefix is the bucket prefix under which all Pyroscope internal cluster-wide objects are stored. 11 // The object storage path delimiter (/) is appended to this prefix when building the full object path. 12 const PyroscopeInternalsPrefix = "__pyroscope_cluster" 13 14 // ListUsers returns all user IDs found scanning the root of the bucket. 15 func ListUsers(ctx context.Context, bucketClient objstore.Bucket) (users []string, err error) { 16 // Iterate the bucket to find all users in the bucket. Due to how the bucket listing 17 // caching works, it's more likely to have a cache hit if there's no delay while 18 // iterating the bucket, so we do load all users in memory and later process them. 19 err = bucketClient.Iter(ctx, "", func(entry string) error { 20 userID := strings.TrimSuffix(entry, "/") 21 if strings.HasSuffix(entry, ".json") { 22 return nil 23 } 24 if isUserIDReserved(userID) { 25 return nil 26 } 27 28 users = append(users, userID) 29 return nil 30 }) 31 32 return users, err 33 } 34 35 // isUserIDReserved returns whether the provided user ID is reserved and can't be used for storing metrics. 36 func isUserIDReserved(name string) bool { 37 return name == PyroscopeInternalsPrefix 38 }