Skip to content

Commit 049c5e4

Browse files
authored
Merge pull request #104 from grafana/56quarters/upstream-update
Upgrade prometheus to latest main
2 parents 19b1932 + fc643a4 commit 049c5e4

12 files changed

Lines changed: 184 additions & 107 deletions

File tree

RELEASE.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Release cadence of first pre-releases being cut is 6 weeks.
3737
| v2.30 | 2021-09-08 | Ganesh Vernekar (GitHub: @codesome) |
3838
| v2.31 | 2021-10-20 | Julien Pivotto (GitHub: @roidelapluie) |
3939
| v2.32 | 2021-12-01 | Julius Volz (GitHub: @juliusv) |
40-
| v2.33 | 2022-01-12 | **searching for volunteer** |
40+
| v2.33 | 2022-01-12 | Björn Rabenstein (GitHub: @beorn7) |
41+
| v2.34 | 2022-02-23 | Chris Marchbanks (GitHub: @csmarchbanks) |
42+
| v2.35 | 2022-04-06 | **searching for volunteer** |
4143

4244
If you are interested in volunteering please create a pull request against the [prometheus/prometheus](https://github.com/prometheus/prometheus) repository and propose yourself for the release series of your choice.
4345

@@ -70,7 +72,7 @@ If a bug fix got accidentally merged into main after non-bug-fix changes in main
7072

7173
Maintaining the release branches for older minor releases happens on a best effort basis.
7274

73-
### 0. Updating dependencies
75+
### 0. Updating dependencies and promoting/demoting experimental features
7476

7577
A few days before a major or minor release, consider updating the dependencies.
7678

@@ -85,6 +87,10 @@ you can skip the dependency update or only update select dependencies. In such a
8587
case, you have to create an issue or pull request in the GitHub project for
8688
later follow-up.
8789

90+
This is also a good time to consider any experimental features and feature
91+
flags for promotion to stable or for deprecation or ultimately removal. Do any
92+
of these in pull requests, one per feature.
93+
8894
#### Updating Go dependencies
8995

9096
```
@@ -155,3 +161,5 @@ For release candidate versions (`v2.16.0-rc.0`), run the benchmark for 3 days us
155161
If the release has happened in the latest release branch, merge the changes into main.
156162

157163
Once the binaries have been uploaded, announce the release on `prometheus-announce@googlegroups.com`. (Please do not use `prometheus-users@googlegroups.com` for announcements anymore.) Check out previous announcement mails for inspiration.
164+
165+
Finally, in case there is no release shepherd listed for the next release yet, find a volunteer.

discovery/legacymanager/manager_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,16 @@ func TestTargetUpdatesOrder(t *testing.T) {
668668
discoveryManager.updatert = 100 * time.Millisecond
669669

670670
var totalUpdatesCount int
671-
provUpdates := make(chan []*targetgroup.Group)
672671
for _, up := range tc.updates {
673-
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
674672
if len(up) > 0 {
675673
totalUpdatesCount += len(up)
676674
}
677675
}
676+
provUpdates := make(chan []*targetgroup.Group, totalUpdatesCount)
677+
678+
for _, up := range tc.updates {
679+
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
680+
}
678681

679682
for x := 0; x < totalUpdatesCount; x++ {
680683
select {

discovery/manager_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,16 @@ func TestTargetUpdatesOrder(t *testing.T) {
668668
discoveryManager.updatert = 100 * time.Millisecond
669669

670670
var totalUpdatesCount int
671-
provUpdates := make(chan []*targetgroup.Group)
672671
for _, up := range tc.updates {
673-
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
674672
if len(up) > 0 {
675673
totalUpdatesCount += len(up)
676674
}
677675
}
676+
provUpdates := make(chan []*targetgroup.Group, totalUpdatesCount)
677+
678+
for _, up := range tc.updates {
679+
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
680+
}
678681

679682
for x := 0; x < totalUpdatesCount; x++ {
680683
select {

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/prometheus/prometheus
33
go 1.16
44

55
require (
6-
github.com/Azure/azure-sdk-for-go v60.3.0+incompatible
6+
github.com/Azure/azure-sdk-for-go v61.1.0+incompatible
77
github.com/Azure/go-autorest/autorest v0.11.23
88
github.com/Azure/go-autorest/autorest/adal v0.9.18
99
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
1010
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
11-
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a
12-
github.com/aws/aws-sdk-go v1.42.25
11+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
12+
github.com/aws/aws-sdk-go v1.42.28
1313
github.com/cespare/xxhash/v2 v2.1.2
1414
github.com/containerd/containerd v1.5.7 // indirect
1515
github.com/dennwc/varint v1.0.0
@@ -27,7 +27,7 @@ require (
2727
github.com/go-zookeeper/zk v1.0.2
2828
github.com/gogo/protobuf v1.3.2
2929
github.com/golang/snappy v0.0.4
30-
github.com/google/pprof v0.0.0-20211122183932-1daafda22083
30+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd
3131
github.com/gophercloud/gophercloud v0.24.0
3232
github.com/grpc-ecosystem/grpc-gateway v1.16.0
3333
github.com/hashicorp/consul/api v1.12.0
@@ -59,14 +59,14 @@ require (
5959
github.com/uber/jaeger-lib v2.4.1+incompatible
6060
go.uber.org/atomic v1.9.0
6161
go.uber.org/goleak v1.1.12
62-
golang.org/x/net v0.0.0-20211209124913-491a49abca63
62+
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98
6363
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
6464
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
6565
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
6666
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
6767
golang.org/x/tools v0.1.8
6868
google.golang.org/api v0.63.0
69-
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
69+
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb
7070
google.golang.org/protobuf v1.27.1
7171
gopkg.in/alecthomas/kingpin.v2 v2.2.6
7272
gopkg.in/yaml.v2 v2.4.0
@@ -75,7 +75,7 @@ require (
7575
k8s.io/apimachinery v0.22.4
7676
k8s.io/client-go v0.22.4
7777
k8s.io/klog v1.0.0
78-
k8s.io/klog/v2 v2.30.0
78+
k8s.io/klog/v2 v2.40.1
7979
)
8080

8181
replace (

go.sum

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
5252
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
5353
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
5454
github.com/Azure/azure-sdk-for-go v41.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
55-
github.com/Azure/azure-sdk-for-go v60.3.0+incompatible h1:u6EXgnASaUOh38GXCwEpRs+u2bbfJpJpXeB42kU2cjg=
56-
github.com/Azure/azure-sdk-for-go v60.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
55+
github.com/Azure/azure-sdk-for-go v61.1.0+incompatible h1:Qbz3jdfkXIPjZECEuk2E7i3iLhC9Ul74pG5mQRQC+z4=
56+
github.com/Azure/azure-sdk-for-go v61.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
5757
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
5858
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
5959
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
@@ -154,8 +154,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
154154
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
155155
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
156156
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
157-
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a h1:E/8AP5dFtMhl5KPJz66Kt9G0n+7Sn41Fy1wv9/jHOrc=
158-
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
157+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
158+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
159159
github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0=
160160
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
161161
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
@@ -188,8 +188,8 @@ github.com/aws/aws-sdk-go v1.30.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZve
188188
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
189189
github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
190190
github.com/aws/aws-sdk-go v1.40.11/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
191-
github.com/aws/aws-sdk-go v1.42.25 h1:BbdvHAi+t9LRiaYUyd53noq9jcaAcfzOhSVbKfr6Avs=
192-
github.com/aws/aws-sdk-go v1.42.25/go.mod h1:gyRszuZ/icHmHAVE4gc/r+cfCmhA1AD+vqfWbgI+eHs=
191+
github.com/aws/aws-sdk-go v1.42.28 h1:YJtgL7IGSN41saY4JLW08jya5nU0vGcuAeAa1OL2M6c=
192+
github.com/aws/aws-sdk-go v1.42.28/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
193193
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
194194
github.com/benbjohnson/immutable v0.2.1/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
195195
github.com/benbjohnson/tmpl v1.0.0/go.mod h1:igT620JFIi44B6awvU9IsDhR77IXWtFigTLil/RPdps=
@@ -719,8 +719,8 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe
719719
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
720720
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
721721
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
722-
github.com/google/pprof v0.0.0-20211122183932-1daafda22083 h1:c8EUapQFi+kjzedr4c6WqbwMdmB95+oDBWZ5XFHFYxY=
723-
github.com/google/pprof v0.0.0-20211122183932-1daafda22083/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
722+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
723+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
724724
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
725725
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
726726
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -1534,8 +1534,9 @@ golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qx
15341534
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15351535
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15361536
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1537-
golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY=
1538-
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1537+
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1538+
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98 h1:+6WJMRLHlD7X7frgp7TUZ36RnQzSf9wVVTNakEp+nqY=
1539+
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15391540
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
15401541
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
15411542
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1906,8 +1907,9 @@ google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEc
19061907
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
19071908
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
19081909
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
1909-
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa h1:I0YcKz0I7OAhddo7ya8kMnvprhcWM045PmkBdMO9zN0=
19101910
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
1911+
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb h1:ZrsicilzPCS/Xr8qtBZZLpy4P9TYXAfl49ctG1/5tgw=
1912+
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
19111913
google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
19121914
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
19131915
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

storage/remote/queue_manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package remote
1515

1616
import (
1717
"context"
18+
"errors"
1819
"math"
1920
"strconv"
2021
"sync"
@@ -1311,12 +1312,16 @@ func (s *shards) sendSamplesWithBackoff(ctx context.Context, samples []prompb.Ti
13111312
}
13121313

13131314
err = sendWriteRequestWithBackoff(ctx, s.qm.cfg, s.qm.logger, attemptStore, onRetry)
1314-
if err != nil {
1315+
if errors.Is(err, context.Canceled) {
1316+
// When there is resharding, we cancel the context for this queue, which means the data is not sent.
1317+
// So we exit early to not update the metrics.
13151318
return err
13161319
}
1320+
13171321
s.qm.metrics.sentBytesTotal.Add(float64(reqSize))
13181322
s.qm.metrics.highestSentTimestamp.Set(float64(highest / 1000))
1319-
return nil
1323+
1324+
return err
13201325
}
13211326

13221327
func sendWriteRequestWithBackoff(ctx context.Context, cfg config.QueueConfig, l log.Logger, attempt func(int) error, onRetry func()) error {

tsdb/exemplar.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ import (
2727
"github.com/prometheus/prometheus/storage"
2828
)
2929

30-
// Indicates that there is no index entry for an exmplar.
31-
const noExemplar = -1
30+
const (
31+
// Indicates that there is no index entry for an exmplar.
32+
noExemplar = -1
33+
// Estimated number of exemplars per series, for sizing the index.
34+
estimatedExemplarsPerSeries = 16
35+
)
3236

3337
type CircularExemplarStorage struct {
3438
lock sync.RWMutex
@@ -117,7 +121,7 @@ func NewCircularExemplarStorage(len int64, m *ExemplarMetrics) (ExemplarStorage,
117121
}
118122
c := &CircularExemplarStorage{
119123
exemplars: make([]*circularBufferEntry, len),
120-
index: make(map[string]*indexEntry),
124+
index: make(map[string]*indexEntry, len/estimatedExemplarsPerSeries),
121125
metrics: m,
122126
}
123127

@@ -202,7 +206,8 @@ Outer:
202206
}
203207

204208
func (ce *CircularExemplarStorage) ValidateExemplar(l labels.Labels, e exemplar.Exemplar) error {
205-
seriesLabels := l.String()
209+
var buf [1024]byte
210+
seriesLabels := l.Bytes(buf[:])
206211

207212
// TODO(bwplotka): This lock can lock all scrapers, there might high contention on this on scale.
208213
// Optimize by moving the lock to be per series (& benchmark it).
@@ -213,7 +218,7 @@ func (ce *CircularExemplarStorage) ValidateExemplar(l labels.Labels, e exemplar.
213218

214219
// Not thread safe. The append parameters tells us whether this is an external validation, or internal
215220
// as a result of an AddExemplar call, in which case we should update any relevant metrics.
216-
func (ce *CircularExemplarStorage) validateExemplar(l string, e exemplar.Exemplar, append bool) error {
221+
func (ce *CircularExemplarStorage) validateExemplar(key []byte, e exemplar.Exemplar, append bool) error {
217222
if len(ce.exemplars) <= 0 {
218223
return storage.ErrExemplarsDisabled
219224
}
@@ -230,7 +235,7 @@ func (ce *CircularExemplarStorage) validateExemplar(l string, e exemplar.Exempla
230235
}
231236
}
232237

233-
idx, ok := ce.index[l]
238+
idx, ok := ce.index[string(key)]
234239
if !ok {
235240
return nil
236241
}
@@ -269,7 +274,7 @@ func (ce *CircularExemplarStorage) Resize(l int64) int {
269274
oldNextIndex := int64(ce.nextIndex)
270275

271276
ce.exemplars = make([]*circularBufferEntry, l)
272-
ce.index = make(map[string]*indexEntry)
277+
ce.index = make(map[string]*indexEntry, l/estimatedExemplarsPerSeries)
273278
ce.nextIndex = 0
274279

275280
// Replay as many entries as needed, starting with oldest first.
@@ -305,13 +310,14 @@ func (ce *CircularExemplarStorage) Resize(l int64) int {
305310
// migrate is like AddExemplar but reuses existing structs. Expected to be called in batch and requires
306311
// external lock and does not compute metrics.
307312
func (ce *CircularExemplarStorage) migrate(entry *circularBufferEntry) {
308-
seriesLabels := entry.ref.seriesLabels.String()
313+
var buf [1024]byte
314+
seriesLabels := entry.ref.seriesLabels.Bytes(buf[:])
309315

310-
idx, ok := ce.index[seriesLabels]
316+
idx, ok := ce.index[string(seriesLabels)]
311317
if !ok {
312318
idx = entry.ref
313319
idx.oldest = ce.nextIndex
314-
ce.index[seriesLabels] = idx
320+
ce.index[string(seriesLabels)] = idx
315321
} else {
316322
entry.ref = idx
317323
ce.exemplars[idx.newest].next = ce.nextIndex
@@ -329,7 +335,8 @@ func (ce *CircularExemplarStorage) AddExemplar(l labels.Labels, e exemplar.Exemp
329335
return storage.ErrExemplarsDisabled
330336
}
331337

332-
seriesLabels := l.String()
338+
var buf [1024]byte
339+
seriesLabels := l.Bytes(buf[:])
333340

334341
// TODO(bwplotka): This lock can lock all scrapers, there might high contention on this on scale.
335342
// Optimize by moving the lock to be per series (& benchmark it).
@@ -345,33 +352,34 @@ func (ce *CircularExemplarStorage) AddExemplar(l labels.Labels, e exemplar.Exemp
345352
return err
346353
}
347354

348-
_, ok := ce.index[seriesLabels]
355+
_, ok := ce.index[string(seriesLabels)]
349356
if !ok {
350-
ce.index[seriesLabels] = &indexEntry{oldest: ce.nextIndex, seriesLabels: l}
357+
ce.index[string(seriesLabels)] = &indexEntry{oldest: ce.nextIndex, seriesLabels: l}
351358
} else {
352-
ce.exemplars[ce.index[seriesLabels].newest].next = ce.nextIndex
359+
ce.exemplars[ce.index[string(seriesLabels)].newest].next = ce.nextIndex
353360
}
354361

355362
if prev := ce.exemplars[ce.nextIndex]; prev == nil {
356363
ce.exemplars[ce.nextIndex] = &circularBufferEntry{}
357364
} else {
358365
// There exists exemplar already on this ce.nextIndex entry, drop it, to make place
359366
// for others.
360-
prevLabels := prev.ref.seriesLabels.String()
367+
var buf [1024]byte
368+
prevLabels := prev.ref.seriesLabels.Bytes(buf[:])
361369
if prev.next == noExemplar {
362370
// Last item for this series, remove index entry.
363-
delete(ce.index, prevLabels)
371+
delete(ce.index, string(prevLabels))
364372
} else {
365-
ce.index[prevLabels].oldest = prev.next
373+
ce.index[string(prevLabels)].oldest = prev.next
366374
}
367375
}
368376

369377
// Default the next value to -1 (which we use to detect that we've iterated through all exemplars for a series in Select)
370378
// since this is the first exemplar stored for this series.
371379
ce.exemplars[ce.nextIndex].next = noExemplar
372380
ce.exemplars[ce.nextIndex].exemplar = e
373-
ce.exemplars[ce.nextIndex].ref = ce.index[seriesLabels]
374-
ce.index[seriesLabels].newest = ce.nextIndex
381+
ce.exemplars[ce.nextIndex].ref = ce.index[string(seriesLabels)]
382+
ce.index[string(seriesLabels)].newest = ce.nextIndex
375383

376384
ce.nextIndex = (ce.nextIndex + 1) % len(ce.exemplars)
377385

0 commit comments

Comments
 (0)