@@ -123,6 +123,7 @@ const (
123123epAlertManagers = apiPrefix + "/alertmanagers"
124124epQuery = apiPrefix + "/query"
125125epQueryRange = apiPrefix + "/query_range"
126+ epQueryExemplars = apiPrefix + "/query_exemplars"
126127epLabels = apiPrefix + "/labels"
127128epLabelValues = apiPrefix + "/label/:name/values"
128129epSeries = apiPrefix + "/series"
@@ -239,6 +240,8 @@ type API interface {
239240Query (ctx context.Context , query string , ts time.Time ) (model.Value , Warnings , error )
240241// QueryRange performs a query for the given range.
241242QueryRange (ctx context.Context , query string , r Range ) (model.Value , Warnings , error )
243+ // QueryExemplars performs a query for exemplars by the given query and time range.
244+ QueryExemplars (ctx context.Context , query string , startTime time.Time , endTime time.Time ) ([]ExemplarQueryResult , error )
242245// Buildinfo returns various build information properties about the Prometheus server
243246Buildinfo (ctx context.Context ) (BuildinfoResult , error )
244247// Runtimeinfo returns the various runtime information properties about the Prometheus server.
@@ -588,6 +591,18 @@ func (qr *queryResult) UnmarshalJSON(b []byte) error {
588591return err
589592}
590593
594+ // Exemplar is additional information associated with a time series.
595+ type Exemplar struct {
596+ Labels model.LabelSet `json:"labels"`
597+ Value model.SampleValue `json:"value"`
598+ Timestamp model.Time `json:"timestamp"`
599+ }
600+
601+ type ExemplarQueryResult struct {
602+ SeriesLabels model.LabelSet `json:"seriesLabels"`
603+ Exemplars []Exemplar `json:"exemplars"`
604+ }
605+
591606// NewAPI returns a new API for the client.
592607//
593608// It is safe to use the returned API from multiple goroutines.
@@ -967,7 +982,29 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
967982
968983var res TSDBResult
969984return res , json .Unmarshal (body , & res )
985+ }
986+
987+ func (h * httpAPI ) QueryExemplars (ctx context.Context , query string , startTime time.Time , endTime time.Time ) ([]ExemplarQueryResult , error ) {
988+ u := h .client .URL (epQueryExemplars , nil )
989+ q := u .Query ()
990+
991+ q .Set ("query" , query )
992+ q .Set ("start" , formatTime (startTime ))
993+ q .Set ("end" , formatTime (endTime ))
994+ u .RawQuery = q .Encode ()
970995
996+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
997+ if err != nil {
998+ return nil , err
999+ }
1000+
1001+ _ , body , _ , err := h .client .Do (ctx , req )
1002+ if err != nil {
1003+ return nil , err
1004+ }
1005+
1006+ var res []ExemplarQueryResult
1007+ return res , json .Unmarshal (body , & res )
9711008}
9721009
9731010// Warnings is an array of non critical errors
0 commit comments