Add parameter for specifying prometheus path (#1602)
Some checks are pending
Clang / format (push) Waiting to run
Clang / sanitize (address,pointer-compare,pointer-subtract) (push) Waiting to run
Clang / sanitize (thread) (push) Waiting to run
Clang / tidy (Release) (push) Waiting to run
CMake / build (push) Waiting to run
CodeQL / analyze (push) Waiting to run
Docker / build (amd64, alpine) (push) Waiting to run
Docker / build (amd64, debian) (push) Waiting to run
Docker / build (arm32v6, alpine) (push) Waiting to run
Docker / build (arm32v6, debian) (push) Waiting to run
Docker / build (arm32v7, alpine) (push) Waiting to run
Docker / build (arm32v7, debian) (push) Waiting to run
Docker / build (arm64v8, alpine) (push) Waiting to run
Docker / build (arm64v8, debian) (push) Waiting to run
Docker / build (i386, alpine) (push) Waiting to run
Docker / build (i386, debian) (push) Waiting to run
Docker / build (ppc64le, alpine) (push) Waiting to run
Docker / build (ppc64le, debian) (push) Waiting to run
Docker / build (s390x, alpine) (push) Waiting to run
Docker / build (s390x, debian) (push) Waiting to run
Docker / test (amd64, alpine) (push) Blocked by required conditions
Docker / test (amd64, debian) (push) Blocked by required conditions
Docker / test (arm32v7, debian) (push) Blocked by required conditions
Docker / test (arm64v8, alpine) (push) Blocked by required conditions
Docker / test (arm64v8, debian) (push) Blocked by required conditions
Docker / test (i386, alpine) (push) Blocked by required conditions
Docker / test (i386, debian) (push) Blocked by required conditions
Docker / push (debian, quay.io) (push) Blocked by required conditions
Docker / test (arm32v6, alpine) (push) Blocked by required conditions
Docker / test (arm32v6, debian) (push) Blocked by required conditions
Docker / test (arm32v7, alpine) (push) Blocked by required conditions
Docker / test (ppc64le, alpine) (push) Blocked by required conditions
Docker / test (ppc64le, debian) (push) Blocked by required conditions
Docker / test (s390x, debian) (push) Blocked by required conditions
Docker / push (alpine, docker.io) (push) Blocked by required conditions
Docker / push (alpine, ghcr.io) (push) Blocked by required conditions
Docker / push (alpine, quay.io) (push) Blocked by required conditions
Docker / push (debian, docker.io) (push) Blocked by required conditions
Docker / push (debian, ghcr.io) (push) Blocked by required conditions
Docker / release (GitHub) (push) Blocked by required conditions
Linux / build + test (amazonlinux:2023) (push) Waiting to run
Linux / build + test (ubuntu:20.04) (push) Waiting to run
Linux / build + test (ubuntu:22.04) (push) Waiting to run
Linux / build + test (ubuntu:24.04) (push) Waiting to run
macOS / build + test (13) (push) Waiting to run
macOS / build + test (14) (push) Waiting to run
macOS / build + test (15) (push) Waiting to run
MinGW / build (OFF, Debug, windows) (push) Waiting to run
MinGW / build (OFF, Release, windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (OFF, Debug, x64, v143, windows, x64-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (ON, Debug, x64, v143, windows, x64-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (ON, Release, Win32, v142, windows, x86-windows) (push) Waiting to run
MSVC / code analysis (windows-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (OFF, Release, x64, v143) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (OFF, Debug, Win32, v142, windows, x86-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (OFF, Release, Win32, v142, windows, x86-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (OFF, Release, x64, v143, windows, x64-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (ON, Debug, Win32, v142, windows, x86-windows) (push) Waiting to run
MSVC / compile (${{ matrix.os }}-vc-${{ matrix.VCPKG_PLATFORM_TOOLSET }}-${{ matrix.CMAKE_GENERATOR_PLATFORM }}-${{ matrix.BUILD_TYPE }}-${{ matrix.BUILD_SHARED_LIBS }}) (ON, Release, x64, v143, windows, x64-windows) (push) Waiting to run

Add a `--prometheus-path` parameter which allows users to specify at
what
path the metrics should be exposed.

This simplifies serving metrics on a specific path behind some
restrictive reverse proxies that expect the upstream server to serve
URLs with paths matching the requested path.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
This commit is contained in:
Alex Gustafsson 2024-12-18 23:50:38 +01:00 committed by GitHub
parent 3370eaf12d
commit 790cc6f79e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 1 deletions

View File

@ -64,3 +64,10 @@ turnserver_pid="$!"
sleep 2
assert_prom_response "http://127.0.0.1:8080/metrics"
kill "$turnserver_pid"
echo "Running turnserver with prometheus, using custom path"
$BINDIR/turnserver --prometheus --prometheus-path="/coturn/metrics" > /dev/null &
turnserver_pid="$!"
sleep 2
assert_prom_response "http://localhost:9641/coturn/metrics"
kill "$turnserver_pid"

View File

@ -209,6 +209,7 @@ turn_params_t turn_params = {
0, /* prometheus disabled by default */
DEFAULT_PROM_SERVER_PORT, /* prometheus port */
"", /* prometheus address */
"/metrics", /* prometheus path */
0, /* prometheus username labelling disabled by default when prometheus is enabled */
///////////// Users DB //////////////
@ -1137,6 +1138,7 @@ static char Usage[] =
" also the path / on this port can be used as a health check\n"
" --prometheus-port <port> Prometheus metrics port (Default: 9641).\n"
" --prometheus-address <address> Prometheus listening address (Default: any).\n"
" --prometheus-path <path> Prometheus serve path (Default: /metrics).\n"
" --prometheus-username-labels When metrics are enabled, add labels with client usernames.\n"
#endif
" --use-auth-secret TURN REST API flag.\n"
@ -1436,6 +1438,7 @@ enum EXTRA_OPTS {
PROMETHEUS_OPT,
PROMETHEUS_PORT_OPT,
PROMETHEUS_ADDRESS_OPT,
PROMETHEUS_PATH_OPT,
PROMETHEUS_ENABLE_USERNAMES_OPT,
AUTH_SECRET_OPT,
NO_AUTH_PINGS_OPT,
@ -1555,6 +1558,7 @@ static const struct myoption long_options[] = {
{"prometheus", optional_argument, NULL, PROMETHEUS_OPT},
{"prometheus-port", optional_argument, NULL, PROMETHEUS_PORT_OPT},
{"prometheus-address", optional_argument, NULL, PROMETHEUS_ADDRESS_OPT},
{"prometheus-path", optional_argument, NULL, PROMETHEUS_PATH_OPT},
{"prometheus-username-labels", optional_argument, NULL, PROMETHEUS_ENABLE_USERNAMES_OPT},
#endif
{"use-auth-secret", optional_argument, NULL, AUTH_SECRET_OPT},
@ -2207,6 +2211,9 @@ static void set_option(int c, char *value) {
case PROMETHEUS_ADDRESS_OPT:
STRCPY(turn_params.prometheus_address, value);
break;
case PROMETHEUS_PATH_OPT:
STRCPY(turn_params.prometheus_path, value);
break;
case PROMETHEUS_ENABLE_USERNAMES_OPT:
turn_params.prometheus_username_labels = 1;
break;

View File

@ -311,6 +311,7 @@ typedef struct _turn_params_ {
int prometheus;
int prometheus_port;
char prometheus_address[INET6_ADDRSTRLEN];
char prometheus_path[1025];
int prometheus_username_labels;
/////// Users DB ///////////

View File

@ -52,7 +52,7 @@ MHD_RESULT promhttp_handler(void *cls, struct MHD_Connection *connection, const
if (strcmp(method, "GET") != 0) {
status = MHD_HTTP_METHOD_NOT_ALLOWED;
body = "method not allowed";
} else if (strcmp(url, "/metrics") == 0) {
} else if (strcmp(url, turn_params.prometheus_path) == 0) {
body = prom_collector_registry_bridge(PROM_COLLECTOR_REGISTRY_DEFAULT);
mode = MHD_RESPMEM_MUST_FREE;
status = MHD_HTTP_OK;