Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1340 better metric support #1343

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

env:
BUILD_TYPE: Release
LIBPROM_VERS: '1.2.0-1'
LIBPROM_URL: 'https://pkg.cs.ovgu.de/LNF/linux/ubuntu/20.04'

jobs:
build:
Expand All @@ -28,10 +30,10 @@ jobs:
- uses: actions/checkout@v4
- name: Prometheus support
run: |
wget https://github.com/digitalocean/prometheus-client-c/releases/download/v0.1.3/libprom-dev-0.1.3-Linux.deb && \
wget https://github.com/digitalocean/prometheus-client-c/releases/download/v0.1.3/libpromhttp-dev-0.1.3-Linux.deb && \
sudo apt install ./libprom-dev-0.1.3-Linux.deb ./libpromhttp-dev-0.1.3-Linux.deb && \
rm ./libprom-dev-0.1.3-Linux.deb ./libpromhttp-dev-0.1.3-Linux.deb
wget ${LIBPROM_URL}/libprom-dev-${LIBPROM_VERS}.deb && \
wget ${LIBPROM_URL}/libprom-${LIBPROM_VERS}.deb && \
sudo apt install ./libprom-${LIBPROM_VERS}.deb ./libprom-dev-${LIBPROM_VERS}.deb && \
rm -f ./libprom-*.deb
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- arm64v8
- i386
- ppc64le
- s390x
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -94,7 +93,6 @@ jobs:
- arm64v8
- i386
- ppc64le
- s390x
runs-on: ${{ (matrix.dist == 'alpine' && matrix.arch == 's390x' && 'macos')
|| 'ubuntu' }}-latest
steps:
Expand Down Expand Up @@ -203,8 +201,7 @@ jobs:
arm32v7 \
arm64v8 \
i386 \
ppc64le \
s390x
ppc64le
do
make docker.untar \
from-file=.cache/${{ matrix.dist }}-$arch-${{ github.run_number }}/image.tar
Expand All @@ -225,8 +222,7 @@ jobs:
${{ steps.docker.outputs.tag }}-arm32v7
${{ steps.docker.outputs.tag }}-arm64v8
${{ steps.docker.outputs.tag }}-i386
${{ steps.docker.outputs.tag }}-ppc64le
${{ steps.docker.outputs.tag }}-s390x'
${{ steps.docker.outputs.tag }}-ppc64le'
tags=${{ (!startsWith(github.ref, 'refs/tags/')
&& steps.docker.outputs.tag)
|| '' }}
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: mingw

on: [push]

env:
LIBPROM_REPO: 'https://github.com/jelmd/libprom'
# GHA does not support ksh/bash parameter expansion like ${LIBPROM_REPO##*/}
LIBPROM_DIR: 'libprom'

jobs:
build:
name: build
Expand Down Expand Up @@ -69,8 +74,8 @@ jobs:
PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin
run: |
cd ${{env.SOURCE_DIR}}
git clone https://github.com/digitalocean/prometheus-client-c.git
cd prometheus-client-c/prom
git clone ${LIBPROM_REPO}
cd ${LIBPROM_DIR}/prom
mkdir build
cd build
cmake .. -G"MinGW Makefiles" ^
Expand All @@ -79,7 +84,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=${{env.INSTALL_DIR}}
cmake --build . --config ${{matrix.BUILD_TYPE}}
cmake --build . --config ${{matrix.BUILD_TYPE}} --target install
cd ${{env.SOURCE_DIR}}/prometheus-client-c/promhttp
cd ${{env.SOURCE_DIR}}/${LIBPROM_DIR}/promhttp
mkdir build
cd build
cmake .. -G"MinGW Makefiles" ^
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ on:
pull_request:
types: [ opened, reopened, synchronize ]

env:
LIBPROM_VERS: '1.2.0-1'
LIBPROM_URL: 'https://pkg.cs.ovgu.de/LNF/linux/ubuntu/20.04'

jobs:
builds:
strategy:
fail-fast: false
matrix:
os: [ 'ubuntu:16.04', 'ubuntu:20.04', 'ubuntu:22.04' ]
os: [ 'ubuntu:20.04', 'ubuntu:22.04' ]
runs-on: ubuntu-latest
container: ${{ matrix.os }}
steps:
Expand All @@ -30,13 +34,12 @@ jobs:
libpq-dev libsqlite3-dev \
libhiredis-dev \
libmongoc-dev \
libmicrohttpd-dev
if [ ${{ matrix.os }} = 'ubuntu:16.04' ]; then apt-get install -y libmariadb-client-lgpl-dev; fi
if [ ${{ matrix.os }} != 'ubuntu:16.04' ]; then apt-get install -y libmariadb-dev; fi
wget https://github.com/digitalocean/prometheus-client-c/releases/download/v0.1.3/libprom-dev-0.1.3-Linux.deb && \
wget https://github.com/digitalocean/prometheus-client-c/releases/download/v0.1.3/libpromhttp-dev-0.1.3-Linux.deb && \
apt install ./libprom-dev-0.1.3-Linux.deb ./libpromhttp-dev-0.1.3-Linux.deb && \
rm ./libprom-dev-0.1.3-Linux.deb ./libpromhttp-dev-0.1.3-Linux.deb
libmicrohttpd-dev \
libmariadb-dev
wget ${LIBPROM_URL}/libprom-dev-${LIBPROM_VERS}.deb && \
wget ${LIBPROM_URL}/libprom-${LIBPROM_VERS}.deb && \
apt install ./libprom-${LIBPROM_VERS}.deb ./libprom-dev-${LIBPROM_VERS}.deb && \
rm -f ./libprom-*.deb
- uses: actions/checkout@v3
- name: configure
run: ./configure
Expand Down
6 changes: 4 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ check: bin/turnutils_rfc5769check
bin/turnutils_rfc5769check

format:
find . -iname "*.c" -o -iname "*.h" | xargs clang-format -i
find src -iname "*.c" -o -iname "*.h" | \
xargs clang-format -i

lint:
find . -iname "*.c" -o -iname "*.h" | xargs clang-format --dry-run -Werror
find src -iname "*.c" -o -iname "*.h" | \
xargs clang-format --dry-run -Werror

include/turn/ns_turn_defs.h: src/ns_turn_defs.h
${RMCMD} include
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ coturn requires following dependencies to be installed first

Optional
- openssl (to support TLS and DTLS, authorized STUN and TURN)
- libmicrohttp and [prometheus-client-c](https://github.com/digitalocean/prometheus-client-c) (prometheus interface)
- libmicrohttp and [libprom](https://github.com/jelmd/libprom) (libprom interface)
- MySQL (user database)
- [Hiredis](https://github.com/redis/hiredis) (user database, monitoring)
- SQLite (user database)
Expand Down Expand Up @@ -111,7 +111,7 @@ Management interfaces:

Monitoring:
* Redis can be used for status and statistics storage and notification
* [prometheus](https://prometheus.io/) interface (unavailable on apt package)
* [libprom](https://jelmd.github.io/libprom/) interface (unavailable on apt package)

Message integrity digest algorithms:

Expand Down
51 changes: 39 additions & 12 deletions README.turnserver
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ User database settings:

Flags:

-h Help.

-v, --verbose Moderate verbose mode.

-V, --Verbose Extra verbose mode, very annoying and not recommended.
Expand Down Expand Up @@ -285,21 +287,46 @@ Flags:
main ORIGIN attribute value (if the ORIGIN was
initially used by the session).

--prometheus Enable prometheus metrics. By default it is
disabled. Would listen on port 9641 under the path /metrics
also the path / on this port can be used as a health check.
Unavailable on apt installations.

--prometheus-username-labels Enable labeling prometheus traffic
metrics with client usernames. Labeling with client usernames is
disabled by default, because this may cause memory leaks when using
authentication with ephemeral usernames (e.g. TURN REST API).

--prometheus-port Prometheus listener port (Default: 9641).
Prometheus/OpenMetrics options:

--prom Enable metric collections to monitor this application and make them
available via HTTP in reports using the Prometheus/OpenMetrics
exposition format via http://host:port/metrics . All options
starting with "--prom-" are only effective if this one is enabled.
For more information and details you should read `docs/Metrics.md`.

--prom-port=<port> Listen on the given port for /metric requests. Default: 9641

--prom-compact Omit the HELP and TYPE comments when generating the metric
reports. Recommended for all production systems.

--prom-realm Label the session state metric with the session realm. Usually just overhead.

--prom-usernames Label the session state metric with client usernames. One
should not use, unless really needed!

--prom-uniq-sid Label session related metrics with the unique ID of the session.
One should not use, unless really needed!

--prom-sid Reuse session IDs of already closed sessions to reduce the number
of generate metrics. However, still a vulnerable point for DoS attacks
so should not be used or in an environment, where one has pretty good
control over the clients accessing this service.
NOTE: --prom-sid supersedes the --prom-sid option.

--prom-sid-retain=<num> Set the time in seconds a session must have been closed
before its ID can be re-used by a new session.

--log-ip Log the IP address of each session endpoint, when a session gets created.
Right now IP addresses are logged in verbose mode at the session end, only.
This is not sufficient or too late if one needs to correlate metrics. So
this option allows one to turn it on on demand. Default: 0

For production the recommended options are --prom and --prom-compact.

-h Help.

Options with values:
Other Options with values:

--stale-nonce[=<value>] Use extra security with nonce value having
limited lifetime, in seconds (default 600 secs).
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindPrometheus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ find_library(
PATH_SUFFIXES lib ${CMAKE_INSTALL_LIBDIR})

find_path(prom_INCLUDE_DIR
NAMES prom.h
NAMES prom.h libprom/prom.h
HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_prom_INCLUDE_DIRS} /usr
PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT}
PATH_SUFFIXES include
Expand All @@ -48,7 +48,7 @@ find_library(
PATH_SUFFIXES lib ${CMAKE_INSTALL_LIBDIR})

find_path(promhttp_INCLUDE_DIR
NAMES promhttp.h
NAMES promhttp.h libprom/promhttp.h
HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_promhttp_INCLUDE_DIRS} /usr
PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT}
PATH_SUFFIXES include
Expand Down
16 changes: 15 additions & 1 deletion configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

DEBUG=

# Proprietary configure script of Coturn project

cleanup() {
Expand All @@ -19,6 +21,12 @@ testlibraw() {
ER=$?
if ! [ ${ER} -eq 0 ] ; then
${ECHO_CMD} "Library option -${1} cannot be used"
if [ -n ${DEBUG} ]; then
${ECHO_CMD} "Command: ${CC} ${TMPCPROGC} -o ${TMPCPROGB} ${OSCFLAGS} ${OSLIBS} -${1}"
${ECHO_CMD} "${TMPCPROGC}:\n---start---"
cat ${TMPCPROGC}
${ECHO_CMD} "---end---"
fi
return 0
else
OSLIBS="${OSLIBS} -${1}"
Expand Down Expand Up @@ -843,6 +851,7 @@ fi

if [ -z "${TURN_NO_PROMETHEUS}" ] ; then

DEBUG="1"
testlib prom
ER=$?
if ! [ ${ER} -eq 0 ] ; then
Expand Down Expand Up @@ -878,13 +887,18 @@ if [ -z "${TURN_NO_PROMETHEUS}" ] ; then
fi
else
${ECHO_CMD}
if [ -n ${DEBUG} ]; then
ls -al /usr/lib/*/libprom*
ls -al /usr/lib/libprom*
${ECHO_CMD}
fi
${ECHO_CMD} "Warning: Libprom development libraries are not installed properly in required location."
${ECHO_CMD} "Prometheus support will be disabled."
${ECHO_CMD} "See the docs/Prometheus.md file."
${ECHO_CMD}
OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS"
fi

DEBUG=
else
OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS"
fi
Expand Down
57 changes: 15 additions & 42 deletions docker/coturn/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ ARG alpine_ver=3.18.5


#
# Stage 'dist-libprom' creates prometheus-client-c distribution.
# Stage 'dist-libprom' creates libprom distribution.
#

# We compile prometheus-client-c from sources, because Alpine doesn't provide
# We compile libprom from sources, because Alpine doesn't provide
# it as its package yet.
#
# TODO: Re-check this to be present in packages on next Alpine major version update.
Expand All @@ -25,54 +25,27 @@ RUN apk update \
ca-certificates cmake g++ git make \
&& update-ca-certificates

# Install prometheus-client-c build dependencies.
# Install libprom build dependencies.
RUN apk add --no-cache \
libmicrohttpd-dev

# Prepare prometheus-client-c sources for building.
ARG prom_ver=0.1.3
# Prepare libprom sources for building.
ARG prom_ver=1.2.0
RUN mkdir -p /build/ && cd /build/ \
&& git init \
&& git remote add origin https://github.com/digitalocean/prometheus-client-c \
&& git remote add origin https://github.com/jelmd/libprom \
&& git fetch --depth=1 origin "v${prom_ver}" \
&& git checkout FETCH_HEAD

# Build libprom.so from sources.
RUN mkdir -p /build/prom/build/ && cd /build/prom/build/ \
&& TEST=0 cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_SKIP_BUILD_RPATH=TRUE \
-DCMAKE_C_FLAGS="-DPROM_LOG_ENABLE -g -O3" \
.. \
&& make
# Build libprom.so and libpromhttp.so from sources.
RUN cd /build && make VERBOSE=1

# Build libpromhttp.so from sources.
RUN mkdir -p /build/promhttp/build/ && cd /build/promhttp/build/ \
# Fix compiler warning: -Werror=incompatible-pointer-types
&& sed -i 's/\&promhttp_handler/(MHD_AccessHandlerCallback)\&promhttp_handler/' \
/build/promhttp/src/promhttp.c \
&& TEST=0 cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_SKIP_BUILD_RPATH=TRUE \
-DCMAKE_C_FLAGS="-g -O3" \
.. \
&& make VERBOSE=1

# Install prometheus-client-c.
RUN LIBS_DIR=/out/$(dirname $(find /usr/ -name libc.so)) \
&& mkdir -p $LIBS_DIR/ \
&& cp -rf /build/prom/build/libprom.so \
/build/promhttp/build/libpromhttp.so \
$LIBS_DIR/ \
&& mkdir -p /out/usr/include/ \
&& cp -rf /build/prom/include/* \
/build/promhttp/include/* \
/out/usr/include/ \
# Install libprom.
RUN cd /build/prom/build && DESTDIR=/out make install \
&& cd /build/promhttp/build && DESTDIR=/out make install \
# Preserve license file.
&& mkdir -p /out/usr/share/licenses/prometheus-client-c/ \
&& cp /build/LICENSE /out/usr/share/licenses/prometheus-client-c/


&& mkdir -p /out/usr/share/licenses/libprom/ \
&& cp /build/LICENSE /out/usr/share/licenses/libprom/


#
Expand All @@ -98,7 +71,7 @@ RUN apk add --no-cache \
mongo-c-driver-dev \
libmicrohttpd-dev

# Install prometheus-client-c distribution.
# Install libprom distribution.
COPY --from=dist-libprom /out/ /

# Prepare local Coturn sources for building.
Expand Down Expand Up @@ -160,7 +133,7 @@ RUN ln -s /usr/local/bin/detect-external-ip.sh \
/out/usr/local/bin/detect-external-ip
RUN chown -R nobody:nogroup /out/var/lib/coturn/

# Re-export prometheus-client-c distribution.
# Re-export libprom distribution.
COPY --from=dist-libprom /out/ /out/


Expand Down