Skip to content

[surfacers.prometheus] Sanitize label values before exposing them #975

Open

Description

@manugarg

This is particularly a problem for external and browser probes where we don't control label values. We should do this in prometheus surfacer. From official documentation:

label_value can be any sequence of UTF-8 characters, but the backslash (\), double-quote ("), and line feed (\n) characters have to be escaped as \\, \", and \n, respectively.

https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md

Activity

  1. added
    bug
    on Jan 25, 2025
  2. manugarg commented on Jan 25, 2025

    @manugarg
    ContributorAuthor

    We should sanitize label values within browser probe reporter as well, e.g.

    print(`test_status{${testLabels(test)},status="${result.status}"} 1`);
    print(`test_latency{${testLabels(test)},status="${result.status}"} ${result.duration*1000}`);

    for example, a test title -- "do x, then y", will end up being parsed as {test=""do x", because of the bug here: #951.

  3. manugarg commented on Jan 26, 2025

    @manugarg
    ContributorAuthor

    #976 fixes the underlying line parsing problem.

  4. manugarg commented on Jan 27, 2025

    @manugarg
    ContributorAuthor

    Note that after #976 merge, it should be less of an issue. Labels are generated in one of the following ways:

    1. Added by us: probe, dst, etc.
    2. Configured by the user through additional_labels
    3. Parsed from the probe output.

    It's only the last one (3rd) that has caused issues so far. 1st and 2nd options can get spurious values if one deliberately adds such value, e.g. bad probe name.

  5. self-assigned this
    on Jan 27, 2025
  6. manugarg commented on Jan 29, 2025

    @manugarg
    ContributorAuthor

    Since the main problem is fixed, it's really hard to get tripped by it. Marking it as enhancement.

  7. added
    enhancement
    and removed
    bug
    on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions