Skip to content

Instantly share code, notes, and snippets.

@GiedriusS
Created November 7, 2022 13:20
Show Gist options
  • Save GiedriusS/aada711443326ea452ec5c4c0c508b07 to your computer and use it in GitHub Desktop.
Save GiedriusS/aada711443326ea452ec5c4c0c508b07 to your computer and use it in GitHub Desktop.
diff --git a/pkg/store/proxy_heap.go b/pkg/store/proxy_heap.go
index d354d4db..5161930b 100644
--- a/pkg/store/proxy_heap.go
+++ b/pkg/store/proxy_heap.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"sort"
+ "strings"
"sync"
"time"
@@ -618,6 +619,8 @@ func newEagerRespSet(
applySharding bool,
emptyStreamResponses prometheus.Counter,
) respSet {
+ labelsCounter := map[string]uint64{}
+
ret := &eagerRespSet{
span: span,
st: st,
@@ -693,6 +696,11 @@ func newEagerRespSet(
if resp.GetSeries() != nil {
seriesStats.Count(resp.GetSeries())
+ s := resp.GetSeries()
+ for _, lbl := range s.Labels {
+ labelsCounter[lbl.Name]++
+ labelsCounter[lbl.Value]++
+ }
}
l.bufferedResponses = append(l.bufferedResponses, resp)
@@ -707,6 +715,34 @@ func newEagerRespSet(
for {
if !handleRecvResponse(t) {
+ var sb strings.Builder
+
+ fmt.Fprintln(&sb, "--------")
+ keys := []string{}
+ for k := range labelsCounter {
+ keys = append(keys, k)
+ }
+ sort.Slice(keys, func(i, j int) bool {
+ return labelsCounter[keys[i]] > labelsCounter[keys[j]]
+ })
+ for i, k := range keys {
+ fmt.Fprintf(&sb, "%s %d\n", k, labelsCounter[k])
+ if i > 3 {
+ break
+ }
+ }
+
+ var totalSum uint64
+ var totalMinimal uint64
+
+ for k, count := range labelsCounter {
+ totalSum += uint64(len(k)) * count
+ totalMinimal += uint64(len(k))
+ }
+ fmt.Fprintf(&sb, "Total sum is %d, total minimal is %d\n", totalSum, totalMinimal)
+ fmt.Fprintln(&sb, "--------")
+ fmt.Println(sb.String())
+
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment