louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
59.46k stars 5.32k forks source link

Error: Invalid label name when using non-ASCII characters in tags #5096

Closed candies404 closed 1 month ago

candies404 commented 2 months ago

πŸ“‘ I have found these related issues/pull requests

No correlation has been found

πŸ›‘οΈ Security Policy

Description

When using non-ASCII characters (such as Chinese) in tag names, the system throws an "Invalid label name" error during Prometheus metrics initialization.

image

πŸ‘Ÿ Reproduction steps

  1. Create a tag with a non-ASCII name (e.g., Chinese characters) in Uptime Kuma
  2. Restart the Uptime Kuma service or trigger Prometheus metrics initialization

πŸ‘€ Expected behavior

The system should handle non-ASCII tag names gracefully, either by converting them to valid Prometheus label names or by using a separate field for Prometheus-compatible names.

πŸ˜“ Actual Behavior

The system crashes with an "Invalid label name" error when initializing Prometheus metrics.

🐻 Uptime-Kuma Version

2.0.0-dev

πŸ’» Operating System and Arch

Ubuntu Linux

🌐 Browser

127.0.6533.120

πŸ–₯️ Deployment Environment

πŸ“ Relevant log output

Error message:
Trace: Error: Invalid label name
    at new Metric (/app/node_modules/prom-client/lib/metric.js:39:10)
    at new Gauge (/app/node_modules/prom-client/lib/gauge.js:19:1)
    at Prometheus.initMetrics (/app/server/prometheus.js:61:45)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Prometheus.createAndInitMetrics (/app/server/prometheus.js:96:9)
    at async Proxy.start (/app/server/model/monitor.js:349:27)
    at async startMonitors (/app/server/server.js:1805:9)
    at process.unexpectedErrorHandler (/app/server/server.js:1859:13)
    at process.emit (node:events:519:28)
    at emitUnhandledRejection (node:internal/process/promises:250:13)
    at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)
    at processPromiseRejections (node:internal/process/promises:470:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)
louislam commented 2 months ago

Thanks for finding the root cause. I was experiencing this issue last week too. It should be related to this pull request:

https://github.com/louislam/uptime-kuma/pull/4704#discussion_r1738343271

louislam commented 1 month ago

Actually I think it is not related to non-ASCII, it the pr causes all monitors are not working, I am going to revert the pr now.