prometheus / prometheus/alertmanager

Alertmanager not logging bad request error when posting to v2 api

Open
#2,532 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Go
Stars
8.6k
Forks
2.5k
Avg merge
2d 6h
Merged PRs (30d)
61

Description

What did you do?
When I post any json data that is not an array to /v2/api/alerts, alertmanager server doesn't log the bad request error, however, it does when I post it to /v1/api/alerts

e.g.:

$ curl -H "Content-Type: application/json" -d "{}" http://localhost:9093/api/v2/alerts
{"code":400,"message":"parsing alerts body from \"\" failed, because json: cannot unmarshal object into Go value of type models.PostableAlerts"}%

What did you expect to see?
In the alertmanager logs I would expect to see an error. For example for v1 API I would see:

level=error ts=2021-03-31T15:46:14.450Z caller=api.go:780 component=api version=v1 msg="API error" err="bad_data: json: cannot unmarshal object into Go value of type []*types.Alert"

What did you see instead? Under which circumstances?
No logs

Environment

  • System information:
$ uname -srn
Linux 47a38d40724b 4.19.121-linuxkit
  • Alertmanager version:
$ alertmanager --version
alertmanager, version 0.21.0 (branch: HEAD, revision: 4c6c03ebfe21009c546e4d1e9b92c371d67c021d)
  build user:       root@dee35927357f
  build date:       20200617-08:54:02
  go version:       go1.14.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the malformed JSON request against /v2/api/alerts and compare its handling with /v1/api/alerts, using the reported Alertmanager logs as the expected reference. Trace the v2 API request path and identify where the bad request is returned without being logged. Done means malformed non-array JSON returns the existing 400 response and produces an error entry in the Alertmanager logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.