@@ -115,13 +115,12 @@ func RecordRangeAndInstantQueryMetrics(
115115 result promql_parser.Value ,
116116) {
117117 var (
118- logger = fixLogger (ctx , log )
119- rangeType = GetRangeType (p )
120- rt = string (rangeType )
121- latencyType = latencyTypeFast
122- returnedLines = 0
123- cardinalityEstimate = uint64 (0 )
124- queryTags , _ = ctx .Value (httpreq .QueryTagsHTTPHeader ).(string ) // it's ok to be empty.
118+ logger = fixLogger (ctx , log )
119+ rangeType = GetRangeType (p )
120+ rt = string (rangeType )
121+ latencyType = latencyTypeFast
122+ returnedLines = 0
123+ queryTags , _ = ctx .Value (httpreq .QueryTagsHTTPHeader ).(string ) // it's ok to be empty.
125124 )
126125
127126 queryType , err := QueryType (p .GetExpression ())
@@ -162,10 +161,6 @@ func RecordRangeAndInstantQueryMetrics(
162161 bloomRatio = float64 (stats .Index .TotalChunks - stats .Index .PostFilterChunks ) / float64 (stats .Index .TotalChunks )
163162 }
164163
165- if r , ok := result .(CountMinSketchVector ); ok {
166- cardinalityEstimate = r .F .HyperLogLog .Estimate ()
167- }
168-
169164 logValues = append (logValues , []interface {}{
170165 "latency" , latencyType , // this can be used to filter log lines.
171166 "query" , query ,
@@ -213,8 +208,6 @@ func RecordRangeAndInstantQueryMetrics(
213208 "cache_result_hit" , resultCache .EntriesFound ,
214209 "cache_result_download_time" , resultCache .CacheDownloadTime (),
215210 "cache_result_query_length_served" , resultCache .CacheQueryLengthServed (),
216- // Cardinality estimate for some approximate query types
217- "cardinality_estimate" , cardinalityEstimate ,
218211 // The total of chunk reference fetched from index.
219212 "ingester_chunk_refs" , stats .Ingester .Store .GetTotalChunksRef (),
220213 // Total number of chunks fetched.
@@ -240,8 +233,15 @@ func RecordRangeAndInstantQueryMetrics(
240233 "index_bloom_filter_ratio" , fmt .Sprintf ("%.2f" , bloomRatio ),
241234 "index_used_bloom_filters" , stats .Index .UsedBloomFilters ,
242235 "index_shard_resolver_duration" , time .Duration (stats .Index .ShardsDuration ),
236+ "index_bloom_filter_time" , logql_stats .ConvertSecondsToNanoseconds (stats .Index .BloomFilterTime ),
237+ "index_chunk_refs_lookup_time" , logql_stats .ConvertSecondsToNanoseconds (stats .Index .ChunkRefsLookupTime ),
243238 }... )
244239
240+ if r , ok := result .(CountMinSketchVector ); ok {
241+ cardinalityEstimate := r .F .HyperLogLog .Estimate ()
242+ logValues = append (logValues , "cardinality_estimate" , cardinalityEstimate )
243+ }
244+
245245 logValues = append (logValues , httpreq .TagsToKeyValues (queryTags )... )
246246
247247 if httpreq .ExtractHeader (ctx , httpreq .LokiDisablePipelineWrappersHeader ) == "true" {
0 commit comments