Skip to content

Commit 130b2b7

Browse files
committed
New version of GetRef() that returns labels
Now we only need to make a copy if GetRef() returns zero Note Prometheus update brings in JSON marshalling of model.Duration prometheus/common#280 Signed-off-by: Bryan Boreham <[email protected]>
1 parent 5f9457b commit 130b2b7

File tree

10 files changed

+81
-39
lines changed

10 files changed

+81
-39
lines changed

go.mod

+14-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ require (
4646
github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6
4747
github.com/prometheus/client_golang v1.9.0
4848
github.com/prometheus/client_model v0.2.0
49-
github.com/prometheus/common v0.18.0
50-
github.com/prometheus/prometheus v1.8.2-0.20210319192855-d614ae9ecf1c
49+
github.com/prometheus/common v0.20.0
50+
github.com/prometheus/prometheus v1.8.2-0.20210321183757-31a518faab18
5151
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e
5252
github.com/sony/gobreaker v0.4.1
5353
github.com/spf13/afero v1.2.2
@@ -101,3 +101,15 @@ replace github.com/go-openapi/strfmt => github.com/go-openapi/strfmt v0.19.5
101101
replace github.com/go-openapi/swag => github.com/go-openapi/swag v0.19.9
102102

103103
replace github.com/go-openapi/validate => github.com/go-openapi/validate v0.19.8
104+
105+
// Branch for testing
106+
replace github.com/prometheus/prometheus => github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c
107+
108+
// Pin these otherwise they downgrade
109+
replace go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver v1.3.2
110+
111+
replace github.com/mitchellh/mapstructure => github.com/mitchellh/mapstructure v1.2.2
112+
113+
replace github.com/hashicorp/go-hclog => github.com/hashicorp/go-hclog v0.12.2
114+
115+
replace github.com/hashicorp/go-immutable-radix => github.com/hashicorp/go-immutable-radix v1.2.0

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ github.com/aws/aws-sdk-go v1.37.8/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zK
197197
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
198198
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
199199
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
200+
github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c h1:rnzCAKpqQJ0Imp9D2lpqB4ZPypZKEZ7Dj0AQ26gOPrM=
201+
github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c/go.mod h1:QXavF3rQy2C4kfRg+O+44fkSXg2ADPVfXPCRKwTmbAk=
200202
github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg=
201203
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
202204
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -1067,6 +1069,8 @@ github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16
10671069
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
10681070
github.com/prometheus/common v0.18.0 h1:WCVKW7aL6LEe1uryfI9dnEc2ZqNB1Fn0ok930v0iL1Y=
10691071
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
1072+
github.com/prometheus/common v0.20.0 h1:pfeDeUdQcIxOMutNjCejsEFp7qeP+/iltHSSmLpE+hU=
1073+
github.com/prometheus/common v0.20.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
10701074
github.com/prometheus/exporter-toolkit v0.5.0/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg=
10711075
github.com/prometheus/exporter-toolkit v0.5.1/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg=
10721076
github.com/prometheus/node_exporter v1.0.0-rc.0.0.20200428091818-01054558c289 h1:dTUS1vaLWq+Y6XKOTnrFpoVsQKLCbCp1OLj24TDi7oM=

pkg/ingester/ingester_v2.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,11 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
724724
// Walk the samples, appending them to the users database
725725
app := db.Appender(ctx).(extendedAppender)
726726
for _, ts := range req.Timeseries {
727-
// Keeps a reference to labels copy, if it was needed. This is to avoid making a copy twice,
728-
// once for TSDB, and second time for activeSeries map.
729-
var copiedLabels []labels.Label
730-
731727
// The labels must be sorted (in our case, it's guaranteed a write request
732728
// has sorted labels once hit the ingester).
733729

734-
// Look up a reference for this series. Holding the appendLock ensures that no compaction will happen while we use it.
735-
ref := app.GetRef(cortexpb.FromLabelAdaptersToLabels(ts.Labels))
730+
// Look up a reference for this series.
731+
ref, copiedLabels := app.GetRef(cortexpb.FromLabelAdaptersToLabels(ts.Labels))
736732

737733
// To find out if any sample was added to this series, we keep old value.
738734
oldSucceededSamplesCount := succeededSamplesCount
@@ -742,14 +738,13 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
742738

743739
// If the cached reference exists, we try to use it.
744740
if ref != 0 {
745-
labels := cortexpb.FromLabelAdaptersToLabels(ts.Labels)
746-
if _, err = app.Append(ref, labels, s.TimestampMs, s.Value); err == nil {
741+
if _, err = app.Append(ref, copiedLabels, s.TimestampMs, s.Value); err == nil {
747742
succeededSamplesCount++
748743
continue
749744
}
750745

751746
} else {
752-
// Copy the label set because both TSDB and the cache may retain it.
747+
// Copy the label set because both TSDB and the active series tracker may retain it.
753748
copiedLabels = cortexpb.FromLabelAdaptersToLabelsWithCopy(ts.Labels)
754749

755750
// Retain the reference in case there are multiple samples for the series.
@@ -789,9 +784,6 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
789784
case errMaxSeriesPerMetricLimitExceeded:
790785
perMetricSeriesLimitCount++
791786
updateFirstPartial(func() error {
792-
if copiedLabels == nil {
793-
copiedLabels = cortexpb.FromLabelAdaptersToLabelsWithCopy(ts.Labels)
794-
}
795787
return makeMetricLimitError(perMetricSeriesLimit, copiedLabels, i.limiter.FormatError(userID, cause))
796788
})
797789
continue
@@ -807,11 +799,7 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
807799

808800
if i.cfg.ActiveSeriesMetricsEnabled && succeededSamplesCount > oldSucceededSamplesCount {
809801
db.activeSeries.UpdateSeries(cortexpb.FromLabelAdaptersToLabels(ts.Labels), startAppend, func(l labels.Labels) labels.Labels {
810-
// If we have already made a copy during this push, no need to create new one.
811-
if copiedLabels != nil {
812-
return copiedLabels
813-
}
814-
return cortexpb.CopyLabels(l)
802+
return copiedLabels
815803
})
816804
}
817805
}

vendor/github.com/prometheus/common/config/http_config.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/model/time.go

+32-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/prometheus/config/config.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/prometheus/storage/interface.go

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/prometheus/tsdb/db.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/prometheus/tsdb/head.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

+12-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)