Просмотр исходного кода

Merge pull request #23700 from overleaf/bg-history-redis

add redis to history-v1

GitOrigin-RevId: def900c4b560ea0a297b11b6c0ecc8cc8caa5b49
Brian Gough 1 год назад
Родитель
Сommit
32983da29c

+ 1 - 1
services/history-v1/buildscript.txt

@@ -1,5 +1,5 @@
 history-v1
---dependencies=postgres,gcs,mongo,s3
+--dependencies=postgres,gcs,mongo,redis,s3
 --docker-repos=us-east1-docker.pkg.dev/overleaf-ops/ol-docker
 --env-add=
 --env-pass-through=

+ 8 - 1
services/history-v1/config/custom-environment-variables.json

@@ -82,5 +82,12 @@
   "clusterWorkers": "CLUSTER_WORKERS",
   "maxFileUploadSize": "MAX_FILE_UPLOAD_SIZE",
   "httpsOnly": "HTTPS_ONLY",
-  "httpRequestTimeout": "HTTP_REQUEST_TIMEOUT"
+  "httpRequestTimeout": "HTTP_REQUEST_TIMEOUT",
+  "redis": {
+    "queue": {
+      "host": "REDIS_HOST",
+      "password": "REDIS_PASSWORD",
+      "port": "REDIS_PORT"
+    }
+  }
 }

+ 12 - 0
services/history-v1/docker-compose.ci.yml

@@ -19,6 +19,9 @@ services:
     image: ci/$PROJECT_NAME:$BRANCH_NAME-$BUILD_NUMBER
     environment:
       ELASTIC_SEARCH_DSN: es:9200
+      REDIS_HOST: redis
+      QUEUES_REDIS_HOST: redis
+      ANALYTICS_QUEUES_REDIS_HOST: redis
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       AWS_S3_ENDPOINT: https://minio:9000
@@ -38,6 +41,8 @@ services:
     depends_on:
       mongo:
         condition: service_healthy
+      redis:
+        condition: service_healthy
       postgres:
         condition: service_healthy
       certs:
@@ -59,6 +64,13 @@ services:
       - ./:/tmp/build/
     command: tar -czf /tmp/build/build.tar.gz --exclude=build.tar.gz --exclude-vcs .
     user: root
+  redis:
+    image: redis
+    healthcheck:
+      test: ping="$$(redis-cli ping)" && [ "$$ping" = 'PONG' ]
+      interval: 1s
+      retries: 20
+
   mongo:
     image: mongo:6.0.13
     command: --replSet overleaf

+ 12 - 0
services/history-v1/docker-compose.yml

@@ -36,6 +36,9 @@ services:
     working_dir: /overleaf/services/history-v1
     environment:
       ELASTIC_SEARCH_DSN: es:9200
+      REDIS_HOST: redis
+      QUEUES_REDIS_HOST: redis
+      ANALYTICS_QUEUES_REDIS_HOST: redis
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       AWS_S3_ENDPOINT: https://minio:9000
@@ -55,6 +58,8 @@ services:
     depends_on:
       mongo:
         condition: service_healthy
+      redis:
+        condition: service_healthy
       postgres:
         condition: service_healthy
       certs:
@@ -67,6 +72,13 @@ services:
         condition: service_healthy
     command: npm run --silent test:acceptance
 
+  redis:
+    image: redis
+    healthcheck:
+      test: ping=$$(redis-cli ping) && [ "$$ping" = 'PONG' ]
+      interval: 1s
+      retries: 20
+
   mongo:
     image: mongo:6.0.13
     command: --replSet overleaf

+ 16 - 0
services/history-v1/storage/scripts/redis.mjs

@@ -0,0 +1,16 @@
+import redis from '@overleaf/redis-wrapper'
+import config from 'config'
+
+const redisOptions = config.get('redis.queue')
+
+console.log('REDIS CONFIG', redisOptions)
+const rclient = redis.createClient(redisOptions)
+
+try {
+  await rclient.healthCheck()
+  console.log('REDIS HEALTHCHECK SUCCEEDED')
+} catch (error) {
+  console.error('REDIS HEALTHCHECK FAILED', error)
+} finally {
+  await rclient.quit()
+}