-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3716 from FlowFuse/3715-health-check-interval
Implement health check interval user setting
- Loading branch information
Showing
10 changed files
with
330 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
frontend/src/pages/instance/Settings/LauncherSettings.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<template> | ||
<FormHeading class="mb-6">Launcher Settings</FormHeading> | ||
<form class="space-y-6" data-el="launcher-settings-form"> | ||
<FormRow v-model="input.healthCheckInterval" type="number" :error="errors.healthCheckInterval"> | ||
Health check interval (ms) | ||
<template #description> | ||
The interval at which the launcher will check the health of Node-RED. | ||
Flows that perform CPU intensive work may need to increase this from the default of 7500ms. | ||
</template> | ||
</FormRow> | ||
|
||
<div class="space-x-4 whitespace-nowrap"> | ||
<ff-button size="small" :disabled="!unsavedChanges || !validateFormInputs()" data-action="save-settings" @click="saveSettings()">Save settings</ff-button> | ||
</div> | ||
</form> | ||
</template> | ||
|
||
<script> | ||
import { useRouter } from 'vue-router' | ||
import { mapState } from 'vuex' | ||
import InstanceApi from '../../../api/instances.js' | ||
import FormHeading from '../../../components/FormHeading.vue' | ||
import FormRow from '../../../components/FormRow.vue' | ||
import permissionsMixin from '../../../mixins/Permissions.js' | ||
import alerts from '../../../services/alerts.js' | ||
export default { | ||
name: 'LauncherSettings', | ||
components: { | ||
FormRow, | ||
FormHeading | ||
}, | ||
mixins: [permissionsMixin], | ||
inheritAttrs: false, | ||
props: { | ||
project: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
emits: ['instance-updated'], | ||
data () { | ||
return { | ||
mounted: false, | ||
original: { | ||
healthCheckInterval: null | ||
}, | ||
input: { | ||
healthCheckInterval: null | ||
}, | ||
errors: { | ||
healthCheckInterval: '' | ||
} | ||
} | ||
}, | ||
computed: { | ||
...mapState('account', ['team', 'teamMembership']), | ||
unsavedChanges: function () { | ||
return this.original.healthCheckInterval !== this.input.healthCheckInterval | ||
} | ||
}, | ||
watch: { | ||
project: 'getSettings', | ||
'input.healthCheckInterval': function (value) { | ||
if (this.mounted) { | ||
this.validateFormInputs() | ||
} | ||
} | ||
}, | ||
mounted () { | ||
this.checkAccess() | ||
this.getSettings() | ||
this.mounted = true | ||
}, | ||
methods: { | ||
checkAccess: function () { | ||
if (!this.hasPermission('project:edit')) { | ||
useRouter().push({ replace: true, path: 'general' }) | ||
} | ||
}, | ||
validateFormInputs () { | ||
if (!this.unsavedChanges) { | ||
this.errors.healthCheckInterval = '' | ||
} else { | ||
const hci = parseInt(this.input.healthCheckInterval) | ||
if (isNaN(hci) || hci < 5000) { | ||
this.errors.healthCheckInterval = 'Health check interval must be 5000 or greater' | ||
} else { | ||
this.errors.healthCheckInterval = '' | ||
} | ||
} | ||
return !this.errors.healthCheckInterval | ||
}, | ||
getSettings: function () { | ||
this.original.healthCheckInterval = this.project?.launcherSettings?.healthCheckInterval | ||
this.input.healthCheckInterval = this.project?.launcherSettings.healthCheckInterval | ||
}, | ||
async saveSettings () { | ||
const launcherSettings = { | ||
healthCheckInterval: this.input.healthCheckInterval | ||
} | ||
if (!this.validateFormInputs()) { | ||
alerts.emit('Please correct the errors before saving.', 'error') | ||
return | ||
} | ||
await InstanceApi.updateInstance(this.project.id, { launcherSettings }) | ||
this.$emit('instance-updated') | ||
alerts.emit('Instance successfully updated. Restart the instance to apply the changes.', 'confirmation') | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
test/e2e/frontend/cypress/tests/instances/settings/launcher.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/// <reference types="Cypress" /> | ||
describe('FlowFuse - Instance - Settings - Launcher', () => { | ||
function navigateToInstanceSettings (teamName, projectName) { | ||
cy.request('GET', '/api/v1/user/teams') | ||
.then((response) => { | ||
const team = response.body.teams.find( | ||
(team) => team.name === teamName | ||
) | ||
return cy.request('GET', `/api/v1/teams/${team.id}/projects`) | ||
}) | ||
.then((response) => { | ||
const project = response.body.projects.find( | ||
(project) => project.name === projectName | ||
) | ||
cy.visit(`/instance/${project.id}/settings/general`) | ||
cy.wait('@getInstance') | ||
}) | ||
} | ||
|
||
function getForm () { | ||
return cy.get('[data-el="launcher-settings-form"]') | ||
} | ||
|
||
beforeEach(() => { | ||
cy.intercept('GET', '/api/*/projects/').as('getProjects') | ||
cy.intercept('GET', '/api/*/projects/*').as('getInstance') | ||
cy.login('bob', 'bbPassword') | ||
cy.home() | ||
}) | ||
|
||
it('Validates health check interval user input', () => { | ||
cy.intercept('PUT', '/api/*/projects/*').as('updateInstance') | ||
// navigate to instance settings -> launcher tab | ||
cy.login('bob', 'bbPassword') | ||
cy.home() | ||
navigateToInstanceSettings('BTeam', 'instance-2-1') | ||
|
||
cy.get('[data-el="section-side-menu"] li').contains('Launcher').click() | ||
|
||
// wait for url /instance/***/settings/launcher | ||
cy.url().should('include', 'settings/launcher') | ||
|
||
// Change value to < 5000 | ||
getForm().first('div').get('.ff-input > input[type=number]').clear() | ||
getForm().first('div').get('.ff-input > input[type=number]').type(4999) | ||
cy.get('[data-action="save-settings"]').should('be.disabled') | ||
getForm().first('div').get('[data-el="form-row-error"').contains('Health check interval must be 5000 or greater').should('exist') | ||
|
||
// Change value to > 5000 | ||
getForm().first('div').get('.ff-input > input[type=number]').clear() | ||
getForm().first('div').get('.ff-input > input[type=number]').type(5001) | ||
cy.get('[data-action="save-settings"]').should('not.be.disabled') | ||
getForm().first('div').get('[data-el="form-row-error"').should('not.exist') | ||
}) | ||
|
||
it('Can set health check interval value', () => { | ||
cy.intercept('PUT', '/api/*/projects/*').as('updateInstance') | ||
|
||
navigateToInstanceSettings('BTeam', 'instance-2-1') | ||
|
||
// locate and click on the launcher tab | ||
cy.get('[data-el="section-side-menu"] li').contains('Launcher').click() | ||
|
||
// wait for url /instance/***/settings/launcher | ||
cy.url().should('include', 'settings/launcher') | ||
|
||
// // ensure the first child's title is correct | ||
getForm().should('exist') | ||
getForm().first('div').should('exist') | ||
getForm().first('div').get('[data-el="form-row-title"]').contains('Health check interval (ms)').should('exist') | ||
// ensure the first child's numeric input exists | ||
getForm().first('div').get('.ff-input > input[type=number]').should('exist') | ||
|
||
// Change value & save | ||
const randomBetween6789and9876 = Math.floor(Math.random() * (9876 - 6789 + 1)) + 6789 | ||
getForm().first('div').get('.ff-input > input[type=number]').clear() | ||
getForm().first('div').get('.ff-input > input[type=number]').type(randomBetween6789and9876) | ||
cy.get('[data-action="save-settings"]').click() | ||
cy.wait('@updateInstance') | ||
|
||
// refresh page | ||
navigateToInstanceSettings('BTeam', 'instance-2-1') | ||
cy.get('[data-el="section-side-menu"] li').contains('Launcher').click() | ||
|
||
// check value is restored | ||
cy.get('[data-el="launcher-settings-form"]').first().get('.ff-input > input[type=number]').should('have.value', randomBetween6789and9876) | ||
}) | ||
}) |
Oops, something went wrong.