cortex
cortex copied to clipboard
Extract ipAddress from context
What this PR does:
Extract the IP address from the X-Forwarder-For value in the context. Add it to the duplicate samples error message. The error message now looks like this:
level=error ts=2020-08-06T10:15:13.204489Z caller=push.go:47 org_id=fake traceID=d4cf2362923ab2d msg="push error" err="rpc error: code = Code(400) desc = user=fake: sample with repeated timestamp but different value; last value: 0.015037291, incoming value: 0.015055151 from IP address 1.2.3.4, ::1, ::1 for series {__name__=\"scrape_duration_seconds\", instance=\"localhost:9090\", job=\"prometheus\"}"
The fact that the IP addresses look like '1.2.3.4, ::1, ::1' is a result of the proxy I'm using. Prometheus remote writes to a reverse proxy which forwards the remote write to Cortex. Prometheus, the reverse proxy and Cortex are running locally on a Mac hence the ::1 IP v6 address. The reverse proxy adds the X-Forwarded-For header of 1.2.3.4. This reverse proxy uses the Go httputil.ReverseProxy type which automatically adds the IP address of it's client (Prometheus) as well. So X-Forwarded-For = "1.2.3.4, ::1" coming into Cortex. The last ::1 is then the remote address of the proxy.
Checklist
- [ ] Tests updated
- [ ] Documentation added
- [ ]
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.
:white_check_mark: pracucci
:x: MichelHollands
You have signed the CLA already but the status is still pending? Let us recheck it.