Skip to content

ui: Allow viewing detailed relabeling steps for each discovered target#17337

Merged
juliusv merged 1 commit intomainfrom
ui/visualize-relabel-steps
Nov 2, 2025
Merged

ui: Allow viewing detailed relabeling steps for each discovered target#17337
juliusv merged 1 commit intomainfrom
ui/visualize-relabel-steps

Conversation

@juliusv
Copy link
Member

@juliusv juliusv commented 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)

relabel-steps.mp4

Fixes #17283

[FEATURE] UI: Allow viewing detailed relabeling steps for each discovered target

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 juliusv force-pushed the ui/visualize-relabel-steps branch from fe7e54a to 8b1bd7d Compare October 15, 2025 13:33
@juliusv
Copy link
Member Author

juliusv commented Oct 15, 2025

Adding @yeya24 to determine how much trouble it would cause for Thanos to rename those relabeling config JSON export fields to their original snake_case versions again.

@juliusv juliusv requested a review from Nexucis October 15, 2025 13:34
@roidelapluie
Copy link
Member

roidelapluie commented Oct 16, 2025

Hello,

I do believe this would cause breakage.

We could have a (pseudo-code, not tested):

type RelabelStep struct {
    Rule   relabelConfigV2 `json:"rule"`
    Output labels.Labels   `json:"output"`
    Keep   bool            `json:"keep"`
}

type relabelConfigV2 struct {
    SourceLabels []string `json:"source_labels,omitempty"`
    Separator    string   `json:"separator,omitempty"`
    Regex        string   `json:"regex,omitempty"`
    Modulus      uint64   `json:"modulus,omitempty"`
    TargetLabel  string   `json:"target_label,omitempty"`
    Replacement  string   `json:"replacement,omitempty"`
    Action       string   `json:"action,omitempty"`
}

in the API response and do something like:

func (api *API) targetRelabelSteps(r *http.Request) apiFuncResult {
    ...
    for i, rule := range rules {
        outLabels, keep := relabel.Process(lbls, rules[:i+1]...)

        steps[i] = RelabelStep{
            Rule:   convertRelabelConfigV2(rule),
            Output: outLabels,
            Keep:   keep,
        }
    }

    return apiFuncResult{&RelabelStepsResponse{Steps: steps}, nil, nil, nil}
}

func convertRelabelConfigV2(rule *relabel.Config) *relabelConfigV2 {
    return &relabelConfigV2{
        SourceLabels: rule.SourceLabels,
        Separator:    rule.Separator,
        Regex:        rule.Regex.String(),
        Modulus:      rule.Modulus,
        TargetLabel:  rule.TargetLabel,
        Replacement:  rule.Replacement,
        Action:       string(rule.Action),
    }
}

I am not a great fan of that mix between both, but I like the new API to use snake_case, but dislike breaking API stability promises...

@juliusv
Copy link
Member Author

juliusv commented Oct 16, 2025

@roidelapluie Yeah, I had a copy of the relabel config struct in my standalone Relabeler tool for similar reasons. But I think this kind of duplication and field transfer is always a bit annoying and brittle, especially if someone forgets to update both versions when there's a change.

I am not a great fan of that mix between both, but I like the new API to use snake_case, but dislike breaking API stability promises...

In terms of breakage, I think this should not affect Prometheus itself, as I don't think any of our APIs returns relabel configs in JSON format. The JSON serialization was only added by @yeya24 a year ago in #15383 because Thanos wanted to store the relabel configs in their Thanos metadata files. But I'm wondering if Thanos could deal with this instead of having to bake the duplication into the Prometheus codebase.

@roidelapluie
Copy link
Member

Oh I see. That should be fine then, pending @yeya24's answer.

Copy link
Member

@Nexucis Nexucis left a comment

Choose a reason for hiding this comment

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

If @yeya24 is fine with the changes, then we should be good, code looks fine for me !

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

image

@roeybenarieh
Copy link

Would love to get your help @yeya24!

@juliusv
Copy link
Member Author

juliusv commented Oct 26, 2025

Thanks everyone - I'd say let's give this 3 more days to check for any response from @yeya24, after which I'd just merge it. I think keeping the field names the same between JSON + YAML is good, and Thanos should be able to manage the change somehow, or in the worst case we can still revert things.

@roeybenarieh
Copy link

@juliusv would you like to merge?

@juliusv
Copy link
Member Author

juliusv commented Nov 2, 2025

Thanks for reminding me - will merge :)

@juliusv juliusv merged commit 0093e21 into main Nov 2, 2025
46 checks passed
@juliusv juliusv deleted the ui/visualize-relabel-steps branch November 2, 2025 12:51
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.

Better message for dropped target reason.

5 participants