Skip to content

Commit

Permalink
New version of GetRef() that returns labels
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bboreham committed Mar 30, 2021
1 parent 93351aa commit 4ee2538
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 39 deletions.
16 changes: 14 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ require (
github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.18.0
github.com/prometheus/prometheus v1.8.2-0.20210319192855-d614ae9ecf1c
github.com/prometheus/common v0.20.0
github.com/prometheus/prometheus v1.8.2-0.20210321183757-31a518faab18
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e
github.com/sony/gobreaker v0.4.1
github.com/spf13/afero v1.2.2
Expand Down Expand Up @@ -101,3 +101,15 @@ replace github.com/go-openapi/strfmt => github.com/go-openapi/strfmt v0.19.5
replace github.com/go-openapi/swag => github.com/go-openapi/swag v0.19.9

replace github.com/go-openapi/validate => github.com/go-openapi/validate v0.19.8

// Branch for testing
replace github.com/prometheus/prometheus => github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c

// Pin these otherwise they downgrade
replace go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver v1.3.2

replace github.com/mitchellh/mapstructure => github.com/mitchellh/mapstructure v1.2.2

replace github.com/hashicorp/go-hclog => github.com/hashicorp/go-hclog v0.12.2

replace github.com/hashicorp/go-immutable-radix => github.com/hashicorp/go-immutable-radix v1.2.0
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ github.com/aws/aws-sdk-go v1.37.8/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zK
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c h1:rnzCAKpqQJ0Imp9D2lpqB4ZPypZKEZ7Dj0AQ26gOPrM=
github.com/bboreham/prometheus v1.7.2-0.20210323212203-73930f5e682c/go.mod h1:QXavF3rQy2C4kfRg+O+44fkSXg2ADPVfXPCRKwTmbAk=
github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -1067,6 +1069,8 @@ github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.18.0 h1:WCVKW7aL6LEe1uryfI9dnEc2ZqNB1Fn0ok930v0iL1Y=
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.20.0 h1:pfeDeUdQcIxOMutNjCejsEFp7qeP+/iltHSSmLpE+hU=
github.com/prometheus/common v0.20.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/exporter-toolkit v0.5.0/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg=
github.com/prometheus/exporter-toolkit v0.5.1/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg=
github.com/prometheus/node_exporter v1.0.0-rc.0.0.20200428091818-01054558c289 h1:dTUS1vaLWq+Y6XKOTnrFpoVsQKLCbCp1OLj24TDi7oM=
Expand Down
22 changes: 5 additions & 17 deletions pkg/ingester/ingester_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,11 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
// Walk the samples, appending them to the users database
app := db.Appender(ctx).(extendedAppender)
for _, ts := range req.Timeseries {
// Keeps a reference to labels copy, if it was needed. This is to avoid making a copy twice,
// once for TSDB, and second time for activeSeries map.
var copiedLabels []labels.Label

// The labels must be sorted (in our case, it's guaranteed a write request
// has sorted labels once hit the ingester).

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

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

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

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

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

if i.cfg.ActiveSeriesMetricsEnabled && succeededSamplesCount > oldSucceededSamplesCount {
db.activeSeries.UpdateSeries(cortexpb.FromLabelAdaptersToLabels(ts.Labels), startAppend, func(l labels.Labels) labels.Labels {
// If we have already made a copy during this push, no need to create new one.
if copiedLabels != nil {
return copiedLabels
}
return cortexpb.CopyLabels(l)
return copiedLabels
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/prometheus/common/config/http_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion vendor/github.com/prometheus/common/model/time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/prometheus/prometheus/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/github.com/prometheus/prometheus/storage/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/prometheus/prometheus/tsdb/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions vendor/github.com/prometheus/prometheus/tsdb/head.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ee2538

Please sign in to comment.