forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult.go
55 lines (45 loc) · 1014 Bytes
/
result.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
package models
import (
"time"
"github.com/grafana/grafana-plugin-sdk-go/data"
)
// +enum
type ResultType string
const (
ResultTypeMatrix ResultType = "matrix"
ResultTypeExemplar ResultType = "exemplar"
ResultTypeVector ResultType = "vector"
ResultTypeUnknown ResultType = ""
)
func ResultTypeFromFrame(frame *data.Frame) ResultType {
if frame.Meta.Custom == nil {
return ResultTypeUnknown
}
custom, ok := frame.Meta.Custom.(map[string]string)
if !ok {
return ResultTypeUnknown
}
rt, ok := custom["resultType"]
if !ok {
return ResultTypeUnknown
}
switch rt {
case ResultTypeMatrix.String():
return ResultTypeMatrix
case ResultTypeExemplar.String():
return ResultTypeExemplar
case ResultTypeVector.String():
return ResultTypeVector
}
return ResultTypeUnknown
}
func (r ResultType) String() string {
return string(r)
}
type Exemplar struct {
SeriesLabels map[string]string
Fields []*data.Field
RowIdx int
Value float64
Timestamp time.Time
}