-
Notifications
You must be signed in to change notification settings - Fork 455
/
series_sharding.go
46 lines (40 loc) · 1.28 KB
/
series_sharding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/distributor/distributor.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.
package mimirpb
import (
"github.com/prometheus/prometheus/model/labels"
)
// ShardByMetricName returns the token for the given metric. The provided metricName
// is guaranteed to not be retained.
func ShardByMetricName(userID string, metricName string) uint32 {
h := ShardByUser(userID)
h = HashAdd32(h, metricName)
return h
}
func ShardByUser(userID string) uint32 {
h := HashNew32()
h = HashAdd32(h, userID)
return h
}
// ShardByAllLabels returns the token for given user and series.
//
// ShardByAllLabels generates different values for different order of same labels.
func ShardByAllLabels(userID string, ls labels.Labels) uint32 {
h := ShardByUser(userID)
ls.Range(func(l labels.Label) {
h = HashAdd32(h, l.Name)
h = HashAdd32(h, l.Value)
})
return h
}
// ShardByAllLabelAdapters is like ShardByAllLabel, but uses LabelAdapter type.
func ShardByAllLabelAdapters(userID string, ls []LabelAdapter) uint32 {
h := ShardByUser(userID)
for _, l := range ls {
h = HashAdd32(h, l.Name)
h = HashAdd32(h, l.Value)
}
return h
}