labelsFor gives the final labels for the series. Slower and not on the hot path. This is tweaked to match what prometheus does where possible with an exception. In the case of all values missing. (1) Standard case: a label is created for each group-by value in the series: Ex: rate() by (x,y) can y
(vals S)
| 858 | // Ex: rate() by (x,y,z) and all nil yields: |
| 859 | // {x="nil"} |
| 860 | func (g *GroupingAggregator[F, S]) labelsFor(vals S) (Labels, SeriesMapKey) { |
| 861 | labels := make(Labels, 0, len(g.by)+1) |
| 862 | for i := range g.by { |
| 863 | if vals[i].Type == TypeNil { |
| 864 | continue |
| 865 | } |
| 866 | labels = append(labels, Label{g.by[i].String(), vals[i]}) |
| 867 | } |
| 868 | if g.byFunc != nil { |
| 869 | labels = append(labels, Label{g.byFuncLabel, vals[len(g.by)]}) |
| 870 | } |
| 871 | |
| 872 | if len(labels) == 0 { |
| 873 | // When all nil then force one |
| 874 | labels = append(labels, Label{g.by[0].String(), NewStaticNil()}) |
| 875 | } |
| 876 | |
| 877 | return labels, labels.MapKey() |
| 878 | } |
| 879 | |
| 880 | func (g *GroupingAggregator[F, S]) Series() SeriesSet { |
| 881 | ss := SeriesSet{} |
no test coverage detected