@@ -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.
@@ -344,23 +347,28 @@ type Rules []interface{}
344
347
345
348
// AlertingRule models a alerting rule.
346
349
type AlertingRule struct {
347
- Name string `json:"name"`
348
- Query string `json:"query"`
349
- Duration float64 `json:"duration"`
350
- Labels model.LabelSet `json:"labels"`
351
- Annotations model.LabelSet `json:"annotations"`
352
- Alerts []* Alert `json:"alerts"`
353
- Health RuleHealth `json:"health"`
354
- LastError string `json:"lastError,omitempty"`
350
+ Name string `json:"name"`
351
+ Query string `json:"query"`
352
+ Duration float64 `json:"duration"`
353
+ Labels model.LabelSet `json:"labels"`
354
+ Annotations model.LabelSet `json:"annotations"`
355
+ Alerts []* Alert `json:"alerts"`
356
+ Health RuleHealth `json:"health"`
357
+ LastError string `json:"lastError,omitempty"`
358
+ EvaluationTime float64 `json:"evaluationTime"`
359
+ LastEvaluation time.Time `json:"lastEvaluation"`
360
+ State string `json:"state"`
355
361
}
356
362
357
363
// RecordingRule models a recording rule.
358
364
type RecordingRule struct {
359
- Name string `json:"name"`
360
- Query string `json:"query"`
361
- Labels model.LabelSet `json:"labels,omitempty"`
362
- Health RuleHealth `json:"health"`
363
- LastError string `json:"lastError,omitempty"`
365
+ Name string `json:"name"`
366
+ Query string `json:"query"`
367
+ Labels model.LabelSet `json:"labels,omitempty"`
368
+ Health RuleHealth `json:"health"`
369
+ LastError string `json:"lastError,omitempty"`
370
+ EvaluationTime float64 `json:"evaluationTime"`
371
+ LastEvaluation time.Time `json:"lastEvaluation"`
364
372
}
365
373
366
374
// Alert models an active alert.
@@ -380,12 +388,15 @@ type TargetsResult struct {
380
388
381
389
// ActiveTarget models an active Prometheus scrape target.
382
390
type ActiveTarget struct {
383
- DiscoveredLabels map [string ]string `json:"discoveredLabels"`
384
- Labels model.LabelSet `json:"labels"`
385
- ScrapeURL string `json:"scrapeUrl"`
386
- LastError string `json:"lastError"`
387
- LastScrape time.Time `json:"lastScrape"`
388
- Health HealthStatus `json:"health"`
391
+ DiscoveredLabels map [string ]string `json:"discoveredLabels"`
392
+ Labels model.LabelSet `json:"labels"`
393
+ ScrapePool string `json:"scrapePool"`
394
+ ScrapeURL string `json:"scrapeUrl"`
395
+ GlobalURL string `json:"globalUrl"`
396
+ LastError string `json:"lastError"`
397
+ LastScrape time.Time `json:"lastScrape"`
398
+ LastScrapeDuration float64 `json:"lastScrapeDuration"`
399
+ Health HealthStatus `json:"health"`
389
400
}
390
401
391
402
// DroppedTarget models a dropped Prometheus scrape target.
@@ -480,14 +491,17 @@ func (r *AlertingRule) UnmarshalJSON(b []byte) error {
480
491
}
481
492
482
493
rule := struct {
483
- Name string `json:"name"`
484
- Query string `json:"query"`
485
- Duration float64 `json:"duration"`
486
- Labels model.LabelSet `json:"labels"`
487
- Annotations model.LabelSet `json:"annotations"`
488
- Alerts []* Alert `json:"alerts"`
489
- Health RuleHealth `json:"health"`
490
- LastError string `json:"lastError,omitempty"`
494
+ Name string `json:"name"`
495
+ Query string `json:"query"`
496
+ Duration float64 `json:"duration"`
497
+ Labels model.LabelSet `json:"labels"`
498
+ Annotations model.LabelSet `json:"annotations"`
499
+ Alerts []* Alert `json:"alerts"`
500
+ Health RuleHealth `json:"health"`
501
+ LastError string `json:"lastError,omitempty"`
502
+ EvaluationTime float64 `json:"evaluationTime"`
503
+ LastEvaluation time.Time `json:"lastEvaluation"`
504
+ State string `json:"state"`
491
505
}{}
492
506
if err := json .Unmarshal (b , & rule ); err != nil {
493
507
return err
@@ -500,6 +514,9 @@ func (r *AlertingRule) UnmarshalJSON(b []byte) error {
500
514
r .Duration = rule .Duration
501
515
r .Labels = rule .Labels
502
516
r .LastError = rule .LastError
517
+ r .EvaluationTime = rule .EvaluationTime
518
+ r .LastEvaluation = rule .LastEvaluation
519
+ r .State = rule .State
503
520
504
521
return nil
505
522
}
@@ -519,11 +536,13 @@ func (r *RecordingRule) UnmarshalJSON(b []byte) error {
519
536
}
520
537
521
538
rule := struct {
522
- Name string `json:"name"`
523
- Query string `json:"query"`
524
- Labels model.LabelSet `json:"labels,omitempty"`
525
- Health RuleHealth `json:"health"`
526
- LastError string `json:"lastError,omitempty"`
539
+ Name string `json:"name"`
540
+ Query string `json:"query"`
541
+ Labels model.LabelSet `json:"labels,omitempty"`
542
+ Health RuleHealth `json:"health"`
543
+ LastError string `json:"lastError,omitempty"`
544
+ EvaluationTime float64 `json:"evaluationTime"`
545
+ LastEvaluation time.Time `json:"lastEvaluation"`
527
546
}{}
528
547
if err := json .Unmarshal (b , & rule ); err != nil {
529
548
return err
@@ -533,6 +552,8 @@ func (r *RecordingRule) UnmarshalJSON(b []byte) error {
533
552
r .Name = rule .Name
534
553
r .LastError = rule .LastError
535
554
r .Query = rule .Query
555
+ r .EvaluationTime = rule .EvaluationTime
556
+ r .LastEvaluation = rule .LastEvaluation
536
557
537
558
return nil
538
559
}
@@ -570,6 +591,18 @@ func (qr *queryResult) UnmarshalJSON(b []byte) error {
570
591
return err
571
592
}
572
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
+
573
606
// NewAPI returns a new API for the client.
574
607
//
575
608
// It is safe to use the returned API from multiple goroutines.
@@ -949,7 +982,29 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
949
982
950
983
var res TSDBResult
951
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 ()
995
+
996
+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
997
+ if err != nil {
998
+ return nil , err
999
+ }
952
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 )
953
1008
}
954
1009
955
1010
// Warnings is an array of non critical errors
0 commit comments