Skip to content

Commit ce36ee3

Browse files
committed
Merge branch 'master' into beorn7/histogram
2 parents d698336 + 5486764 commit ce36ee3

File tree

3 files changed

+275
-42
lines changed

3 files changed

+275
-42
lines changed

Makefile.common

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ ifneq ($(shell which gotestsum),)
7878
endif
7979
endif
8080

81-
PROMU_VERSION ?= 0.11.1
81+
PROMU_VERSION ?= 0.12.0
8282
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8383

8484
GOLANGCI_LINT :=
8585
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.36.0
86+
GOLANGCI_LINT_VERSION ?= v1.39.0
8787
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8888
# windows isn't included here because of the path separator being different.
8989
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

api/prometheus/v1/api.go

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const (
123123
epAlertManagers = apiPrefix + "/alertmanagers"
124124
epQuery = apiPrefix + "/query"
125125
epQueryRange = apiPrefix + "/query_range"
126+
epQueryExemplars = apiPrefix + "/query_exemplars"
126127
epLabels = apiPrefix + "/labels"
127128
epLabelValues = apiPrefix + "/label/:name/values"
128129
epSeries = apiPrefix + "/series"
@@ -239,6 +240,8 @@ type API interface {
239240
Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error)
240241
// QueryRange performs a query for the given range.
241242
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)
242245
// Buildinfo returns various build information properties about the Prometheus server
243246
Buildinfo(ctx context.Context) (BuildinfoResult, error)
244247
// Runtimeinfo returns the various runtime information properties about the Prometheus server.
@@ -344,23 +347,28 @@ type Rules []interface{}
344347

345348
// AlertingRule models a alerting rule.
346349
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"`
355361
}
356362

357363
// RecordingRule models a recording rule.
358364
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"`
364372
}
365373

366374
// Alert models an active alert.
@@ -380,12 +388,15 @@ type TargetsResult struct {
380388

381389
// ActiveTarget models an active Prometheus scrape target.
382390
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"`
389400
}
390401

391402
// DroppedTarget models a dropped Prometheus scrape target.
@@ -480,14 +491,17 @@ func (r *AlertingRule) UnmarshalJSON(b []byte) error {
480491
}
481492

482493
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"`
491505
}{}
492506
if err := json.Unmarshal(b, &rule); err != nil {
493507
return err
@@ -500,6 +514,9 @@ func (r *AlertingRule) UnmarshalJSON(b []byte) error {
500514
r.Duration = rule.Duration
501515
r.Labels = rule.Labels
502516
r.LastError = rule.LastError
517+
r.EvaluationTime = rule.EvaluationTime
518+
r.LastEvaluation = rule.LastEvaluation
519+
r.State = rule.State
503520

504521
return nil
505522
}
@@ -519,11 +536,13 @@ func (r *RecordingRule) UnmarshalJSON(b []byte) error {
519536
}
520537

521538
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"`
527546
}{}
528547
if err := json.Unmarshal(b, &rule); err != nil {
529548
return err
@@ -533,6 +552,8 @@ func (r *RecordingRule) UnmarshalJSON(b []byte) error {
533552
r.Name = rule.Name
534553
r.LastError = rule.LastError
535554
r.Query = rule.Query
555+
r.EvaluationTime = rule.EvaluationTime
556+
r.LastEvaluation = rule.LastEvaluation
536557

537558
return nil
538559
}
@@ -570,6 +591,18 @@ func (qr *queryResult) UnmarshalJSON(b []byte) error {
570591
return err
571592
}
572593

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+
573606
// NewAPI returns a new API for the client.
574607
//
575608
// It is safe to use the returned API from multiple goroutines.
@@ -949,7 +982,29 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
949982

950983
var res TSDBResult
951984
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+
}
9521000

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)
9531008
}
9541009

9551010
// Warnings is an array of non critical errors

0 commit comments

Comments
 (0)