Skip to content

Commit

Permalink
Merge branch 'usingtechnology-feat/forms-1331-event-stream'
Browse files Browse the repository at this point in the history
resolving package.json merge conflicts.
  • Loading branch information
usingtechnology committed Sep 23, 2024
2 parents 0d49e8d + 2f5c5a0 commit 2bee361
Show file tree
Hide file tree
Showing 148 changed files with 19,680 additions and 9,316 deletions.
12 changes: 12 additions & 0 deletions .devcontainer/chefs_local/local.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
"proxy": "352f7c24819086bf3df5a38c1a40586045f73e0007440c9d27d59ee8560e3fe7"
}
},
"features": {
"eventStreamService": true
},
"eventStreamService": {
"servers": "localhost:4222,localhost:4223,localhost:4224",
"websockets": "false",
"streamName": "CHEFS",
"source": "chefs-local",
"domain": "forms",
"username": "chefs",
"password": "password"
},
"serviceClient": {
"commonServices": {
"ches": {
Expand Down
11 changes: 11 additions & 0 deletions .devcontainer/chefs_local/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
"proxy": "5fb2054478353fd8d514056d1745b3a9eef066deadda4b90967af7ca65ce6505"
}
},
"features": {
"eventStreamService": false
},
"eventStreamService": {
"servers": "localhost:4222,localhost:4223,localhost:4224",
"streamName": "CHEFS",
"source": "chefs",
"domain": "forms",
"username": "chefs",
"password": "password"
},
"serviceClient": {
"commonServices": {
"ches": {
Expand Down
9 changes: 9 additions & 0 deletions .github/actions/deploy-to-environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ runs:
run: |
oc process --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f openshift/app.cm.yaml -p NAMESPACE=${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -p APP_NAME=${{ inputs.acronym }} -p JOB_NAME=${{ inputs.job_name }} -p SERVER_HOST=${{ inputs.server_host }} -o yaml | oc apply --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f -
- name: Deploy event stream ConfigMaps
shell: bash
run: |
if [[ "${{ inputs.job_name }}" == pr-* ]]; then
oc process --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f openshift/ess.cm.yaml -p APP_NAME=${{ inputs.acronym }} -p JOB_NAME=${{ inputs.job_name }} -p SOURCE=${{ inputs.job_name }} -o yaml | oc apply --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f -
else
oc process --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f openshift/ess.cm.yaml -p APP_NAME=${{ inputs.acronym }} -p JOB_NAME=${{ inputs.job_name }} --param-file=openshift/ess.${{ inputs.namespace_environment }}.param -o yaml | oc apply --namespace ${{ inputs.namespace_prefix }}-${{ inputs.namespace_environment }} -f -
fi
- name: Deploy App
shell: bash
run: |
Expand Down
36 changes: 27 additions & 9 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<!-- Provide a general summary of your changes in the Title above -->
<!--
The above Title for the Pull Request should use the format:
type: FORMS-ABCD your change description
For example:
feat: FORMS-1234 add Assigned To column to submission table
-->

# Description

<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If it fixes an open issue, please link to the issue here. -->
<!--
Describe your changes in detail.
- Why is this change required?
- What problem does it solve?
-->

## Types of changes
## Type of Change

<!-- Uncomment the main reason for the change (for example, all feat PRs should include docs and test, but only uncomment feat): -->
<!--
Uncomment the main reason for the change. For example: all "feat" PRs should
include documentation ("docs") and tests ("test"), but only uncomment "feat".
-->

<!-- feat (a new feature) -->
<!-- fix (a bug fix) -->
Expand All @@ -18,6 +29,7 @@
<!-- docs (change to documentation) -->
<!-- perf (change to improve performance) -->
<!-- refactor (change to improve code quality) -->
<!-- revert (reverts changes in a previous commit) -->
<!-- style (change to code style/formatting) -->
<!-- test (add missing tests or correct existing tests) -->

Expand All @@ -27,8 +39,10 @@ This is a breaking change because ...

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
<!--
Go over all the following points, and put an `x` in all the boxes that apply. If
you're unsure about any of these, don't hesitate to ask. We're here to help!
-->

- [ ] I have read the [CONTRIBUTING](/bcgov/common-hosted-form-service/blob/main/CONTRIBUTING.md) doc
- [ ] I have checked that unit tests pass locally with my changes
Expand All @@ -39,4 +53,8 @@ This is a breaking change because ...

## Further comments

<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
<!--
If this is a relatively large or complex change, kick off the discussion by
explaining why you chose the solution you did and what alternatives you
considered, etc...
-->
53 changes: 51 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ const middleware = require('./src/forms/common/middleware');
const v1Router = require('./src/routes/v1');

const DataConnection = require('./src/db/dataConnection');
const { featureFlags } = require('./src/components/featureFlags');
const dataConnection = new DataConnection();
const { eventStreamService } = require('./src/components/eventStreamService');

const apiRouter = express.Router();
const state = {
connections: {
data: false,
eventStreamService: false,
},
ready: false,
shutdown: false,
};

if (!featureFlags.eventStreamService) delete state.connections.eventStreamService;

let probeId;
const app = express();
app.use(compression());
Expand Down Expand Up @@ -58,7 +65,16 @@ apiRouter.use('/config', (_req, res, next) => {
const frontend = config.get('frontend');
// we will need to pass
const uploads = config.get('files.uploads');
const feConfig = { ...frontend, uploads: uploads };
const features = config.get('features');
const feConfig = { ...frontend, uploads: uploads, features: features };
if (featureFlags.eventStreamService) {
let ess = config.util.cloneDeep(config.get('eventStreamService'));
delete ess['username'];
delete ess['password'];
feConfig['eventStreamService'] = {
...ess,
};
}
res.status(200).json(feConfig);
} catch (err) {
next(err);
Expand Down Expand Up @@ -157,6 +173,7 @@ function cleanup() {
log.info('Cleaning up...', { function: 'cleanup' });
clearInterval(probeId);

if (featureFlags.eventStreamService) eventStreamService.closeConnection();
dataConnection.close(() => process.exit());

// Wait 10 seconds max before hard exiting
Expand All @@ -172,6 +189,10 @@ function initializeConnections() {
// Initialize connections and exit if unsuccessful
const tasks = [dataConnection.checkAll()];

if (featureFlags.eventStreamService) {
tasks.push(eventStreamService.checkConnection());
}

Promise.all(tasks)
.then((results) => {
state.connections.data = results[0];
Expand All @@ -180,9 +201,23 @@ function initializeConnections() {
log.info('DataConnection Reachable', {
function: 'initializeConnections',
});

if (featureFlags.eventStreamService) {
state.connections.eventStreamService = results[1];
if (state.connections.eventStreamService) {
log.info('EventStreamService Reachable', {
function: 'initializeConnections',
});
}
} else {
log.info('EventStreamService feature is not enabled.');
}
})
.catch((error) => {
log.error(`Initialization failed: Database OK = ${state.connections.data}`, { function: 'initializeConnections' });
if (featureFlags.eventStreamService)
log.error(`Initialization failed: EventStreamService OK = ${state.connections.eventStreamService}`, { function: 'initializeConnections' });

log.error('Connection initialization failure', error.message, {
function: 'initializeConnections',
});
Expand All @@ -198,7 +233,16 @@ function initializeConnections() {
function: 'initializeConnections',
});
// Start periodic 10 second connection probe check
probeId = setInterval(checkConnections, 10000);
probeId = setInterval(checkConnections, 30000);
} else {
log.error(`Service not ready to accept traffic`, {
function: 'initializeConnections',
});
log.error(`Database connected = ${state.connections.data}`, { function: 'initializeConnections' });
if (featureFlags.eventStreamService) log.error(`EventStreamService connected = ${state.connections.eventStreamService}`, { function: 'initializeConnections' });

process.exitCode = 1;
shutdown();
}
});
}
Expand All @@ -212,16 +256,21 @@ function checkConnections() {
const wasReady = state.ready;
if (!state.shutdown) {
const tasks = [dataConnection.checkConnection()];
if (featureFlags.eventStreamService) tasks.push(eventStreamService.checkConnection());

Promise.all(tasks).then((results) => {
state.connections.data = results[0];
if (featureFlags.eventStreamService) state.connections.eventStreamService = results[1];

state.ready = Object.values(state.connections).every((x) => x);
if (!wasReady && state.ready)
log.info('Service ready to accept traffic', {
function: 'checkConnections',
});
log.verbose(state);
if (!state.ready) {
log.error(`Database connected = ${state.connections.data}`, { function: 'checkConnections' });
if (featureFlags.eventStreamService) log.error(`EventStreamService connected = ${state.connections.eventStreamService}`, { function: 'checkConnections' });
process.exitCode = 1;
shutdown();
}
Expand Down
12 changes: 12 additions & 0 deletions app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
"proxy": "SERVER_ENCRYPTION_PROXY"
}
},
"features": {
"eventStreamService": "FEATURES_EVENTSTREAMSERVICE"
},
"eventStreamService": {
"servers": "EVENTSTREAMSERVICE_SERVERS",
"websockets": "EVENTSTREAMSERVICE_WEBSOCKETS",
"streamName": "EVENTSTREAMSERVICE_STREAMNAME",
"source": "EVENTSTREAMSERVICE_SOURCE",
"domain": "EVENTSTREAMSERVICE_DOMAIN",
"username": "EVENTSTREAMSERVICE_USERNAME",
"password": "EVENTSTREAMSERVICE_PASSWORD"
},
"serviceClient": {
"commonServices": {
"ches": {
Expand Down
12 changes: 12 additions & 0 deletions app/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
"proxy": "352f7c24819086bf3df5a38c1a40586045f73e0007440c9d27d59ee8560e3fe7"
}
},
"features": {
"eventStreamService": true
},
"eventStreamService": {
"servers": "localhost:4222,localhost:4223,localhost:4224",
"websockets": "false",
"streamName": "CHEFS",
"source": "chefs-local",
"domain": "forms",
"username": "chefs",
"password": "password"
},
"serviceClient": {
"commonServices": {
"ches": {
Expand Down
Loading

0 comments on commit 2bee361

Please sign in to comment.