Skip to content

Commit 738c149

Browse files
authored
feat: add kubernetes support (#284)
2 parents 2debcb2 + 1c6a929 commit 738c149

29 files changed

Lines changed: 2949 additions & 730 deletions

.github/workflows/integration-test-k8s.yml

Lines changed: 450 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/integration-test.yml

Lines changed: 115 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
POSTGRES_USER: root
9090
POSTGRES_PASSWORD: rootpassword
9191
POSTGRES_DB: nextcloud
92-
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5
92+
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 --name postgres --hostname postgres
9393

9494
steps:
9595
- name: Checkout server
@@ -120,6 +120,14 @@ jobs:
120120
path: context_chat_backend/
121121
persist-credentials: false
122122

123+
- name: Checkout app_api
124+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
125+
with:
126+
repository: nextcloud/app_api
127+
ref: ${{ matrix.server-versions == 'master' && 'main' || matrix.server-versions }}
128+
path: apps/app_api
129+
persist-credentials: false
130+
123131
- name: Get app version
124132
id: appinfo
125133
uses: skjnldsv/xpath-action@7e6a7c379d0e9abc8acaef43df403ab4fc4f770c # master
@@ -167,6 +175,10 @@ jobs:
167175
cd ..
168176
rm -rf documentation
169177
178+
- name: Run files scan
179+
run: |
180+
./occ files:scan --all
181+
170182
- name: Setup python 3.11
171183
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
172184
with:
@@ -195,42 +207,109 @@ jobs:
195207
timeout 10 ./occ app_api:daemon:register --net host manual_install "Manual Install" manual-install http localhost http://localhost:8080
196208
timeout 120 ./occ app_api:app:register context_chat_backend manual_install --json-info "{\"appid\":\"context_chat_backend\",\"name\":\"Context Chat Backend\",\"daemon_config_name\":\"manual_install\",\"version\":\"${{ fromJson(steps.appinfo.outputs.result).version }}\",\"secret\":\"12345\",\"port\":10034,\"scopes\":[],\"system_app\":0}" --force-scopes --wait-finish
197209
ls -la context_chat_backend/persistent_storage/*
198-
sleep 30 # Wait for the em server to get ready
199-
200-
- name: Scan files, baseline
201-
run: |
202-
./occ files:scan admin
203-
./occ context_chat:scan admin -m text/plain
204210
205-
- name: Check python memory usage
211+
- name: Initial memory usage check
206212
run: |
207213
ps -p $(cat pid.txt) -o pid,cmd,%mem,rss --sort=-%mem
208214
ps -p $(cat pid.txt) -o %mem --no-headers > initial_mem.txt
209215
210-
- name: Scan files
216+
- name: Run cron jobs
217+
run: |
218+
# every 10 seconds indefinitely
219+
while true; do
220+
php cron.php
221+
sleep 10
222+
done &
223+
sleep 30
224+
# list all the bg jobs
225+
./occ background-job:list
226+
227+
- name: Initial dump of DB with context_chat_queue populated
228+
if: always()
211229
run: |
212-
./occ files:scan admin
213-
./occ context_chat:scan admin -m text/markdown &
214-
./occ context_chat:scan admin -m text/x-rst
230+
docker exec postgres pg_dump nextcloud > /tmp/0_pgdump_nextcloud
215231
216-
- name: Check python memory usage
232+
- name: Periodically check context_chat stats for 15 minutes to allow the backend to index the files
217233
run: |
218-
ps -p $(cat pid.txt) -o pid,cmd,%mem,rss --sort=-%mem
219-
ps -p $(cat pid.txt) -o %mem --no-headers > after_scan_mem.txt
234+
success=0
235+
echo "::group::Checking stats periodically for 15 minutes to allow the backend to index the files"
236+
for i in {1..90}; do
237+
echo "Checking stats, attempt $i..."
238+
239+
stats_err=$(mktemp)
240+
stats_exit=0
241+
stats=$(timeout 30 ./occ context_chat:stats --json 2>"$stats_err") || stats_exit=$?
242+
echo "Stats output:"
243+
echo "$stats"
244+
if [ -s "$stats_err" ]; then
245+
echo "Stderr:"
246+
cat "$stats_err"
247+
fi
248+
echo "---"
249+
rm -f "$stats_err"
250+
251+
# Check for critical errors in output
252+
if [ $stats_exit -ne 0 ] || echo "$stats" | grep -q "Error during request"; then
253+
echo "Backend connection error detected (exit=$stats_exit), retrying..."
254+
sleep 10
255+
continue
256+
fi
257+
258+
# Extract total eligible files
259+
total_eligible_files=$(echo "$stats" | jq '.eligible_files_count' || echo "")
260+
261+
# Extract indexed documents count (files__default)
262+
indexed_count=$(echo "$stats" | jq '.vectordb_document_counts.files__default' || echo "")
263+
264+
echo "Total eligible files: $total_eligible_files"
265+
echo "Indexed documents (files__default): $indexed_count"
266+
267+
diff=$((total_eligible_files - indexed_count))
268+
threshold=$((total_eligible_files * 3 / 100))
269+
270+
# Check if difference is within tolerance
271+
if [ $diff -le $threshold ]; then
272+
echo "Indexing within 3% tolerance (diff=$diff, threshold=$threshold)"
273+
success=1
274+
break
275+
else
276+
progress=$((diff * 100 / total_eligible_files))
277+
echo "Outside 3% tolerance: diff=$diff (${progress}%), threshold=$threshold"
278+
fi
279+
280+
# Check if backend is still alive
281+
ccb_alive=$(ps -p $(cat pid.txt) -o cmd= | grep -c "main.py" || echo "0")
282+
if [ "$ccb_alive" -eq 0 ]; then
283+
echo "Error: Context Chat Backend process is not running. Exiting."
284+
exit 1
285+
fi
286+
287+
sleep 10
288+
done
289+
290+
echo "::endgroup::"
291+
292+
if [ $success -ne 1 ]; then
293+
echo "Max attempts reached"
294+
exit 1
295+
fi
220296
221297
- name: Run the prompts
222298
run: |
223299
./occ background-job:worker 'OC\TaskProcessing\SynchronousBackgroundJob' > worker1_logs 2>&1 &
224300
./occ background-job:worker 'OC\TaskProcessing\SynchronousBackgroundJob' > worker2_logs 2>&1 &
225301
302+
echo ::group::English prompt
226303
OUT1=$(./occ context_chat:prompt admin "Which factors are taken into account for the Ethical AI Rating?")
227304
echo "$OUT1"
228-
echo '--------------------------------------------------'
305+
echo "$OUT1" | grep -q "If all of these points are met, we give a Green label." || exit 1
306+
echo ::endgroup::
307+
308+
echo ::group::German prompt
229309
OUT2=$(./occ context_chat:prompt admin "Welche Faktoren beeinflussen das Ethical AI Rating?")
230310
echo "$OUT2"
231-
232-
echo "$OUT1" | grep -q "If all of these points are met, we give a Green label." || exit 1
233311
echo "$OUT2" | grep -q "If all of these points are met, we give a Green label." || exit 1
312+
echo ::endgroup::
234313
235314
- name: Check python memory usage
236315
run: |
@@ -250,18 +329,10 @@ jobs:
250329
echo "Memory usage during scan is stable. No memory leak detected."
251330
fi
252331
253-
- name: Compare memory usage and detect leak
332+
- name: Final dump of DB with vectordb populated
333+
if: always()
254334
run: |
255-
initial_mem=$(cat after_scan_mem.txt | tr -d ' ')
256-
final_mem=$(cat after_prompt_mem.txt | tr -d ' ')
257-
echo "Initial Memory Usage: $initial_mem%"
258-
echo "Memory Usage after prompt: $final_mem%"
259-
260-
if (( $(echo "$final_mem > $initial_mem" | bc -l) )); then
261-
echo "Memory usage has increased during prompt. Possible memory leak detected!"
262-
else
263-
echo "Memory usage during prompt is stable. No memory leak detected."
264-
fi
335+
docker exec postgres pg_dump nextcloud > /tmp/1_pgdump_nextcloud
265336
266337
- name: Show server logs
267338
if: always()
@@ -298,6 +369,21 @@ jobs:
298369
run: |
299370
tail -v -n +1 context_chat_backend/persistent_storage/logs/em_server.log* || echo "No logs in logs directory"
300371
372+
- name: Upload database dumps
373+
uses: actions/upload-artifact@v4
374+
if: always()
375+
with:
376+
name: database-dumps-${{ matrix.server-versions }}-php@${{ matrix.php-versions }}
377+
path: |
378+
/tmp/0_pgdump_nextcloud
379+
/tmp/1_pgdump_nextcloud
380+
381+
- name: Final stats log
382+
if: always()
383+
run: |
384+
./occ context_chat:stats
385+
./occ context_chat:stats --json
386+
301387
summary:
302388
permissions:
303389
contents: none

0 commit comments

Comments
 (0)