@@ -123,6 +123,7 @@ const (
123
123
epAlertManagers = apiPrefix + "/alertmanagers"
124
124
epQuery = apiPrefix + "/query"
125
125
epQueryRange = apiPrefix + "/query_range"
126
+ epQueryExemplars = apiPrefix + "/query_exemplars"
126
127
epLabels = apiPrefix + "/labels"
127
128
epLabelValues = apiPrefix + "/label/:name/values"
128
129
epSeries = apiPrefix + "/series"
@@ -239,6 +240,8 @@ type API interface {
239
240
Query (ctx context.Context , query string , ts time.Time ) (model.Value , Warnings , error )
240
241
// QueryRange performs a query for the given range.
241
242
QueryRange (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 )
242
245
// Buildinfo returns various build information properties about the Prometheus server
243
246
Buildinfo (ctx context.Context ) (BuildinfoResult , error )
244
247
// Runtimeinfo returns the various runtime information properties about the Prometheus server.
@@ -588,6 +591,18 @@ func (qr *queryResult) UnmarshalJSON(b []byte) error {
588
591
return err
589
592
}
590
593
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
+
591
606
// NewAPI returns a new API for the client.
592
607
//
593
608
// It is safe to use the returned API from multiple goroutines.
@@ -967,7 +982,29 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
967
982
968
983
var res TSDBResult
969
984
return 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 ()
970
995
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 )
971
1008
}
972
1009
973
1010
// Warnings is an array of non critical errors
0 commit comments