/
query.go
50 lines (42 loc) · 912 Bytes
/
query.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
package metric
import (
"github.com/prometheus/client_golang/prometheus"
)
// 负责一个指标的查询管理
type TcmQuery struct {
Metric *TcmMetric
LatestQueryStatus int
repo TcmMetricRepository
}
type TcmQuerySet []*TcmQuery
func (q *TcmQuery) GetPromMetrics() (pms []prometheus.Metric, err error) {
q.LatestQueryStatus = 2
pms, err = q.Metric.GetLatestPromMetrics(q.repo)
if err != nil {
return
}
q.LatestQueryStatus = 1
return
}
func (qs TcmQuerySet) SplitByBatch(batch int) (steps [][]*TcmQuery) {
total := len(qs)
for i := 0; i < total/batch+1; i++ {
s := i * batch
if s >= total {
continue
}
e := i*batch + batch
if e >= total {
e = total
}
steps = append(steps, qs[s:e])
}
return
}
func NewTcmQuery(m *TcmMetric, repo TcmMetricRepository) (query *TcmQuery, err error) {
query = &TcmQuery{
Metric: m,
repo: repo,
}
return
}