Add label set as first parameter to AddFast, ingored by TSDB adapter.

This commit is contained in:
Tom Wilkie 2017-07-12 12:41:27 +01:00
parent 2dda5775e3
commit db8128ceeb
8 changed files with 31 additions and 24 deletions

View file

@ -27,16 +27,16 @@ func (a nopAppendable) Appender() (storage.Appender, error) {
type nopAppender struct{} type nopAppender struct{}
func (a nopAppender) Add(labels.Labels, int64, float64) (string, error) { return "", nil } func (a nopAppender) Add(labels.Labels, int64, float64) (string, error) { return "", nil }
func (a nopAppender) AddFast(string, int64, float64) error { return nil } func (a nopAppender) AddFast(labels.Labels, string, int64, float64) error { return nil }
func (a nopAppender) Commit() error { return nil } func (a nopAppender) Commit() error { return nil }
func (a nopAppender) Rollback() error { return nil } func (a nopAppender) Rollback() error { return nil }
type collectResultAppender struct { type collectResultAppender struct {
result []sample result []sample
} }
func (a *collectResultAppender) AddFast(ref string, t int64, v float64) error { func (a *collectResultAppender) AddFast(m labels.Labels, ref string, t int64, v float64) error {
// Not implemented. // Not implemented.
return storage.ErrNotFound return storage.ErrNotFound
} }

View file

@ -751,8 +751,10 @@ loop:
} }
ref, ok := sl.cache.getRef(yoloString(met)) ref, ok := sl.cache.getRef(yoloString(met))
var lset labels.Labels
p.Metric(&lset)
if ok { if ok {
switch err = app.AddFast(ref, t, v); err { switch err = app.AddFast(lset, ref, t, v); err {
case nil: case nil:
if tp == nil { if tp == nil {
e := sl.cache.lsets[ref] e := sl.cache.lsets[ref]
@ -945,10 +947,12 @@ func (sl *scrapeLoop) addReportSample(app storage.Appender, s string, t int64, v
// Suffix s with the invalid \xff unicode rune to avoid collisions // Suffix s with the invalid \xff unicode rune to avoid collisions
// with scraped metrics. // with scraped metrics.
s2 := s + "\xff" s2 := s + "\xff"
met := labels.Labels{
labels.Label{Name: labels.MetricName, Value: s},
}
ref, ok := sl.cache.getRef(s2) ref, ok := sl.cache.getRef(s2)
if ok { if ok {
err := app.AddFast(ref, t, v) err := app.AddFast(met, ref, t, v)
switch err { switch err {
case nil: case nil:
return nil return nil
@ -962,9 +966,7 @@ func (sl *scrapeLoop) addReportSample(app storage.Appender, s string, t int64, v
return err return err
} }
} }
met := labels.Labels{
labels.Label{Name: labels.MetricName, Value: s},
}
ref, err := app.Add(met, t, v) ref, err := app.Add(met, t, v)
switch err { switch err {
case nil: case nil:

View file

@ -885,8 +885,8 @@ func (app *errorAppender) Add(lset labels.Labels, t int64, v float64) (string, e
} }
} }
func (app *errorAppender) AddFast(ref string, t int64, v float64) error { func (app *errorAppender) AddFast(lset labels.Labels, ref string, t int64, v float64) error {
return app.collectResultAppender.AddFast(ref, t, v) return app.collectResultAppender.AddFast(lset, ref, t, v)
} }
func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T) { func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T) {

View file

@ -212,14 +212,14 @@ func (app *limitAppender) Add(lset labels.Labels, t int64, v float64) (string, e
return ref, nil return ref, nil
} }
func (app *limitAppender) AddFast(ref string, t int64, v float64) error { func (app *limitAppender) AddFast(lset labels.Labels, ref string, t int64, v float64) error {
if !value.IsStaleNaN(v) { if !value.IsStaleNaN(v) {
app.i++ app.i++
if app.i > app.limit { if app.i > app.limit {
return errSampleLimit return errSampleLimit
} }
} }
if err := app.Appender.AddFast(ref, t, v); err != nil { if err := app.Appender.AddFast(lset, ref, t, v); err != nil {
return err return err
} }
return nil return nil
@ -243,11 +243,11 @@ func (app *timeLimitAppender) Add(lset labels.Labels, t int64, v float64) (strin
return ref, nil return ref, nil
} }
func (app *timeLimitAppender) AddFast(ref string, t int64, v float64) error { func (app *timeLimitAppender) AddFast(lset labels.Labels, ref string, t int64, v float64) error {
if t > app.maxTime { if t > app.maxTime {
return storage.ErrOutOfBounds return storage.ErrOutOfBounds
} }
if err := app.Appender.AddFast(ref, t, v); err != nil { if err := app.Appender.AddFast(lset, ref, t, v); err != nil {
return err return err
} }
return nil return nil

View file

@ -87,9 +87,13 @@ func (f *fanoutAppender) Add(l labels.Labels, t int64, v float64) (string, error
return "", nil return "", nil
} }
func (f *fanoutAppender) AddFast(ref string, t int64, v float64) error { func (f *fanoutAppender) AddFast(l labels.Labels, ref string, t int64, v float64) error {
// TODO this is a cheat, and causes us to fall back to slow path even for local writes. for _, appender := range f.appenders {
return ErrNotFound if err := appender.AddFast(l, ref, t, v); err != nil {
return err
}
}
return nil
} }
func (f *fanoutAppender) Commit() error { func (f *fanoutAppender) Commit() error {

View file

@ -56,7 +56,7 @@ type Querier interface {
type Appender interface { type Appender interface {
Add(l labels.Labels, t int64, v float64) (string, error) Add(l labels.Labels, t int64, v float64) (string, error)
AddFast(ref string, t int64, v float64) error AddFast(l labels.Labels, ref string, t int64, v float64) error
// Commit submits the collected samples and purges the batch. // Commit submits the collected samples and purges the batch.
Commit() error Commit() error

View file

@ -44,8 +44,9 @@ func labelsToMetric(ls labels.Labels) model.Metric {
return metric return metric
} }
func (*Storage) AddFast(ref string, t int64, v float64) error { func (s *Storage) AddFast(l labels.Labels, _ string, t int64, v float64) error {
return storage.ErrNotFound _, err := s.Add(l, t, v)
return err
} }
func (*Storage) Commit() error { func (*Storage) Commit() error {

View file

@ -135,7 +135,7 @@ func (a appender) Add(lset labels.Labels, t int64, v float64) (string, error) {
return ref, err return ref, err
} }
func (a appender) AddFast(ref string, t int64, v float64) error { func (a appender) AddFast(_ labels.Labels, ref string, t int64, v float64) error {
err := a.a.AddFast(ref, t, v) err := a.a.AddFast(ref, t, v)
switch errors.Cause(err) { switch errors.Cause(err) {