-
Notifications
You must be signed in to change notification settings - Fork 781
/
compat.go
80 lines (67 loc) · 1.88 KB
/
compat.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ruler
import (
"context"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/storage"
"github.com/weaveworks/common/user"
"github.com/cortexproject/cortex/pkg/ingester/client"
)
// Pusher is an ingester server that accepts pushes.
type Pusher interface {
Push(context.Context, *client.WriteRequest) (*client.WriteResponse, error)
}
type appender struct {
pusher Pusher
labels []labels.Labels
samples []client.Sample
userID string
}
func (a *appender) Add(l labels.Labels, t int64, v float64) (uint64, error) {
a.labels = append(a.labels, l)
a.samples = append(a.samples, client.Sample{
TimestampMs: t,
Value: v,
})
return 0, nil
}
func (a *appender) AddFast(l labels.Labels, ref uint64, t int64, v float64) error {
_, err := a.Add(l, t, v)
return err
}
func (a *appender) Commit() error {
_, err := a.pusher.Push(user.InjectOrgID(context.Background(), a.userID), client.ToWriteRequest(a.labels, a.samples, client.RULE))
a.labels = nil
a.samples = nil
return err
}
func (a *appender) Rollback() error {
a.labels = nil
a.samples = nil
return nil
}
// TSDB fulfills the storage.Storage interface for prometheus manager
// it allows for alerts to be restored by the manager
type tsdb struct {
pusher Pusher
userID string
queryable storage.Queryable
}
// Appender returns a storage.Appender
func (t *tsdb) Appender() (storage.Appender, error) {
return &appender{
pusher: t.pusher,
userID: t.userID,
}, nil
}
// Querier returns a new Querier on the storage.
func (t *tsdb) Querier(ctx context.Context, mint int64, maxt int64) (storage.Querier, error) {
return t.queryable.Querier(ctx, mint, maxt)
}
// StartTime returns the oldest timestamp stored in the storage.
func (t *tsdb) StartTime() (int64, error) {
return 0, nil
}
// Close closes the storage and all its underlying resources.
func (t *tsdb) Close() error {
return nil
}