Commit Graph

35 Commits

Author SHA1 Message Date
George Robinson 342f6a599c
Add godot linter (#3613)
* Add godot linter

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Remove extra line from LICENSE

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-03-21 11:26:46 +00:00
Matthieu MOREL b81bad8711 use Go standard errors
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-12-08 16:44:13 +01:00
George Robinson 9dbc8b6b91
Support UTF-8 label matchers: Update Stringer for non-Prometheus compliant label names (#3580)
* Update Stringer for non-Prometheus compliant label names

This commit updates the String method to print non-Prometheus
compliant label names in a format that can be parsed in the
UTF-8 parser. Such inputs are never valid in the classic parser.
If the label name is Prometheus compliant, it is still printed
unquoted.

Signed-off-by: George Robinson <george.robinson@grafana.co

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-14 16:25:13 +00:00
George Robinson 8512285e54
Support UTF-8 label matchers: Update compliance tests (#3569)
* Update compliance tests

This commit updates compliance tests to include openmetrics
escape sequences that are not valid in the UTF-8 matchers parser.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add tests for openmetrics escape sequences

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-10-25 09:52:17 +01:00
George Robinson 9f683fc4e7
Document difference between tab and newline in tests (#3383)
Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-06-07 13:32:48 -04:00
George Robinson 93797c3c9d
Add more tests to TestMatchers (#3362)
Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-05-16 09:41:25 +01:00
George Robinson f67d03fe28
Add tests to TestMatchers (#3357)
* Add tests to TestMatchers

This commit adds a number of tests to TestMatchers that asserts
some of the more nuanced behavior when parsing label matchers.

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-05-12 10:32:45 +01:00
Ben Kochie 432ee01c8c
Update Go to 1.19 (#3150)
* Update Go to 1.19

* Update Go.
* Update some Go modules.
* Update Swagger to the latest for Go 1.19 compatibility.
* api/v2: regenerate
* Accommodate to the changes in the client package
* asset/assets_vfsdata.go: regenerate

Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
2022-11-30 17:06:57 +01:00
gotjosh bd89550ce2
Take another approach
Signed-off-by: gotjosh <josue.abreu@gmail.com>
2022-09-30 12:36:32 +01:00
gotjosh 05f073f42f
Ensure matcher values are present when parsing matchers from strings
Fixes #2936

Signed-off-by: gotjosh <josue.abreu@gmail.com>
2022-09-30 12:36:32 +01:00
Matthias Loibl a6d10bd5bc
Update golangci-lint and fix complaints (#2853)
* Copy latest golangci-lint files from Prometheus

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Use grafana/regexp over stdlib regexp

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Fix typos in comments

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Fix goimports complains in import sorting

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* gofumpt all Go files

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Update naming to comply with revive linter

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* config: Fix error messages to be lower case

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* test/cli: Fix error messages to be lower case

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* .golangci.yaml: Remove obsolete space

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* config: Fix expected victorOps error

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Use stdlib regexp

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Clean up Go modules

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
2022-03-25 17:59:51 +01:00
beorn7 2cc5cc4f29 Add deprecation note to pkg directory
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-13 14:21:52 +02:00
Björn Rabenstein fd0929ba9f
Merge pull request #2627 from prometheus/release-0.22
Merge release branch back into master
2021-06-23 13:41:56 +02:00
Bartlomiej Plotka 02346e4e49
matchers: Parse Matcher now expects consistent enclosing with quotes. (#2632)
Fixes https://github.com/prometheus/alertmanager/issues/2630

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
2021-06-23 10:05:49 +01:00
sinkingpoint 6a072dbae3 Default the isEqual flag to true in alertmanager
Solves #2602 - the new version of alertmanager introduces an isEqual
flag to support != matchers in alertmanager silences. Clients set this
to true in the JSON blob sent to the api to indicate a foo=bar matcher,
and to false to indicate foo!=bar. Due to gos unmarshalling, anything
that _doesn't_ include this flag will default to false (i.e. a !=
matcher), so any clients that aren't aware of this flag (such as amtools
before negative matchers and the new api) will not send it, and when you
think you are making a foo=bar matcher, alertmanager will interpret that
as a not equals.

This commit changes the Unmarshaling of the v1matcher struct to default
the IsEqual flag to true, to keep the old behaviour for clients not
setting the flag

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
2021-05-27 20:03:05 +10:00
Kiril Vladimirov f85651f2c4 Marshal Matcher to JSON for API v1 compatibility
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
2021-01-22 17:03:27 +02:00
Kiril Vladimirov 97e0c754c0 Remove NewRegexpMatcher and panic on error instead
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
2021-01-22 17:03:24 +02:00
Kiril Vladimirov 7320d83cbc Replace types.Matcher(s)? with labels.Matcher(s)?
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
2021-01-22 17:02:48 +02:00
Atibhi Agrawal 6b36afbbec
Add negative matchers for routing. (#2434)
Add negative route matchers using label.Matcher

Signed-off-by: aSquare14 <atibhi.a@gmail.com>

Signed-off-by: beorn7 <beorn@grafana.com>

Co-authored-by: Björn Rabenstein <beorn@grafana.com>
2021-01-15 21:11:39 +01:00
beorn7 99e4a4fbae Address code review comments
Signed-off-by: beorn7 <beorn@grafana.com>
2021-01-13 18:49:06 +01:00
beorn7 e1ab2477c0 Fix escaping for `Matcher.String()`
Now the string created will correctly parse back.

Signed-off-by: beorn7 <beorn@grafana.com>
2021-01-13 13:21:30 +01:00
beorn7 f7742393ae labels.Matcher: Add more test cases
Signed-off-by: beorn7 <beorn@grafana.com>
2020-12-23 23:59:25 +01:00
beorn7 3ce1d888d7 labels.ParseMatchers: Allow escaped quotes
Previously, escaped double quotes would still be seen as ending the
quoting, potentially leading to wronk tokenization.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-12-23 22:37:12 +01:00
beorn7 9bb7ab43cd labels.Matcher: Improve regexp and allow escaping
This addresses a number of issues:

- It was impossible to include a literal '"' or a line break in the value.
- It was impossible to include '=', '~', or '!' in the value.
- It was not validated if the label name is valid.
- It was not validated if the value is valid UTF-8.
- No whitespace was allowed around the operator.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-12-23 21:55:30 +01:00
beorn7 e87985a9a8 Add doc comments to labels.ParseMatcher and labels.ParseMatchers
The doc comments do not describe the current (arguably buggy) state,
but the desired state, as it will be implemented in future commits.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-12-23 20:47:35 +01:00
Simon Pasquier e0cc523893
api/v2: add path and method to API v2 logs (#2261)
* api/v2: add path and method to API v2 logs

When an API v2 handler logged a message, the log wouldn't include the
path and method. Since different handlers perform the same validations
(e.g. matchers for alerts and silences), it isn't easy to know which
handler was invoked (though the logged filename
+ line number provides a hint).

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Capitalize messages + improve logs

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-06-02 16:13:31 +02:00
Simon Pasquier e4437ab54f
*: remove dependency on github.com/prometheus/prometheus (#2009)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-09-16 10:56:29 +02:00
Simon Pasquier b676fa79c0 *: update Makefile.common with new staticcheck (#1692)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-01-04 15:37:33 +01:00
Simon Pasquier 3558e6fd9e Migrate from go-bindata to vfsgen (#1532)
* Migrate from go-bindata to vfsgen

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Ensure idempotent generation for vfsgen

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* asset: update generated files

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Fix asset paths for Windows platforms

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Regenerate assets

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Add vfs wrapper that returns constant mod time

This is identical to what we had with go-bindata and avoids the extra
step of storing the identity of the complete file system in another
location.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Additional cleanup

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-09-24 15:12:40 +02:00
Simon Pasquier 49717d91b0 parse: fix parsing for label values with commas (#1395)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-05-28 11:36:47 +02:00
Simon Pasquier 0ebaeccd4b *: add missing license headers
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-05-14 17:37:13 +02:00
Simon Pasquier cb169a5ec6 parse: fix missing argument to fmt.Errorf (#1311) 2018-04-04 10:37:35 +02:00
Stuart Nelson f5df55666b Filter empty matchers correctly 2018-03-20 10:08:58 +01:00
Kellen Fox 3aab66ec3a Amtool implementation (#636)
* Implement alertmanager cli tool 'amtool'

The primary goal of an alertmanager tool is to provide a cli interface
for the prometheus alertmanager.

My vision for this tool has two parts:
  - Silence management (query, add, delete)

  - Alert management (query, maybe more in future?)

Resolves: #567
2017-04-20 11:04:17 +02:00
stuart nelson 1e34f29532 Filter alerts (#633)
* Vendor dependencies.

This updates several old dependencies, removes
some that are no longer needed, and adds
`pkg/labels` from prometheus `dev-2.0` branch.

* Add metrics selector parsing code

This is a temporary simplified re-implementation
of promQL's metric selector parsing.

* Add alerts filtering

Filter alerts through `?filter=` query string.

* Add silences filtering

Filter silences through `?filter=` query string.

* Move `parse` to `pkg/parse`
2017-03-16 11:16:10 +01:00