Skip to content

Commit

Permalink
Add job indexing to Omnistat container
Browse files Browse the repository at this point in the history
Signed-off-by: Jordà Polo <jorda.polo@amd.com>
  • Loading branch information
jordap committed Feb 4, 2025
1 parent dc0e2ad commit 6e2b4a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM victoriametrics/victoria-metrics

RUN apk update && apk add curl su-exec
RUN apk --update --no-cache add curl su-exec python3 py3-pip py3-aiohttp

COPY load.sh /usr/local/bin/omnistat-load
COPY index.py /usr/local/bin/omnistat-index
COPY entrypoint.sh /usr/local/bin/entrypoint

RUN chmod 0777 /usr/local/bin/omnistat-load
RUN chmod 0777 /usr/local/bin/omnistat-index

ENTRYPOINT ["/usr/local/bin/entrypoint"]
3 changes: 3 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ services:
- VICTORIA_TIMEOUT=30
- VICTORIA_LOCK_TIMEOUT=30
- VICTORIA_RETENTION_PERIOD=5y
- INDEX_DAYS=365
- INDEX_LIMIT=16
- INDEX_QUERY_TIMEOUT=1
volumes:
- ${DATADIR:-${MULTIDIR:-./data}}:/data

Expand Down
2 changes: 1 addition & 1 deletion docker/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def scan_database(address, days, step, limit, timeout):
print(f" Number of jobs in the database: {len(job_data)}")

print("Starting job index", flush=True)
server_address = ("", 8181)
server_address = ("", 9091)
handler = JobIndexHandler(job_data)
httpd = http.server.HTTPServer(server_address, handler)
httpd.serve_forever()
38 changes: 28 additions & 10 deletions docker/load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ if [ -n "$MULTIDIR" ]; then
fi

# Adress of the main Victoria Metrics server.
TARGET_URL=localhost:9090
TARGET_PORT=$(echo $TARGET_URL | awk -F':' '{print $2}')
TARGET_ADDRESS=localhost:9090
TARGET_PORT=$(echo $TARGET_ADDRESS | awk -F':' '{print $2}')

# Adress to export Victoria Metrics data from source databases when using
# MULTIDIR.
SOURCE_URL=localhost:8428
SOURCE_ADDRESS=localhost:8428

# Path to the temporary file used for exporting/importing databases.
DATA_FILE=/tmp/data.bin
Expand All @@ -52,6 +52,9 @@ VICTORIA_ARGS="-retentionPeriod=$VICTORIA_RETENTION_PERIOD -loggerLevel=ERROR"
VICTORIA_URL=http://omnistat:9090/-/healthy
VICTORIA_INTERVAL=1
VICTORIA_TIMEOUT=${VICTORIA_TIMEOUT:-30}
INDEX_URL=http://omnistat:9091/
INDEX_INTERVAL=1
INDEX_TIMEOUT=${INDEX_TIMEOUT:-30}
GRAFANA_URL=http://grafana:3000/
GRAFANA_INTERVAL=1
GRAFANA_TIMEOUT=30
Expand Down Expand Up @@ -81,7 +84,7 @@ wait_for_url() {
return 1
fi

curl -s --fail --head $url > /dev/null
curl -s --fail $url > /dev/null
if [ $? -eq 0 ]; then
return 0
fi
Expand Down Expand Up @@ -158,7 +161,7 @@ merge_databases() {
local num_databases
local db_name

start_victoria $TARGET_URL $TARGET_DIR
start_victoria $TARGET_ADDRESS $TARGET_DIR
target_pid=$?
if [ $target_pid -eq 0 ]; then
echo "Error: failed to start target Victoria Metrics server"
Expand All @@ -184,15 +187,15 @@ merge_databases() {
fi

echo "Loading $db_name"
start_victoria $SOURCE_URL $i
start_victoria $SOURCE_ADDRESS $i
source_pid=$!
if [ $source_pid -eq 0 ]; then
echo ".. Warning: Failed to load $i"
continue
fi

echo ".. Exporting data from $db_name"
curl -s --fail $SOURCE_URL/api/v1/export/native -d 'match[]={__name__!~"vm_.*"}' > $DATA_FILE
curl -s --fail $SOURCE_ADDRESS/api/v1/export/native -d 'match[]={__name__!~"vm_.*"}' > $DATA_FILE
if [ $? -ne 0 ]; then
echo ".. Warning: Failed to export $db_name"
continue
Expand All @@ -202,7 +205,7 @@ merge_databases() {
kill -SIGINT $source_pid

echo ".. Merging data from $db_name to $HOST_DIR"
curl -s --fail -X POST $TARGET_URL/api/v1/import/native -T $DATA_FILE
curl -s --fail -X POST $TARGET_ADDRESS/api/v1/import/native -T $DATA_FILE
if [ $? -ne 0 ]; then
echo ".. Warning: Failed to import $i"
continue
Expand Down Expand Up @@ -241,14 +244,28 @@ echo "Starting Victoria Metrics using $HOST_DIR"
$VICTORIA_BIN $VICTORIA_ARGS \
-httpListenAddr=:$TARGET_PORT \
-storageDataPath=$TARGET_DIR &
pid=$!
victoria_pid=$!

wait_for_url $VICTORIA_URL $VICTORIA_INTERVAL $VICTORIA_TIMEOUT
if [ $? -ne 0 ]; then
echo "Error: Victoria Metrics not responding"
exit 1
fi

omnistat-index \
--address ${TARGET_ADDRESS} \
--days ${INDEX_DAYS:-365} \
--step ${INDEX_STEP:-5} \
--limit ${INDEX_LIMIT:-16} \
--timeout ${INDEX_QUERY_TIMEOUT:-1} &
index_pid=$!

wait_for_url $INDEX_URL $INDEX_INTERVAL $INDEX_TIMEOUT
if [ $? -ne 0 ]; then
echo "Error: Job index not responding"
exit 1
fi

wait_for_url $GRAFANA_URL $GRAFANA_INTERVAL $GRAFANA_TIMEOUT
if [ $? -ne 0 ]; then
echo "Error: Grafana not responding"
Expand All @@ -257,4 +274,5 @@ fi

echo "Omnistat dashboard ready: http://localhost:3000"

wait $pid
wait $victoria_pid $index_pid
exit 0

0 comments on commit 6e2b4a8

Please sign in to comment.