Don't escape UTF-8 names by default for OpenMetrics 2.0
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- java
- Lĩnh vực
- api, backend, documentation
Hướng nghiên cứu
Start with prometheus-metrics-config/.../EscapingScheme.java, PrometheusScrapeHandler.java, and ExpositionFormats.java, then inspect how Accept clauses are parsed and matched. Add coverage in ExpositionFormatsTest and a scrape-handler test for OM 2.0, explicit escaping, older formats, and contentNegotiation=false. Update the referenced escaping schemes documentation and verify the linked pull request before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When a scraper negotiates OpenMetrics 2.0 (Accept: application/openmetrics-text;version=2.0.0) without an escaping parameter, PrometheusScrapeHandler escapes UTF-8 metric and label names with EscapingScheme.DEFAULT (underscores). OpenMetrics 2.0 supports UTF-8 names natively and doesn't define an escaping parameter at all, so we could assume that scraper asking for 2.0.0 already supports UTF-8 names. In that case we shouldn't escape by default.
Prometheus main doesn't send escaping for OM 2.0 (https://github.com/prometheus/prometheus/blob/961c9ba40923ca4d7adf4a7a9167e56d0406df83/scrape/scrape.go#L794-L800), so UTF-8 names are currently escaped to underscores when scraping a Java target with OM 2.0. There's a Prometheus-side workaround in https://github.com/prometheus/prometheus/compare/main...bwplotka/om2-accept-escaping, but the default here should be fixed regardless.
The escaping scheme is chosen without looking at the selected format:
EscapingScheme.fromAcceptHeaderreturnsDEFAULTwhen there's noescapingterm: https://github.com/prometheus/client_java/blob/9e9deb6b9e591c2a62b12882d8a987f120661b71/prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/EscapingScheme.java#L29-L67.PrometheusScrapeHandlercomputes it before, and separately from,findWriter: https://github.com/prometheus/client_java/blob/9e9deb6b9e591c2a62b12882d8a987f120661b71/prometheus-metrics-exporter-common/src/main/java/io/prometheus/metrics/exporter/common/PrometheusScrapeHandler.java#L73-L91.ExpositionFormats.findWriterpicks the OM 2.0 writer: https://github.com/prometheus/client_java/blob/9e9deb6b9e591c2a62b12882d8a987f120661b71/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/ExpositionFormats.java#L63-L86.
Proposed change (pseudo code):
// PrometheusScrapeHandler
String acceptHeader = request.getHeader("Accept");
ExpositionFormatWriter writer = expositionFormats.findWriter(acceptHeader);
EscapingScheme escapingScheme = EscapingScheme.fromAcceptHeader(acceptHeader, defaultFor(acceptHeader));
// Only default to UTF-8 when 2.0.0 was explicitly requested. With
// contentNegotiation=false the OM 2.0 writer also serves OM 1.0 / unversioned
// requests, e.g. from pre-3.0 Prometheus that can't parse UTF-8 names.
EscapingScheme defaultFor(String acceptHeader) {
return "2.0.0".equals(parseOpenMetricsVersion(acceptHeader))
? EscapingScheme.ALLOW_UTF8
: EscapingScheme.DEFAULT;
}
// EscapingScheme
public static EscapingScheme fromAcceptHeader(@Nullable String acceptHeader, EscapingScheme fallback) {
// Same parsing as today. An explicit escaping term always wins, also for OM 2.0
// (e.g. a Prometheus with legacy name validation asking for underscores).
// Return fallback instead of DEFAULT when the term is missing or unknown.
}
Existing fromAcceptHeader(String) can keep delegating with DEFAULT to stay API compatible. Ideally the version and escaping term should come from the same Accept clause that findWriter matched. Today both helpers scan the whole header, so a parameter from another clause can leak in.
Tests to add (e.g. ExpositionFormatsTest, plus a scrape handler test):
version=2.0.0withoutescapingwrites unescaped UTF-8 names.version=2.0.0;escaping=underscoresstill escapes.version=1.0.0, unversioned OpenMetrics andtext/plainwithoutescapingkeep the underscores default, including withcontentNegotiation=false.
The escaping schemes doc should get the same OM 2.0 exception, since its "Default Behavior" section says to use underscores whenever escaping is missing: https://github.com/prometheus/docs/blob/605cf81fefc2e8e91f8ba89bb1555ae52a43a318/docs/instrumenting/escaping_schemes.md#default-behavior.
Matching client_golang issue: https://github.com/prometheus/client_golang/issues/2149
- Ngôn ngữ chính
- Java
- Star
- 2.3k
- Fork
- 832
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 63
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của prometheus/client_java
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prometheus/client_java#2516 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
prometheus/client_java#2416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Switch Micrometer compatibility workflow to upstream once typed-descriptor path becomes defaultCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
prometheus/client_java#2182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
prometheus/client_java#2518 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
prometheus/client_java#2306 · 10 bình luận · 4 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của prometheus/client_java
Issue tương tự
-
Clock.MakeTime fails to validate hour, minute, and second ranges due to inert Calendar.set try-catchĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
mit-cml/appinventor-sources#4139 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[LOOTHUNT] Player Sleep % ToggleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Vakore/ZappierGames#81 ·
-
proposal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
beemdevelopment/Aegis#1843 · 1 reaction ·
-
[Bug] Logo style setting missing and `classic` style not applied across multiple platforms (v3.1.0)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Stirling-Tools/Stirling-PDF#8382 · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
>enhancement needs:triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
elastic/elasticsearch#161191 ·
Maintainer thường phản hồi trong vòng 1 ngày