From ebd4068aac4990864500e3c95253bbf0a9b2de1e Mon Sep 17 00:00:00 2001 From: TwiN Date: Thu, 16 Oct 2025 16:47:11 -0400 Subject: [PATCH] fix(key): Support `(`, `)`, `+` and `&` as name/group (#1340) fix(key): Support (, ), + and & as name/group Relevant: #1339 --- README.md | 16 ++++++++-------- config/key/key.go | 6 +++++- config/key/key_test.go | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ca0c84e0..489a6cf3 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ or send an HTTP request: POST /api/v1/endpoints/{key}/external?success={success}&error={error}&duration={duration} ``` Where: -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. - Using the example configuration above, the key would be `core_ext-ep-test`. - `{success}` is a boolean (`true` or `false`) value indicating whether the health check was successful or not. - `{error}` (optional): a string describing the reason for a failed health check. If {success} is false, this should contain the error message; if the check is successful. @@ -3294,7 +3294,7 @@ The path to generate a badge is the following: ``` Where: - `{duration}` is `30d`, `7d`, `24h` or `1h` -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. For instance, if you want the uptime during the last 24 hours from the endpoint `frontend` in the group `core`, the URL would look like this: @@ -3320,7 +3320,7 @@ The path to generate a badge is the following: /api/v1/endpoints/{key}/health/badge.svg ``` Where: -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. For instance, if you want the current status of the endpoint `frontend` in the group `core`, the URL would look like this: @@ -3337,7 +3337,7 @@ The path to generate a badge is the following: /api/v1/endpoints/{key}/health/badge.shields ``` Where: -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. For instance, if you want the current status of the endpoint `frontend` in the group `core`, the URL would look like this: @@ -3360,7 +3360,7 @@ The endpoint to generate a badge is the following: ``` Where: - `{duration}` is `30d`, `7d`, `24h` or `1h` -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. #### Response time (chart) ![Response time 24h](https://status.twin.sh/api/v1/endpoints/core_blog-external/response-times/24h/chart.svg) @@ -3373,7 +3373,7 @@ The endpoint to generate a response time chart is the following: ``` Where: - `{duration}` is `30d`, `7d`, or `24h` -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. ##### How to change the color thresholds of the response time badge To change the response time badges' threshold, a corresponding configuration can be added to an endpoint. @@ -3431,7 +3431,7 @@ The path to get raw uptime data for an endpoint is: ``` Where: - `{duration}` is `30d`, `7d`, `24h` or `1h` -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. For instance, if you want the raw uptime data for the last 24 hours from the endpoint `frontend` in the group `core`, the URL would look like this: ``` @@ -3445,7 +3445,7 @@ The path to get raw response time data for an endpoint is: ``` Where: - `{duration}` is `30d`, `7d`, `24h` or `1h` -- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.` and `#` replaced by `-`. +- `{key}` has the pattern `_` in which both variables have ` `, `/`, `_`, `,`, `.`, `#`, `(`, `)`, `+` and `&` replaced by `-`. For instance, if you want the raw response time data for the last 24 hours from the endpoint `frontend` in the group `core`, the URL would look like this: ``` diff --git a/config/key/key.go b/config/key/key.go index d0b931dc..f06aa1fb 100644 --- a/config/key/key.go +++ b/config/key/key.go @@ -15,5 +15,9 @@ func sanitize(s string) string { s = strings.ReplaceAll(s, ",", "-") s = strings.ReplaceAll(s, " ", "-") s = strings.ReplaceAll(s, "#", "-") + s = strings.ReplaceAll(s, "(", "-") + s = strings.ReplaceAll(s, ")", "-") + s = strings.ReplaceAll(s, "+", "-") + s = strings.ReplaceAll(s, "&", "-") return s -} \ No newline at end of file +} diff --git a/config/key/key_test.go b/config/key/key_test.go index 34179cfc..3c082c3f 100644 --- a/config/key/key_test.go +++ b/config/key/key_test.go @@ -29,6 +29,21 @@ func TestConvertGroupAndNameToKey(t *testing.T) { Name: "name", ExpectedOutput: "_name", }, + { + GroupName: "API (v1)", + Name: "endpoint", + ExpectedOutput: "api--v1-_endpoint", + }, + { + GroupName: "website (admin)", + Name: "test", + ExpectedOutput: "website--admin-_test", + }, + { + GroupName: "search", + Name: "query&filter", + ExpectedOutput: "search_query-filter", + }, } for _, scenario := range scenarios { t.Run(scenario.ExpectedOutput, func(t *testing.T) {