From 4be0cba9b50a044dda8872e39d8f445316c97422 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Sat, 4 Apr 2026 00:09:37 +0800 Subject: [PATCH] chore(server): db health check (#14779) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### PR Dependency Tree * **PR #14779** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Chores** * Added conditional init checks to service deployments and jobs to wait for the database proxy before starting * Exposed a new health port (9801) for the database proxy to enable readiness probing * **Tests** * Minor test reordering and formatting changes (no behavioral changes) --- .../charts/front/templates/deployment.yaml | 16 ++++++++++++++ .../gcloud-sql-proxy/templates/service.yaml | 4 ++++ .../charts/graphql/templates/deployment.yaml | 16 ++++++++++++++ .../charts/graphql/templates/migration.yaml | 16 ++++++++++++++ .../calendar/__tests__/service.spec.ts | 22 +++++++++++++------ 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/.github/helm/affine/charts/front/templates/deployment.yaml b/.github/helm/affine/charts/front/templates/deployment.yaml index 6efdc80199..e36e10daf3 100644 --- a/.github/helm/affine/charts/front/templates/deployment.yaml +++ b/.github/helm/affine/charts/front/templates/deployment.yaml @@ -25,6 +25,22 @@ spec: serviceAccountName: {{ include "front.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- with .Values.global.database.gcloud }} + {{- if .enabled }} + initContainers: + - name: wait-for-cloud-sql-proxy + image: busybox:1.36.1 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + until wget -q -T 2 -O /dev/null "http://{{ $.Values.global.database.host }}:9801/startup"; do + echo "waiting for cloud sql proxy to become ready" + sleep 2 + done + {{- end }} + {{- end }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/.github/helm/affine/charts/gcloud-sql-proxy/templates/service.yaml b/.github/helm/affine/charts/gcloud-sql-proxy/templates/service.yaml index 6c4e174a87..412d2ecd0f 100644 --- a/.github/helm/affine/charts/gcloud-sql-proxy/templates/service.yaml +++ b/.github/helm/affine/charts/gcloud-sql-proxy/templates/service.yaml @@ -12,6 +12,10 @@ spec: targetPort: cloud-sql-proxy protocol: TCP name: cloud-sql-proxy + - port: 9801 + targetPort: 9801 + protocol: TCP + name: health selector: {{- include "gcloud-sql-proxy.selectorLabels" . | nindent 4 }} {{- end }} diff --git a/.github/helm/affine/charts/graphql/templates/deployment.yaml b/.github/helm/affine/charts/graphql/templates/deployment.yaml index d8ae967958..da332b07d0 100644 --- a/.github/helm/affine/charts/graphql/templates/deployment.yaml +++ b/.github/helm/affine/charts/graphql/templates/deployment.yaml @@ -23,6 +23,22 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "graphql.serviceAccountName" . }} + {{- with .Values.global.database.gcloud }} + {{- if .enabled }} + initContainers: + - name: wait-for-cloud-sql-proxy + image: busybox:1.36.1 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + until wget -q -T 2 -O /dev/null "http://{{ $.Values.global.database.host }}:9801/startup"; do + echo "waiting for cloud sql proxy to become ready" + sleep 2 + done + {{- end }} + {{- end }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/.github/helm/affine/charts/graphql/templates/migration.yaml b/.github/helm/affine/charts/graphql/templates/migration.yaml index 4b2f2cb687..0fc60a80cd 100644 --- a/.github/helm/affine/charts/graphql/templates/migration.yaml +++ b/.github/helm/affine/charts/graphql/templates/migration.yaml @@ -13,6 +13,22 @@ spec: template: spec: serviceAccountName: {{ include "graphql.serviceAccountName" . }} + {{- with .Values.global.database.gcloud }} + {{- if .enabled }} + initContainers: + - name: wait-for-cloud-sql-proxy + image: busybox:1.36.1 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + until wget -q -T 2 -O /dev/null "http://{{ $.Values.global.database.host }}:9801/startup"; do + echo "waiting for cloud sql proxy to become ready" + sleep 2 + done + {{- end }} + {{- end }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/packages/backend/server/src/plugins/calendar/__tests__/service.spec.ts b/packages/backend/server/src/plugins/calendar/__tests__/service.spec.ts index 9fa7c6bf4e..bc8ba059a9 100644 --- a/packages/backend/server/src/plugins/calendar/__tests__/service.spec.ts +++ b/packages/backend/server/src/plugins/calendar/__tests__/service.spec.ts @@ -17,8 +17,8 @@ import type { UpsertCalendarSubscriptionInput, } from '../../../models'; import { Models } from '../../../models'; -import { CalendarModule } from '../index'; import { CalendarCronJobs } from '../cron'; +import { CalendarModule } from '../index'; import { CalendarProvider, CalendarProviderFactory, @@ -614,9 +614,13 @@ test('pollAccounts skips syncing when cluster lock is unavailable', async t => { 'listAllWithAccountForSync', async () => [] ); - const syncAccountMock = mock.method(calendarService, 'syncAccount', async () => { - return; - }); + const syncAccountMock = mock.method( + calendarService, + 'syncAccount', + async () => { + return; + } + ); await calendarCronJobs.pollAccounts(); @@ -649,9 +653,13 @@ test('pollAccounts only syncs due accounts', async t => { ] as any ); - const syncAccountMock = mock.method(calendarService, 'syncAccount', async () => { - return; - }); + const syncAccountMock = mock.method( + calendarService, + 'syncAccount', + async () => { + return; + } + ); await calendarCronJobs.pollAccounts();