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

Report the running version as a metric #163

Closed
wants to merge 15 commits into from
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
path: ./test-integration.log
if-no-files-found: error
end_to_end:
name: E2E tests (maxconns=${{ matrix.max_db_conns }})
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -151,14 +152,15 @@ jobs:
SYNCV3_DB: user=postgres dbname=syncv3 sslmode=disable password=postgres host=localhost
SYNCV3_SERVER: http://localhost:8008
SYNCV3_SECRET: itsasecret
SYNCV3_PROM: :2112
SYNCV3_MAX_DB_CONN: ${{ matrix.max_db_conns }}
E2E_TEST_SERVER_STDOUT: test-e2e-server.log

- name: Upload test log
uses: actions/upload-artifact@v3
if: always()
with:
name: E2E test logs
name: E2E test logs (maxconns=${{ matrix.max_db_conns }})
path: |
./tests-e2e/test-e2e-runner.log
./tests-e2e/test-e2e-server.log
Expand Down
11 changes: 11 additions & 0 deletions cmd/syncv3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
syncv3 "github.com/matrix-org/sliding-sync"
"github.com/matrix-org/sliding-sync/internal"
"github.com/matrix-org/sliding-sync/sync2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
Expand Down Expand Up @@ -117,6 +118,16 @@ func main() {
panic(err)
}
}()
// Cribbed from synapse
// https://github.com/matrix-org/synapse/blob/d93912042191d30ff1f7aa41d9f0779a609caca8/synapse/metrics/__init__.py#L413-L421
// and https://www.robustperception.io/exposing-the-software-version-to-prometheus/
versionGauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "sliding_sync",
Name: "build_info",
ConstLabels: map[string]string{"commit": GitCommit, "version": version},
})
versionGauge.Set(1) // Dummy value; the label is the data here
prometheus.MustRegister(versionGauge)
}
if args[EnvJaeger] != "" {
fmt.Printf("Configuring Jaeger collector...\n")
Expand Down
17 changes: 17 additions & 0 deletions tests-e2e/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ export SYNCV3_DEBUG=1
SYNCV3_PID=$!
trap "kill $SYNCV3_PID" EXIT

waits=0
# wait for the server to be listening, we want this endpoint to 404 instead of connrefused
until [ \
"$(curl -s -w '%{http_code}' -o /dev/null "http://localhost:8844/idonotexist")" \
-eq 404 ]
do
echo 'Waiting for server to start...'
waits=$((waits+1))
if [ "$waits" -ge 60 ]; then
echo "Server did not start within a minute" > /dev/stderr
exit 1
fi
sleep 1
done

# if the metrics env var is set, sanity check that metrics are being served
if [ -n "${SYNCV3_PROM+1}" ]; then
status="$(curl --silent --write-out '%{http_code}' -o /dev/null http://localhost:2112/metrics)"
if [ "$status" != 200 ]; then
echo "Metrics endpoint returned $status, expected 200" > /dev/stderr
exit 1
else
echo "Metrics endpoint returned 200 OK."
fi
fi

go test "$@"
Loading