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
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package exemplar
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/promlib/models"
|
||||
)
|
||||
|
||||
type Sampler interface {
|
||||
Add(models.Exemplar)
|
||||
SetStep(time.Duration)
|
||||
Sample() []models.Exemplar
|
||||
Reset()
|
||||
}
|
||||
|
||||
var _ Sampler = (*NoOpSampler)(nil)
|
||||
|
||||
type NoOpSampler struct {
|
||||
exemplars []models.Exemplar
|
||||
}
|
||||
|
||||
func NewNoOpSampler() Sampler {
|
||||
return &NoOpSampler{
|
||||
exemplars: []models.Exemplar{},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *NoOpSampler) Add(ex models.Exemplar) {
|
||||
e.exemplars = append(e.exemplars, ex)
|
||||
}
|
||||
|
||||
func (e *NoOpSampler) SetStep(time.Duration) {
|
||||
// noop
|
||||
}
|
||||
|
||||
func (e *NoOpSampler) Sample() []models.Exemplar {
|
||||
sort.SliceStable(e.exemplars, func(i, j int) bool {
|
||||
return e.exemplars[i].Timestamp.Before(e.exemplars[j].Timestamp)
|
||||
})
|
||||
return e.exemplars
|
||||
}
|
||||
|
||||
func (e *NoOpSampler) Reset() {
|
||||
e.exemplars = []models.Exemplar{}
|
||||
}
|
||||
Reference in New Issue
Block a user