prometheus / prometheus/prometheus

Remote read adding external labels might lead to unsorted response

Open
#12,605 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
66.1k
Forks
10.8k
Avg merge
2d 1h
Merged PRs (30d)
131

Description

What did you do?

/api/v1/read is supposed to always give a sorted series set as a response. Consider the following:

External labels are region: foo.

Series without any external labels:


aaa{instance="bbb", job="etcd-prometheus-exporter", service="etcd-prometheus-exporter", toposphere="test1"} 1
aaa{instance="bbb", job="etcd-prometheus-exporter", region="bar", service="etcd-prometheus-exporter", toposphere="test1"} 0
aaa{instance="bbb", job="etcd-prometheus-exporter", region="bar", service="etcd-prometheus-exporter", toposphere="test2"} 0
aaa{instance="bbb", job="etcd-prometheus-exporter", region="foo", service="etcd-prometheus-exporter", toposphere="test1"} 1
aaa{instance="bbb", job="etcd-prometheus-exporter", region="foo", service="etcd-prometheus-exporter", toposphere="test2"} 1

https://github.com/prometheus/prometheus/blob/03e549cc39f017f130028737fa71f8abece6d736/storage/remote/codec.go#L230 here is where Prometheus adds region: foo if it does not exist while iterating.

What did you expect to see?

I expected to see an error? that the response cannot contain the same label set. Not sure, though.

What did you see instead? Under which circumstances?

The result is the following:


aaa{instance="bbb", job="etcd-prometheus-exporter", region="foo", service="etcd-prometheus-exporter", toposphere="test1"} 1
aaa{instance="bbb", job="etcd-prometheus-exporter", region="bar", service="etcd-prometheus-exporter", toposphere="test1"} 0
aaa{instance="bbb", job="etcd-prometheus-exporter", region="bar", service="etcd-prometheus-exporter", toposphere="test2"} 0
aaa{instance="bbb", job="etcd-prometheus-exporter", region="foo", service="etcd-prometheus-exporter", toposphere="test1"} 1
aaa{instance="bbb", job="etcd-prometheus-exporter", region="foo", service="etcd-prometheus-exporter", toposphere="test2"} 1
System information

No response

Prometheus version

No response

Prometheus configuration file

No response

Alertmanager version

No response

Alertmanager configuration file

No response

Logs

No response

Contributor guide

Open the contributing guide

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

Start at storage/remote/codec.go around line 230 and reproduce the reported case through the /api/v1/read endpoint. Determine the intended behavior when external labels create duplicate or unsorted label sets; the work is done when that behavior is explicit and the response handling is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.