-
Notifications
You must be signed in to change notification settings - Fork 53
/
prometheus.go
70 lines (58 loc) · 1.69 KB
/
prometheus.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
package query
/*
Make sure pre-configured metrics can be exported as valid prometheus/ promql
to the SLO api.
*/
import (
"net/http"
"regexp"
"github.com/prometheus/client_golang/prometheus"
api "github.com/rancher/opni/plugins/slo/pkg/apis/slo"
)
type PrometheusQueryImpl struct {
name string
GoodQuery Query
TotalQuery Query
LabelRegex regexp.Regexp
datasource string
description string
collector prometheus.Collector
goodEventsGen func(w http.ResponseWriter, r *http.Request)
badEventsGen func(w http.ResponseWriter, r *http.Request)
}
// The actual metricId and window are only known at SLO creation time
func (p *PrometheusQueryImpl) Construct(service *api.ServiceInfo) (*SLOQueryResult, error) {
goodQueryStr, err := p.GoodQuery.Construct(service)
if err != nil {
return nil, err
}
totalQueryStr, err := p.TotalQuery.Construct(service)
if err != nil {
return nil, err
}
return &SLOQueryResult{GoodQuery: goodQueryStr, TotalQuery: totalQueryStr}, nil
}
func (p *PrometheusQueryImpl) Datasource() string {
return p.datasource
}
func (p *PrometheusQueryImpl) Description() string {
return p.description
}
func (p *PrometheusQueryImpl) Name() string {
return p.name
}
func (p *PrometheusQueryImpl) GetGoodQuery() Query {
return p.GoodQuery
}
func (p *PrometheusQueryImpl) GetTotalQuery() Query {
return p.TotalQuery
}
func (p *PrometheusQueryImpl) GetCollector() prometheus.Collector {
return p.collector
}
func (p *PrometheusQueryImpl) GetGoodEventGenerator() func(w http.ResponseWriter, r *http.Request) {
return p.goodEventsGen
}
func (p *PrometheusQueryImpl) GetBadEventGenerator() func(w http.ResponseWriter, r *http.Request) {
return p.badEventsGen
}