Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
0cbee82
Update docker example in migration guide
ArthurSens May 11, 2020
f9d21f1
Only relabelling should apply for scrape_samples_scraped_post_relabel…
brian-brazil Jun 4, 2020
82c7cd3
increase the remote write bucket range (#7323)
BertHartm Jun 4, 2020
6ff4814
Add some unit tests for pkg/labels/labels.go (#7347)
hs0210 Jun 5, 2020
4284dd1
promql: cleanup: use errors.As (#7351)
Jun 5, 2020
e963d95
Update yarn.lock (#7356)
SuperQ Jun 7, 2020
e5ffa8c
Add some unit tests for pkg/labels/labels.go (#7358)
hs0210 Jun 8, 2020
bc1d7d7
Fixed incorrect query results caused by buffer reuse in merge adapter…
pracucci Jun 8, 2020
0f34535
Cut 2.18.2 + cherry pick of query bugfix.
bwplotka Jun 9, 2020
7626115
Cut 2.18.2 release with query bug fix. (#7364)
bwplotka Jun 9, 2020
1a4c97e
Revert "Cut 2.18.2 release with query bug fix. (#7364)" (#7367)
bwplotka Jun 9, 2020
a6600f5
Merge pull request #7368 from prometheus/bugfix-cut-2.18.2-2
bwplotka Jun 9, 2020
8f0a924
Merge branch 'release-2.18' into get2.18.2-to-master
bwplotka Jun 9, 2020
aff3244
Merge pull request #7369 from prometheus/get2.18.2-to-master
bwplotka Jun 9, 2020
66dfb95
*: Consistent Error/Warning handling for SeriesSet iterator: Allowing…
kakkoyun Jun 9, 2020
9593b64
Merge branch 'master' into to-merge-release-2.19
codesome Jun 10, 2020
dff31c2
preserve state on page reload for alert status filters and annotation…
licarpen Jun 10, 2020
b71c00e
Merge pull request #7379 from prometheus/to-merge-release-2.19
codesome Jun 10, 2020
7b1c0d6
discovery/kubernetes: Fix incorrect premature break of reading results
brancz Jun 11, 2020
7c31fe1
Merge pull request #7385 from brancz/fix-flaky-kube-test
brancz Jun 11, 2020
b5d61fb
Add AMI to labels scraped during service discovery. (#7386)
mjrlee Jun 11, 2020
ab6203b
add head compaction test (#7338)
krasi-georgiev Jun 12, 2020
f893786
Fix TSDB test failure (#7394)
Jun 14, 2020
abb4fba
Remove unused env var CLUSTER_NAME. (#7391)
geekodour Jun 14, 2020
7eaffa7
Fix off-by-one error in funcHistogramQuantile / ensureMonotonic (#7393)
linasm Jun 15, 2020
268b4c2
Support extended durations in promtool unit tests (Fixes #6285) (#6297)
neufeldtech Jun 15, 2020
f42ed03
Optimized bstream reader used by XORChunk iterator (#7390)
pracucci Jun 15, 2020
3c753ab
Add missing newline before inline-code block (#7401)
alexmv Jun 16, 2020
6e75546
Update Readme since jsonnetfmt is available in the jsonnet go impleme…
Jun 16, 2020
d5a8f2a
Added the remote read histogram (#7334)
njingco Jun 16, 2020
2dc1797
Merge pull request #7405 from manfontan/update-readme-jsonnetfmt
beorn7 Jun 16, 2020
7b24bb3
Docs: normalize bearer_token_file type (#7408)
Jun 16, 2020
2f12049
tsdb: improve logs when encountering corruption (#7308)
simonpasquier Jun 17, 2020
d634785
tsdb/docs: fix head chunks directory + link from README (#7309)
simonpasquier Jun 17, 2020
cbb1c26
Improve repo sync script
SuperQ Jun 17, 2020
3b529dd
Cleanup bstream_test.go based on post-merge feedback received on #739…
pracucci Jun 18, 2020
fc3aab8
Update NOTICE for the XORChunk (#7415)
codesome Jun 18, 2020
7b4f81b
Merge pull request #7411 from prometheus/superq/sync_changes
SuperQ Jun 18, 2020
c61141c
Add DigitalOcean service discovery (#7407)
Jun 18, 2020
8d3c2f6
Enable WAL compression by default (#7410)
SuperQ Jun 18, 2020
b7c46a8
Merge remote-tracking branch 'upstream/master' into merge-release-2.19
Jun 19, 2020
74207c0
Merge pull request #7421 from codesome/merge-release-2.19
codesome Jun 19, 2020
fb9a1a8
DigitalOcean: limit refresh timeout (#7425)
Jun 20, 2020
1508678
Use 10m timeouts for watches (#7423)
pierresouchay Jun 20, 2020
89fd3eb
repo_sync: fix variable names
Jun 21, 2020
27f89ac
Merge pull request #7428 from roidelapluie/reposync
SuperQ Jun 21, 2020
70b0a34
Exit early on invalid config file (#7399)
harkishen Jun 21, 2020
74a73ba
fix analyze limit not work expected (#7430)
ifooth Jun 22, 2020
9932ff6
Update repo sync policies
SuperQ Jun 22, 2020
08780a9
Merge pull request #7433 from prometheus/superq/force_sync
SuperQ Jun 22, 2020
153f859
Fixed returned API status code on error (#7435)
pracucci Jun 22, 2020
f97d2dd
REACT UI: CollapsibleAlertPanel - value field more friendly human rea…
nunokisc Jun 23, 2020
b41adab
Add unit test case for func FromStrings in labels.go (#7321)
Jun 24, 2020
b788986
storage: Adjusted fully storage layer support for chunk iterators: Re…
bwplotka Jun 24, 2020
cf6890a
web/ui: bump jQuery to 3.5.1 for the legacy UI (#7447)
simonpasquier Jun 24, 2020
325f54b
Add Bartek as remote read maintainer. (#7444)
cstyan Jun 24, 2020
082c17b
Introduce SortedLabelValues/LabelValues to speedup queries for high c…
codesome Jun 25, 2020
ec45e3d
Remove duplicate test in labels_test.go (#7461)
csmarchbanks Jun 25, 2020
d78656c
Pending Samples metric includes samples in channel (#7335)
csmarchbanks Jun 25, 2020
a4c2ea1
Merge remote-tracking branch 'upstream/master' into merge-release-2.19
Jun 26, 2020
cef4dd6
Optimized label regex matcher with literal prefix and/or suffix (#7453)
pracucci Jun 26, 2020
0444a41
Consul: document health meta label (#7466)
Jun 26, 2020
59de58d
Docker Swarm service discovery (#7420)
Jun 26, 2020
d2e6310
Merge pull request #7465 from prometheus/merge-release-2.19
codesome Jun 26, 2020
d17d889
rules: Use narrower interface for rule manager loading of for state (…
brancz Jun 26, 2020
f0a439b
Web: Scroll hash-fragment links with navbar height (#7456)
mhansen Jun 27, 2020
800c0ae
Fix types in k8s+dns docs (#7474)
Jun 28, 2020
9ab072b
Fix golint issue caused by typo (#7475)
Jun 28, 2020
3155642
web/ui/react-app: bump elliptic package version (#7477)
simonpasquier Jun 29, 2020
487f1e0
Add unit test case for func State in alerting.go (#7476)
Jun 29, 2020
1861bf3
tombstones: Fixed Add method in order to support trimming time series…
bwplotka Jun 29, 2020
f50786b
Add unit test case to improve test coverage for quote.go (#7482)
Jun 30, 2020
a94b570
Add a unit test for newAzureResourceFromID in discovery/azure/azure.g…
hs0210 Jun 30, 2020
27b1009
Rename the dashboard in the mixin to 'Prometheus Overview'. (#7489)
tomwilkie Jun 30, 2020
72425d4
Add group() aggregator (#7480)
Jun 30, 2020
578f2b7
Add a unit test for labelsToOpenAPILabelSet in notifier/notifier.go. …
hs0210 Jul 1, 2020
aa452d8
digitalocean: use a safer pagination method (#7498)
Jul 1, 2020
a98be49
Change rule index numbering from 0 to n+1 on errors found in rule fil…
mikejoh Jul 2, 2020
9c9b872
OpenStack SD: Add availability config option, to choose endpoint type…
stefreak Jul 2, 2020
e1f9816
Openstack: Reduce timeouts (#7507)
Jul 2, 2020
74a6959
Docs: fix types (#7508)
Jul 2, 2020
797e48c
support time range in promtool query labels
yeya24 Jun 25, 2020
98a69b7
Fix spelling (#7512)
jbampton Jul 4, 2020
b962029
Add a unit test for MergeLabels in storage/remote/codec.go. (#7499)
hs0210 Jul 5, 2020
e65e2e0
Fix panic from db metrics (#7501)
codesome Jul 5, 2020
f32307b
Increments WAL corruption metric on WAL corruption during checkpointi…
harkishen Jul 5, 2020
ad9449d
Add unit test case for func HasAlertingRules in manager.go (#7502)
Jul 6, 2020
ad7da8f
Merge pull request #7463 from yeya24/support-time-promtool
beorn7 Jul 6, 2020
cf698f7
Add an explanation for the quantile aggregation operator
beorn7 Jul 6, 2020
2786741
openstack tests: use new test.Cleanup function (#7514)
Jul 6, 2020
933aa36
Merge pull request #7522 from prometheus/beorn7/doc
beorn7 Jul 6, 2020
9875afc
Fix the type of the alert name (#7523)
Jul 6, 2020
2f6bf7d
Optimise labels regex matchers containing a literal within the patter…
pracucci Jul 7, 2020
57aac73
Downgrade docker dependency to the stable branch (#7524)
Jul 7, 2020
30505a2
Fix unknown symbol error during head compaction (#7526)
codesome Jul 7, 2020
1f73073
Make without a valid metric identifier (#7533)
slrtbtfs Jul 8, 2020
0f76024
Clarify error messaging, group names must be provided. (#7529)
cstyan Jul 8, 2020
663016e
Add unit test case to improve test coverage for template.go (#7537)
Jul 9, 2020
93ecf0e
Refactor dockerswarm refresh for testing (#7541)
Jul 9, 2020
d017777
Merge pull request #7244 from ArthurSens/master
SuperQ Jul 9, 2020
be96951
Add Docker Swarm configuration example (#7542)
Jul 9, 2020
6a00626
Display dates as well as timestamps in status page (#7544)
sylr Jul 9, 2020
ddefee5
Update dependencies
beorn7 Jul 10, 2020
190addf
Change Scrape Loop mtx to Mutex (#7553)
Jul 11, 2020
492061b
Revert "Fix unknown symbol error during head compaction (#7526)" (#7556)
bwplotka Jul 11, 2020
65d805a
Merge pull request #7551 from prometheus/beorn7/modules
beorn7 Jul 13, 2020
d77b56e
Fix avg_over_time for nan and float64 overflows (#7346)
Jul 13, 2020
823b218
Fixed race between compact (gc, populate) and head append causing unk…
bwplotka Jul 14, 2020
dc10763
Next release shepherds (#7570)
Jul 14, 2020
7a763ff
Avoid empty mmap files by using .tmp files to write headers
Jul 14, 2020
ea01334
Log when starting to create a checkpoint (#7581)
codesome Jul 15, 2020
9c599f1
Add new SD's to alertmanager config (#7584)
Jul 15, 2020
b8a7e80
Fix review comments
Jul 15, 2020
e0067a7
Merge pull request #7573 from codesome/mmap-empty-files
beorn7 Jul 16, 2020
754461b
Reuse the same appender for report and scrape (#7562)
Jul 16, 2020
1760c74
Replay m-map chunks irrespective of WAL (#7589)
codesome Jul 16, 2020
68ac441
Cut 2.20.0-rc.0
beorn7 Jul 15, 2020
d17d20a
Merge pull request #7583 from prometheus/beorn7/release
beorn7 Jul 16, 2020
ee79a6f
Merge tag 'v2.20.0-rc.0' into bump-v0.20.0-rc.0
simonpasquier Jul 17, 2020
009840c
Dockerfile.ocp: switch to Go 1.14
simonpasquier Jul 17, 2020
ac99ccf
vendor: update
simonpasquier Jul 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ jobs:
- setup_remote_docker
- run: ./fuzzit.sh fuzzing

makefile_sync:
repo_sync:
executor: golang
steps:
- checkout
- run: ./scripts/sync_makefiles.sh
- run: ./scripts/sync_repo_files.sh

workflows:
version: 2
Expand Down Expand Up @@ -143,7 +143,7 @@ workflows:
only:
- master
jobs:
- makefile_sync:
- repo_sync:
context: org-context
- fuzzit_fuzzing:
context: org-context
1 change: 0 additions & 1 deletion .github/workflows/funcbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
AUTH_FILE: ${{ secrets.TEST_INFRA_GKE_AUTH }}
BRANCH: ${{ github.event.client_payload.BRANCH }}
BENCH_FUNC_REGEX: ${{ github.event.client_payload.BENCH_FUNC_REGEX }}
CLUSTER_NAME: test-infra
GITHUB_TOKEN: ${{ secrets.PROMBOT_TOKEN }}
GITHUB_ORG: prometheus
GITHUB_REPO: prometheus
Expand Down
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## 2.20.0-rc.0 / 2020-07-16

* [CHANGE] promtool: Changed rule numbering from 0-based to 1-based when reporting rule errors. #7495
* [CHANGE] Remote read: Added `prometheus_remote_storage_read_queries_total` counter and `prometheus_remote_storage_read_request_duration_seconds` histogram, removed `prometheus_remote_storage_remote_read_queries_total` counter.
* [CHANGE] Remote write: Added buckets for longer durations to `prometheus_remote_storage_sent_batch_duration_seconds` histogram.
* [CHANGE] TSDB: WAL compression is enabled by default. #7410
* [FEATURE] PromQL: Added `group()` aggregator. #7480
* [FEATURE] SD: Added Docker Swarm SD. #7420
* [FEATURE] SD: Added DigitalOcean SD. #7407
* [FEATURE] SD: Added Openstack config option to query alternative endpoints. #7494
* [ENHANCEMENT] Configuration: Exit early on invalid config file and signal it with exit code 2. #7399
* [ENHANCEMENT] PromQL: `without` is now a valid metric identifier. #7533
* [ENHANCEMENT] PromQL: Optimized regex label matching for literals within the pattern or as prefix/suffix. #7453 #7503
* [ENHANCEMENT] promtool: Added time range parameters for labels API in promtool. #7463
* [ENHANCEMENT] Remote write: Include samples waiting in channel in pending samples metric. Log number of dropped samples on hard shutdown. #7335
* [ENHANCEMENT] Scrape: Ingest synthetic scrape report metrics atomically with the corresponding scraped metrics. #7562
* [ENHANCEMENT] SD: Reduce timeouts for Openstack SD. #7507
* [ENHANCEMENT] SD: Use 10m timeout for Consul watches. #7423
* [ENHANCEMENT] SD: Added AMI meta label for EC2 SD. #7386
* [ENHANCEMENT] TSDB: Increment WAL corruption metric also on WAL corruption during checkpointing. #7491
* [ENHANCEMENT] TSDB: Improved query performance for high-cardinality labels. #7448
* [ENHANCEMENT] UI: Display dates as well as timestamps in status page. #7544
* [ENHANCEMENT] UI: Improved scrolling when following hash-fragment links. #7456
* [ENHANCEMENT] UI: React UI renders numbers in alerts in a more human-readable way. #7426
* [BUGFIX] API: Fixed error status code in the query API. #7435
* [BUGFIX] PromQL: Fixed `avg` and `avg_over_time` for NaN, Inf, and float64 overflows. #7346
* [BUGFIX] PromQL: Fixed off-by-one error in `histogram_quantile`. #7393
* [BUGFIX] promtool: Support extended durations in rules unit tests. #6297
* [BUGFIX] Scrape: Fix undercounting for `scrape_samples_post_metric_relabeling` in case of errors. #7342
* [BUGFIX] TSDB: Avoid leaving behind empty files in `chunks_head`, causing startup failures. #7573
* [BUGFIX] TSDB: Fixed race between compact (gc, populate) and head append causing unknown symbol error. #7560
* [BUGFIX] TSDB: Fixed unknown symbol error during head compaction. #7526
* [BUGFIX] TSDB: Fixed panic during TSDB metric registration. #7501
* [BUGFIX] TSDB: Fixed `--limit` command line flag in `tsdb` tool. #7430

## 2.19.2 / 2020-06-26

* [BUGFIX] Remote Write: Fix panic when reloading config with modified queue parameters. #7452
Expand All @@ -18,6 +53,9 @@
* [BUGFIX] React UI: Don't null out data when clicking on the current tab. #7243
* [BUGFIX] PromQL: Correctly track number of samples for a query. #7307
* [BUGFIX] PromQL: Return NaN when histogram buckets have 0 observations. #7318

## 2.18.2 / 2020-06-09

* [BUGFIX] TSDB: Fix incorrect query results when using Prometheus with remote reads configured #7361

## 2.18.1 / 2020-05-07
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Dockerfile.ocp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.13 AS builder
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.14 AS builder
WORKDIR /go/src/github.com/prometheus/prometheus
COPY . .
# NOTE(spasquie): the 'build' target regenerates the ReactJS code and the Go
Expand Down
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* `documentation`
* `prometheus-mixin`: @beorn7
* `storage`
* `remote`: @csmarchbanks, @cstyan
* `remote`: @csmarchbanks, @cstyan, @bwplotka
* `tsdb`: @codesome, @krasi-georgiev
* `web`
* `ui`: @juliusv
Expand Down
5 changes: 5 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ https://github.com/samuel/go-zookeeper
Copyright (c) 2013, Samuel Stauffer <samuel@descolada.com>
See https://github.com/samuel/go-zookeeper/blob/master/LICENSE for license details.

Time series compression algorithm from Facebook's Gorilla paper
https://github.com/dgryski/go-tsz
Copyright (c) 2015,2016 Damian Gryski <damian@gryski.com>
See https://github.com/dgryski/go-tsz/blob/master/LICENSE for license details.

We also use code from a large number of npm packages. For details, see:
- https://github.com/prometheus/prometheus/blob/master/web/ui/react-app/package.json
- https://github.com/prometheus/prometheus/blob/master/web/ui/react-app/package-lock.json
Expand Down
4 changes: 3 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Release cadence of first pre-releases being cut is 6 weeks.
| v2.18 | 2020-04-22 | Bartek Plotka (GitHub: @bwplotka) |
| v2.19 | 2020-06-03 | Ganesh Vernekar (GitHub: @codesome) |
| v2.20 | 2020-07-15 | Björn Rabenstein (GitHub: @beorn7) |
| v2.21 | 2020-08-26 | **searching for volunteer** |
| v2.21 | 2020-08-26 | Julien Pivotto (GitHub: @roidelapluie) |
| v2.22 | 2020-10-07 | Frederic Branczyk (GitHub: @brancz) |
| v2.23 | 2020-11-18 | **searching for volunteer** |

If you are interested in volunteering please create a pull request against the [prometheus/prometheus](https://github.com/prometheus/prometheus) repository and propose yourself for the release series of your choice.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.19.2
2.20.0-rc.0
18 changes: 16 additions & 2 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func main() {
Default("false").BoolVar(&cfg.tsdb.AllowOverlappingBlocks)

a.Flag("storage.tsdb.wal-compression", "Compress the tsdb WAL.").
Default("false").BoolVar(&cfg.tsdb.WALCompression)
Default("true").BoolVar(&cfg.tsdb.WALCompression)

a.Flag("storage.remote.flush-deadline", "How long to wait flushing sample on shutdown or config reload.").
Default("1m").PlaceHolder("<duration>").SetValue(&cfg.RemoteFlushDeadline)
Expand Down Expand Up @@ -278,6 +278,12 @@ func main() {
os.Exit(2)
}

// Throw error for invalid config before starting other components.
if _, err := config.LoadFile(cfg.configFile); err != nil {
level.Error(logger).Log("msg", fmt.Sprintf("Error loading config (--config.file=%s)", cfg.configFile), "err", err)
os.Exit(2)
}

cfg.web.ReadTimeout = time.Duration(cfg.webTimeout)
// Default -web.route-prefix to path of -web.external-url.
if cfg.web.RoutePrefix == "" {
Expand Down Expand Up @@ -373,7 +379,7 @@ func main() {

ruleManager = rules.NewManager(&rules.ManagerOptions{
Appendable: fanoutStorage,
TSDB: localStorage,
Queryable: localStorage,
QueryFunc: rules.EngineQueryFunc(queryEngine, fanoutStorage),
NotifyFunc: sendAlerts(notifierManager, cfg.web.ExternalURL.String()),
Context: ctxRule,
Expand Down Expand Up @@ -955,6 +961,14 @@ func (s *readyStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Q
return nil, tsdb.ErrNotReady
}

// ChunkQuerier implements the Storage interface.
func (s *readyStorage) ChunkQuerier(ctx context.Context, mint, maxt int64) (storage.ChunkQuerier, error) {
if x := s.get(); x != nil {
return x.ChunkQuerier(ctx, mint, maxt)
}
return nil, tsdb.ErrNotReady
}

// Appender implements the Storage interface.
func (s *readyStorage) Appender() storage.Appender {
if x := s.get(); x != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/prometheus/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestFailedStartupExitCode(t *testing.T) {
}

fakeInputFile := "fake-input-file"
expectedExitStatus := 1
expectedExitStatus := 2

prom := exec.Command(promPath, "-test.main", "--config.file="+fakeInputFile)
err := prom.Run()
Expand Down
68 changes: 41 additions & 27 deletions cmd/promtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func main() {
queryLabelsCmd := queryCmd.Command("labels", "Run labels query.")
queryLabelsServer := queryLabelsCmd.Arg("server", "Prometheus server to query.").Required().URL()
queryLabelsName := queryLabelsCmd.Arg("name", "Label name to provide label values for.").Required().String()
queryLabelsBegin := queryLabelsCmd.Flag("start", "Start time (RFC3339 or Unix timestamp).").String()
queryLabelsEnd := queryLabelsCmd.Flag("end", "End time (RFC3339 or Unix timestamp).").String()

testCmd := app.Command("test", "Unit testing.")
testRulesCmd := testCmd.Command("rules", "Unit tests for rules.")
Expand Down Expand Up @@ -142,7 +144,7 @@ func main() {
os.Exit(debugAll(*debugAllServer))

case queryLabelsCmd.FullCommand():
os.Exit(QueryLabels(*queryLabelsServer, *queryLabelsName, p))
os.Exit(QueryLabels(*queryLabelsServer, *queryLabelsName, *queryLabelsBegin, *queryLabelsEnd, p))

case testRulesCmd.FullCommand():
os.Exit(RulesUnitTest(*testRulesFiles...))
Expand Down Expand Up @@ -495,30 +497,10 @@ func QuerySeries(url *url.URL, matchers []string, start, end string, p printer)
return 1
}

// TODO: clean up timestamps
var (
minTime = time.Now().Add(-9999 * time.Hour)
maxTime = time.Now().Add(9999 * time.Hour)
)

var stime, etime time.Time

if start == "" {
stime = minTime
} else {
stime, err = parseTime(start)
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing start time:", err)
}
}

if end == "" {
etime = maxTime
} else {
etime, err = parseTime(end)
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing end time:", err)
}
stime, etime, err := parseStartTimeAndEndTime(start, end)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}

// Run query against client.
Expand All @@ -537,7 +519,7 @@ func QuerySeries(url *url.URL, matchers []string, start, end string, p printer)
}

// QueryLabels queries for label values against a Prometheus server.
func QueryLabels(url *url.URL, name string, p printer) int {
func QueryLabels(url *url.URL, name string, start, end string, p printer) int {
config := api.Config{
Address: url.String(),
}
Expand All @@ -549,10 +531,16 @@ func QueryLabels(url *url.URL, name string, p printer) int {
return 1
}

stime, etime, err := parseStartTimeAndEndTime(start, end)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}

// Run query against client.
api := v1.NewAPI(c)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
val, warn, err := api.LabelValues(ctx, name)
val, warn, err := api.LabelValues(ctx, name, stime, etime)
cancel()

for _, v := range warn {
Expand All @@ -568,6 +556,32 @@ func QueryLabels(url *url.URL, name string, p printer) int {
return 0
}

func parseStartTimeAndEndTime(start, end string) (time.Time, time.Time, error) {
var (
minTime = time.Now().Add(-9999 * time.Hour)
maxTime = time.Now().Add(9999 * time.Hour)
err error
)

stime := minTime
etime := maxTime

if start != "" {
stime, err = parseTime(start)
if err != nil {
return stime, etime, errors.Wrap(err, "error parsing start time")
}
}

if end != "" {
etime, err = parseTime(end)
if err != nil {
return stime, etime, errors.Wrap(err, "error parsing end time")
}
}
return stime, etime, nil
}

func parseTime(s string) (time.Time, error) {
if t, err := strconv.ParseFloat(s, 64); err == nil {
s, ns := math.Modf(t)
Expand Down
13 changes: 13 additions & 0 deletions cmd/promtool/testdata/alerts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is the rules file.

groups:
- name: example
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
21 changes: 21 additions & 0 deletions cmd/promtool/testdata/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
rule_files:
- alerts.yml

evaluation_interval: 1m

tests:
- interval: 1m
input_series:
- series: 'up{job="prometheus", instance="localhost:9090"}'
values: "0+0x1440"
alert_rule_test:
- eval_time: 1d
alertname: InstanceDown
exp_alerts:
- exp_labels:
severity: page
instance: localhost:9090
job: prometheus
exp_annotations:
summary: "Instance localhost:9090 down"
description: "localhost:9090 of job prometheus has been down for more than 5 minutes."
Loading