Skip to content

Implement json encoder/decoder for regexp#15383

Merged
aknuds1 merged 3 commits intoprometheus:mainfrom
yeya24:json-regexp
Nov 24, 2024
Merged

Implement json encoder/decoder for regexp#15383
aknuds1 merged 3 commits intoprometheus:mainfrom
yeya24:json-regexp

Conversation

@yeya24
Copy link
Contributor

@yeya24 yeya24 commented Nov 11, 2024

There is a usecase in Thanos where we need to marshal relabel.Config to JSON and store in Thanos metadata file. This PR implements the corresponding JSON encoding and decoding function for Regexp. Otherwise it causes panic.

This should fix thanos-io/thanos#7844.

Signed-off-by: Ben Ye <benye@amazon.com>
Copy link
Member

@bboreham bboreham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want JSON to be inconsistent from YAML?
In YAML we just give the string; your PR has a sub-field regex:.

Also I am wondering why Config doesn't need anything extra to marshal JSON.

Signed-off-by: Ben Ye <benye@amazon.com>
@yeya24
Copy link
Contributor Author

yeya24 commented Nov 12, 2024

@bboreham Thanks I fixed the implementation. Also added json tags.

Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, but why not use the standard JSON camelCase as we do elsewhere?

Signed-off-by: Ben Ye <benye@amazon.com>
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@muff1nman
Copy link

FYI: this broke the draft implementation I had for #8511

muff1nman added a commit to muff1nman/prometheus that referenced this pull request May 16, 2025
@juliusv
Copy link
Member

juliusv commented Oct 15, 2025

FYI: this broke the draft implementation I had for #8511

I also am running into a use case where I want to get back a relabel config through the API (a new API endpoint for analyzing relabeling steps in the UI), and the JSON encoding differing from the YAML field names is disruptive. I would have to un-camelcase the field names in the UI again to show the original names. Maybe translating existing well-known config field names into camelCase isn't the best thing to do here after all?

@yeya24 How much would it hurt you (or Thanos) if this was changed back to the original field names in JSON output?

juliusv added a commit that referenced this pull request Oct 15, 2025
This adds:

* A `ScrapePoolConfig()` method to the scrape manager that allows getting
  the scrape config for a given pool.
* An API endpoint at `/api/v1/targets/relabel_steps` that takes a pool name
  and a label set of a target and returns a detailed list of applied
  relabeling rules and their output for each step.
* A "show relabeling" link/button for each target on the discovery page
  that shows the detailed flow of all relabeling rules (based on the API
  response) for that target.

Note that this changes the JSON encoding of the relabeling rule config
struct to output the original snake_case (instead of camelCase) field names,
and before merging, we need to be sure that's ok :) See my comment about
that at #15383 (comment)

Fixes #17283

Signed-off-by: Julius Volz <julius.volz@gmail.com>
juliusv added a commit that referenced this pull request Oct 15, 2025
This adds:

* A `ScrapePoolConfig()` method to the scrape manager that allows getting
  the scrape config for a given pool.
* An API endpoint at `/api/v1/targets/relabel_steps` that takes a pool name
  and a label set of a target and returns a detailed list of applied
  relabeling rules and their output for each step.
* A "show relabeling" link/button for each target on the discovery page
  that shows the detailed flow of all relabeling rules (based on the API
  response) for that target.

Note that this changes the JSON encoding of the relabeling rule config
struct to output the original snake_case (instead of camelCase) field names,
and before merging, we need to be sure that's ok :) See my comment about
that at #15383 (comment)

Fixes #17283

Signed-off-by: Julius Volz <julius.volz@gmail.com>
juliusv added a commit that referenced this pull request Oct 15, 2025
This adds:

* A `ScrapePoolConfig()` method to the scrape manager that allows getting
  the scrape config for a given pool.
* An API endpoint at `/api/v1/targets/relabel_steps` that takes a pool name
  and a label set of a target and returns a detailed list of applied
  relabeling rules and their output for each step.
* A "show relabeling" link/button for each target on the discovery page
  that shows the detailed flow of all relabeling rules (based on the API
  response) for that target.

Note that this changes the JSON encoding of the relabeling rule config
struct to output the original snake_case (instead of camelCase) field names,
and before merging, we need to be sure that's ok :) See my comment about
that at #15383 (comment)

Fixes #17283

Signed-off-by: Julius Volz <julius.volz@gmail.com>
muff1nman added a commit to muff1nman/prometheus that referenced this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

thanos tools bucket rewrite fails with a segmentation violation on v0.36.0 and later of thanos.

5 participants