grafana/pkg/promlib/models/result.go
ismail simsek 3fb6319d1b
Prometheus: Introduce prometheus backend library (#83952)
* Move files to prometheus-library

* refactor core prometheus to use prometheus-library

* modify client transport options

* mock

* have a type

* import aliases

* rename

* call the right method

* remove unrelated test from the library

* update codeowners

* go work sync

* update go.work.sum

* make swagger-clean && make openapi3-gen

* add promlib to makefile

* remove clilogger

* Export the function

* update unit test

* add prometheus_test.go

* fix mock type

* use mapUtil from grafana-plugin-sdk-go
2024-03-11 17:22:33 +01:00

56 lines
1014 B
Go

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
}