Fix segmentation violation when IsEqual == nil#2634
Fix segmentation violation when IsEqual == nil#2634jmdacruz wants to merge 1 commit intoprometheus:mainfrom
Conversation
c7fd917 to
a585630
Compare
|
Thank you. How can we reproduce this? 1. in tests and 2. pratically when using the command line? Thanks! |
|
For (1), I would suggest a unit test such as this one ( package format
import (
"reflect"
"testing"
"github.com/prometheus/alertmanager/api/v2/models"
"github.com/prometheus/alertmanager/pkg/labels"
)
func TestTabelsMatcher(t *testing.T) {
trueValue := true
tests := map[string]struct {
value string
input models.Matcher
expected *labels.Matcher
}{
"nil IsEqual": {
value: "some value",
input: models.Matcher{IsEqual: nil, IsRegex: &trueValue},
expected: &labels.Matcher{Type: labels.MatchNotRegexp},
},
}
for name, test := range tests {
test.input.Name = &name
test.expected.Name = name
test.input.Value = &test.value
test.expected.Value = test.value
t.Run(name, func(t *testing.T) {
got := labelsMatcher(test.input)
if !reflect.DeepEqual(got, test.expected) {
t.Fail()
}
})
}
}For (2), I was able to reproduce the issue by simply running |
a585630 to
870d2c8
Compare
|
@roidelapluie I just amended the commit by also fixing the case of a nil value for |
870d2c8 to
5ebaa7b
Compare
|
@roidelapluie I created the following version: "3.8"
services:
alertmanager:
image: prom/alertmanager:v0.21.0
ports:
- 9093:9093
setup:
image: prom/alertmanager:v0.22.2
entrypoint: amtool
depends_on:
- alertmanager
command:
- --alertmanager.url=http://alertmanager:9093
- silence
- add
- --author=jmdacruz
- --duration=90d
- --comment="foobar"
- namespace=~foobar
test:
image: prom/alertmanager:v0.22.2
entrypoint: amtool
depends_on:
- alertmanager
command:
- --alertmanager.url=http://alertmanager:9093
- silence
- queryVersion This should trigger the following exception: |
|
@roidelapluie I've updated my previous comment with the proper way of reproducing this issue |
roidelapluie
left a comment
There was a problem hiding this comment.
Thanks, I have left a comment.
Signed-off-by: Marcelo Da cruz pinto <mdacruzpinto@proofpoint.com>
5ebaa7b to
7e9b051
Compare
|
Now I am actually wondering if we should support it. You could create silences to 0.21 that would not be supported. So you would ask amtool to create a silence for env!=prod and it would create a silence env=prod. I think we should to our best so that old clients can talk to new alertmanager, I do not think we should do the opposite. What do you think? |
|
So maybe instead of guessing or panicking we should error properly. |
|
I think it makes sense @roidelapluie. I'm quite new to That said, I noticed something interesting while trying different combinations, let me know if this behavior is expected: I modified my version: "3.8"
services:
alertmanager:
image: prom/alertmanager:${TAG}
ports:
- 9093:9093
setup:
image: prom/alertmanager:${TAG}
entrypoint: amtool
depends_on:
- alertmanager
command:
- --alertmanager.url=http://alertmanager:9093
- silence
- add
- --author=jmdacruz
- --duration=90d
- --comment="foobar"
- namespace=~foobar
test:
image: prom/alertmanager:${TAG}
entrypoint: amtool
depends_on:
- alertmanager
command:
- --alertmanager.url=http://alertmanager:9093
- silence
- query
- namespace=~.+I get two distinct results when running with version The above finds the silence: but with |
|
Note: In the long run we will release a 1.0 release and the clients should be compatible across 1.x releases. |
|
In that case, then maybe surfacing the error for now should be enough. I'll work on changing the PR, see what I can come up with. |
|
The silence not found is expected. The silence has - namespace= |
This is the best we can do to make amtool support old releases. Supersedes prometheus#2634 Fix prometheus#2666 Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
|
Done in #2668, thanks! |
|
No problem! glad to be a contributor! |
Running
amtool silence queryis currently broken with a segmentation fault. This PR adds a default value for IsEqual on thelabelsMatcherfunction. Themodel.Matcherstruct definesIsEqualasomitempty:alertmanager/api/v2/models/matcher.go
Line 35 in fd0929b
which means that this pointer could be nil. The
labelsMatcherfunction is not checking for nil, which causes a segmentation fault:alertmanager/cli/format/format.go
Lines 53 to 67 in fd0929b