hashForSearchRequest returns a uint64 hash of the query. if the query is invalid it returns a 0 hash. before hashing the query is forced into a canonical form so equivalent queries will hash to the same value.
(searchRequest *tempopb.SearchRequest)
| 352 | // hashForSearchRequest returns a uint64 hash of the query. if the query is invalid it returns a 0 hash. |
| 353 | // before hashing the query is forced into a canonical form so equivalent queries will hash to the same value. |
| 354 | func hashForSearchRequest(searchRequest *tempopb.SearchRequest) uint64 { |
| 355 | if searchRequest.Query == "" { |
| 356 | return 0 |
| 357 | } |
| 358 | |
| 359 | ast, err := traceql.ParseNoOptimizations(searchRequest.Query) |
| 360 | if err != nil { // this should never occur. if we've made this far we've already validated the query can parse. however, for sanity, just fail to cache if we can't parse |
| 361 | return 0 |
| 362 | } |
| 363 | |
| 364 | // forces the query into a canonical form |
| 365 | query := ast.String() |
| 366 | |
| 367 | // add the query, limit and spss to the hash |
| 368 | hash := fnv1a.HashString64(query) |
| 369 | hash = fnv1a.AddUint64(hash, uint64(searchRequest.Limit)) |
| 370 | hash = fnv1a.AddUint64(hash, uint64(searchRequest.SpansPerSpanSet)) |
| 371 | for _, name := range searchRequest.SkipASTTransformations { |
| 372 | hash = fnv1a.AddString64(hash, name) |
| 373 | } |
| 374 | |
| 375 | return hash |
| 376 | } |
| 377 | |
| 378 | // pagesPerRequest returns an integer value that indicates the number of pages |
| 379 | // that should be searched per query. This value is based on the target number of bytes |