From a5b2c00a9a85618fbf4f0beba7616a77f18e5ae5 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Mon, 16 Dec 2024 14:40:41 -0800 Subject: [PATCH 1/2] FORMS-1671: Connect to ESS via NATS protocol Signed-off-by: Jason Sherman --- .devcontainer/chefs_local/test.json | 2 ++ app/config/custom-environment-variables.json | 1 + app/config/default.json | 1 + .../designer/settings/FormEventStreamSettings.vue | 2 +- openshift/README.md | 6 +----- openshift/app.dc.yaml | 10 ---------- openshift/ess.cm.yaml | 15 +++++++++++++++ openshift/ess.dev.param | 5 ++++- openshift/ess.prod.param | 5 ++++- openshift/ess.test.param | 5 ++++- 10 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.devcontainer/chefs_local/test.json b/.devcontainer/chefs_local/test.json index bf781161d..b5472c4aa 100644 --- a/.devcontainer/chefs_local/test.json +++ b/.devcontainer/chefs_local/test.json @@ -63,6 +63,8 @@ }, "eventStreamService": { "servers": "localhost:4222,localhost:4223,localhost:4224", + "websockets": "false", + "consumerservers": "localhost:4222,localhost:4223,localhost:4224", "streamName": "CHEFS", "source": "chefs", "domain": "forms", diff --git a/app/config/custom-environment-variables.json b/app/config/custom-environment-variables.json index e9a8b34ab..17d6f23b1 100755 --- a/app/config/custom-environment-variables.json +++ b/app/config/custom-environment-variables.json @@ -61,6 +61,7 @@ "eventStreamService": { "servers": "EVENTSTREAMSERVICE_SERVERS", "websockets": "EVENTSTREAMSERVICE_WEBSOCKETS", + "consumerservers": "EVENTSTREAMSERVICE_CONSUMERSERVERS", "streamName": "EVENTSTREAMSERVICE_STREAMNAME", "source": "EVENTSTREAMSERVICE_SOURCE", "domain": "EVENTSTREAMSERVICE_DOMAIN", diff --git a/app/config/default.json b/app/config/default.json index 0cb75ba33..08606d032 100644 --- a/app/config/default.json +++ b/app/config/default.json @@ -65,6 +65,7 @@ "eventStreamService": { "servers": "localhost:4222,localhost:4223,localhost:4224", "websockets": "false", + "consumerservers": "localhost:4222,localhost:4223,localhost:4224", "streamName": "CHEFS", "source": "chefs-local", "domain": "forms", diff --git a/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue b/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue index 93051f4fb..6583e9972 100644 --- a/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue +++ b/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue @@ -127,7 +127,7 @@ defineExpose({ >{{ $t('trans.formSettings.serversLabel') }}: {{ - appStore.config?.eventStreamService?.servers + appStore.config?.eventStreamService?.consumerservers }}
diff --git a/openshift/README.md b/openshift/README.md index f8646e619..2d8d5b5d7 100644 --- a/openshift/README.md +++ b/openshift/README.md @@ -157,18 +157,14 @@ oc create -n $NAMESPACE secret generic $APP_NAME-encryption-keys \ --from-literal=proxy=$proxy_key ``` -We need to store a password for Event Stream Service client. Since the server(s) will change along with the password, we will store the server and credentials in a secret per environment (DEV, TEST, PROD) and whether we connect with WebSockets or NATS protocols Pull requests can use the same as DEV. +We need to store a username/password for Event Stream Service client. Additional configuration (Stream name, servers, stream limits) is in a Config Map: `chefs-XXX-event-stream-service`. ```sh -export ess_servers= -export ess_websockets= export ess_password= oc create -n $NAMESPACE secret generic $APP_NAME-event-stream-service \ --type=Opaque \ - --from-literal=servers=$ess_servers \ - --from-literal=websockets=$ess_websockets \ --from-literal=username=chefs \ --from-literal=password=$ess_password ``` diff --git a/openshift/app.dc.yaml b/openshift/app.dc.yaml index 7afebe3a7..df6d8a4d3 100644 --- a/openshift/app.dc.yaml +++ b/openshift/app.dc.yaml @@ -233,16 +233,6 @@ objects: secretKeyRef: key: mailapitoken name: "chefs-${JOB_NAME}-secret" - - name: EVENTSTREAMSERVICE_SERVERS - valueFrom: - secretKeyRef: - key: servers - name: "${APP_NAME}-event-stream-service" - - name: EVENTSTREAMSERVICE_WEBSOCKETS - valueFrom: - secretKeyRef: - key: websockets - name: "${APP_NAME}-event-stream-service" - name: EVENTSTREAMSERVICE_USERNAME valueFrom: secretKeyRef: diff --git a/openshift/ess.cm.yaml b/openshift/ess.cm.yaml index 845619b8d..935e51ad5 100644 --- a/openshift/ess.cm.yaml +++ b/openshift/ess.cm.yaml @@ -17,6 +17,9 @@ objects: metadata: name: "${APP_NAME}-${JOB_NAME}-event-stream-service" data: + EVENTSTREAMSERVICE_SERVERS: ${SERVERS} + EVENTSTREAMSERVICE_WEBSOCKETS: ${WEBSOCKETS} + EVENTSTREAMSERVICE_CONSUMERSERVERS: ${CONSUMERSERVERS} EVENTSTREAMSERVICE_STREAMNAME: ${STREAMNAME} EVENTSTREAMSERVICE_SOURCE: ${SOURCE} EVENTSTREAMSERVICE_DOMAIN: ${DOMAIN} @@ -35,6 +38,18 @@ parameters: description: Job identifier (i.e. 'pr-5' OR 'master') displayName: Job Branch Name required: true + - name: SERVERS + description: Comma separated list of NATS servers for Event Stream Service + displayName: Event Stream NATS servers + required: true + - name: WEBSOCKETS + description: Connect to ESS via websockets or NATS protocol + displayName: Connect with websockets + required: true + - name: CONSUMERSERVERS + description: ESS Servers for consumer configuration + displayName: ESS Servers (consumers) + required: true - name: STREAMNAME description: Name of the CHEFS Event Stream displayName: CHEFS Event Stream name diff --git a/openshift/ess.dev.param b/openshift/ess.dev.param index db79f8b97..26cfafc3b 100644 --- a/openshift/ess.dev.param +++ b/openshift/ess.dev.param @@ -6,4 +6,7 @@ MAXBYTES="966367641" MAXMSGS="1000" MAXMSGSIZE="966367" DUPLICATEWINDOW="60000" -NUMREPLICAS="3" \ No newline at end of file +NUMREPLICAS="3" +SERVERS=ess-nats.a191b5-dev.svc.cluster.local +WEBSOCKETS=false +CONSUMERSERVERS=stream-dev.apps.silver.devops.gov.bc.ca \ No newline at end of file diff --git a/openshift/ess.prod.param b/openshift/ess.prod.param index 7f45ab835..5043d8854 100644 --- a/openshift/ess.prod.param +++ b/openshift/ess.prod.param @@ -6,4 +6,7 @@ MAXBYTES="966367641" MAXMSGS="1000" MAXMSGSIZE="966367" DUPLICATEWINDOW="60000" -NUMREPLICAS="3" \ No newline at end of file +NUMREPLICAS="3" +SERVERS=ess-nats.a191b5-prod.svc.cluster.local +WEBSOCKETS=false +CONSUMERSERVERS=stream.digital.gov.bc.ca \ No newline at end of file diff --git a/openshift/ess.test.param b/openshift/ess.test.param index 1164c056d..b0d600591 100644 --- a/openshift/ess.test.param +++ b/openshift/ess.test.param @@ -6,4 +6,7 @@ MAXBYTES="209715200" MAXMSGS="500" MAXMSGSIZE="419430" DUPLICATEWINDOW="60000" -NUMREPLICAS="3" \ No newline at end of file +NUMREPLICAS="3" +SERVERS=ess-nats.a191b5-test.svc.cluster.local +WEBSOCKETS=false +CONSUMERSERVERS=stream-test.apps.silver.devops.gov.bc.ca \ No newline at end of file From 09ec18a3141a8522d8355f8ae5b0bb8408c40833 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Thu, 9 Jan 2025 15:52:19 -0800 Subject: [PATCH 2/2] add some ux tests Signed-off-by: Jason Sherman --- .../settings/FormEventStreamSettings.vue | 8 ++--- .../settings/FormEventStreamSettings.spec.js | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue b/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue index 6583e9972..f26075d73 100644 --- a/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue +++ b/app/frontend/src/components/designer/settings/FormEventStreamSettings.vue @@ -126,7 +126,7 @@ defineExpose({ {{ $t('trans.formSettings.serversLabel') }}: - {{ + {{ appStore.config?.eventStreamService?.consumerservers }} @@ -135,7 +135,7 @@ defineExpose({ {{ $t('trans.formSettings.streamNameLabel') }}: - {{ + {{ appStore.config?.eventStreamService?.streamName }} @@ -144,7 +144,7 @@ defineExpose({ {{ $t('trans.formSettings.sourceLabel') }}: - {{ + {{ appStore.config?.eventStreamService?.source }} @@ -153,7 +153,7 @@ defineExpose({ {{ $t('trans.formSettings.domainLabel') }}: - {{ + {{ appStore.config?.eventStreamService?.domain }} diff --git a/app/frontend/tests/unit/components/designer/settings/FormEventStreamSettings.spec.js b/app/frontend/tests/unit/components/designer/settings/FormEventStreamSettings.spec.js index 1993ffd76..27d8e1d6c 100644 --- a/app/frontend/tests/unit/components/designer/settings/FormEventStreamSettings.spec.js +++ b/app/frontend/tests/unit/components/designer/settings/FormEventStreamSettings.spec.js @@ -4,6 +4,7 @@ import { setActivePinia } from 'pinia'; import { beforeEach, describe, expect, it } from 'vitest'; import { ref } from 'vue'; +import { useAppStore } from '~/store/app'; import { useFormStore } from '~/store/form'; import FormEventStreamSettings from '~/components/designer/settings/FormEventStreamSettings.vue'; @@ -12,11 +13,41 @@ describe('FormEventStreamSettings.vue', () => { setActivePinia(pinia); const formStore = useFormStore(pinia); + const appStore = useAppStore(pinia); beforeEach(() => { + appStore.$reset(); formStore.$reset(); }); + it('renders eventStreamService configuration', async () => { + appStore.config = ref({ + eventStreamService: { + consumerservers: 'http://consumerservers.com', + streamName: 'stream', + source: 'src', + domain: 'domain', + }, + }); + const wrapper = mount(FormEventStreamSettings, { + global: { + plugins: [pinia], + stubs: { + BasePanel: { + name: 'BasePanel', + template: '
', + }, + }, + }, + }); + expect(wrapper.find('[data-test="consumerservers"]').text()).toContain( + 'http://consumerservers.com' + ); + expect(wrapper.find('[data-test="streamName"]').text()).toContain('stream'); + expect(wrapper.find('[data-test="source"]').text()).toContain('src'); + expect(wrapper.find('[data-test="domain"]').text()).toContain('domain'); + }); + it('generates an encryption key when it has an algorithm', async () => { formStore.form = ref({ eventStreamConfig: {