prometheus / prometheus/alertmanager
V2 API swagger file issue re: Matchers
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 8.6k
- Forks
- 2.5k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 61
Description
What did you do?
Created PHP Client from swagger file for CRUD of silences in the alertmanager via the API I am building up a PostableSilence adding Matcher() to Matchers() then adding Matchers() to PostableSilence()
What did you expect to see?
Adding Matcher() to Matchers() Object and then adding Matchers() to PostableSilence() to pass the matcher to the alertmanager.
When getting a silence to be able to loop through Matchers()
What did you see instead? Under which circumstances?
The json created to post to the alert manager is missing matcher resulting in error from alertmanger:
"cannot unmarshal object into Go struct field Silence.matchers of type models.Matchers"
The generated structure looks wrong inside the object compared to the json in the example in the swagger editor of "matchers": {Matchers[array{Matcher}]} matchers needs to be an array of Matcher()
Environment
- Alertmanager version: 0.20.0
- GoVersion: go1.13.5
I have managed to get the PostableSilence to work by bypassing Matchers() altogether and adding an array of Matcher() directly to the Postable silence. I'm a little puzzled why the Matchers Object is even needed? in swagger if you drop Matchers and reference array of matcher in all objects it works:
matchers:
type: array
items:
$ref: '#/definitions/matcher'
I think the above is also causing the issues of missing Matchers() when getting a silence from the API.
I'm very aware v2 is still being worked on but wanted to first check my approach is correct and try and understand why Matchers() exists but brakes the format?
broken:
$silence = new PostableSilence();
$silence->setStartsAt($maintenanceWindow->getStartAsDateTime());
$silence->setEndsAt($maintenanceWindow->getEndAsDateTime());
$silence->setCreatedBy("Portal");
$silence->setComment("created for " . Configure::read('Service.name') . " by maintenance window: {$maintenanceWindow->title}");
$matcher = new Matcher();
$matcher->setName($maintenanceWindow::MATCHER_NAME);
$matcher->setValue($maintenanceWindow->getClusterName());
$matcher->setIsRegex(false);
$matchers = new Matchers();
$matchers->offsetSet(null, $matcher);
$silence->setMatchers($matchers);
return $silence;
working:
$silence = new PostableSilence();
$silence->setStartsAt($maintenanceWindow->getStartAsDateTime());
$silence->setEndsAt($maintenanceWindow->getEndAsDateTime());
$silence->setCreatedBy("Portal");
$silence->setComment("created for " . Configure::read('Service.name') . " by maintenance window: {$maintenanceWindow->title}");
$matcher = new Matcher();
$matcher->setName($maintenanceWindow::MATCHER_NAME);
$matcher->setValue($maintenanceWindow->getClusterName());
$matcher->setIsRegex(false);
// dropped Matchers() here and adding array of Matcher()
$silence->setMatchers([$matcher]);
return $silence;
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the V2 API swagger file and inspect the definitions and references for Matchers and Matcher. Reproduce the PHP client's POST and GET serialization using the examples in the issue; done means matcher arrays are represented consistently and Alertmanager accepts the generated silence payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi, php
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100