Skip to content

Implement json encoder/decoder for regexp - #15383

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

aknuds1 merged 3 commits into
prometheus:mainfrom
yeya24:json-regexp

Conversation

@yeya24

@yeya24 yeya24 commented Nov 11, 2024

Copy link
Copy Markdown
Contributor

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.

@bboreham bboreham left a comment

Copy link
Copy Markdown
Member

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 <[email protected]>
@yeya24

yeya24 commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

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

@aknuds1 aknuds1 left a comment •

Copy link
Copy Markdown
Contributor

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?

Comment thread model/relabel/relabel.go Resolved
Comment thread model/relabel/relabel.go Resolved
Signed-off-by: Ben Ye <[email protected]>

@aknuds1 aknuds1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@muff1nman

Copy link
Copy Markdown

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

juliusv commented Oct 15, 2025

Copy link
Copy Markdown
Member

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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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