Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT container log limitation #1686

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/services/mqtt/docker/eclipse-mosquitto-container.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"ExposedPorts": { "1883/tcp": {} },
"HostConfig": {
"Binds": ["/var/lib/gladysassistant/mosquitto:/mosquitto/config"],
"LogConfig": {
"Type": "json-file",
"Config": {
"max-size": "10m"
}
},
"PortBindings": {
"1883/tcp": [
{
Expand Down
2 changes: 1 addition & 1 deletion server/services/mqtt/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DEFAULT = {
IN_PROGRESS: 'IN_PROGRESS',
ERROR: 'ERROR',
},
MOSQUITTO_VERSION: '2',
MOSQUITTO_VERSION: '3',
};

module.exports = {
Expand Down
12 changes: 7 additions & 5 deletions server/services/mqtt/lib/updateContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const containerParams = require('../docker/eclipse-mosquitto-container.json');
async function updateContainer(configuration) {
logger.info('MQTT: checking for required changes...');

// Check for port listener option
// Check for update request
const { brokerContainerAvailable, mosquittoVersion } = configuration;
if (brokerContainerAvailable && !mosquittoVersion) {
logger.info('MQTT: update to mosquitto v2 required...');
if (brokerContainerAvailable && mosquittoVersion !== DEFAULT.MOSQUITTO_VERSION) {
logger.info(`MQTT: update #${DEFAULT.MOSQUITTO_VERSION} of mosquitto container required...`);
const dockerContainers = await this.gladys.system.getContainers({
all: true,
filters: { name: [containerParams.name] },
});

// Remove non versionned container
// Remove old container
if (dockerContainers.length !== 0) {
const [container] = dockerContainers;
await this.gladys.system.removeContainer(container.id, { force: true });
Expand All @@ -36,7 +36,9 @@ async function updateContainer(configuration) {
DEFAULT.MOSQUITTO_VERSION,
this.serviceId,
);
logger.info('MQTT: update to mosquitto v2 done');
logger.info(`MQTT: update #${DEFAULT.MOSQUITTO_VERSION} of mosquitto container done`);
} else {
logger.info('MQTT: no container update required');
}

return configuration;
Expand Down
18 changes: 11 additions & 7 deletions server/test/services/mqtt/lib/updateContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ describe('mqttHandler.updateContainer', function Describe() {
});

it('should updateContainer: already up-to-date', async () => {
const config = { brokerContainerAvailable: true, mosquittoVersion: '2' };
const config = {
brokerContainerAvailable: true,
mosquittoVersion: DEFAULT.MOSQUITTO_VERSION,
};

await mqttHandler.updateContainer(config);

Expand All @@ -71,17 +74,19 @@ describe('mqttHandler.updateContainer', function Describe() {
assert.calledOnce(gladys.system.restartContainer);
assert.calledOnce(installContainerMock.installContainer);

assert.calledOnce(gladys.variable.setValue);
assert.calledWith(
assert.calledOnceWithExactly(
gladys.variable.setValue,
CONFIGURATION.MQTT_MOSQUITTO_VERSION,
DEFAULT.MOSQUITTO_VERSION,
serviceId,
);
});

it('should updateContainer: MQTT container found', async () => {
const config = { brokerContainerAvailable: true };
it('should updateContainer: missing log limitation', async () => {
const config = {
brokerContainerAvailable: true,
mosquittoVersion: '2',
};
gladys.system.getContainers = fake.resolves([{ id: 'container' }]);

await mqttHandler.updateContainer(config);
Expand All @@ -95,8 +100,7 @@ describe('mqttHandler.updateContainer', function Describe() {

assert.calledOnce(installContainerMock.installContainer);

assert.calledOnce(gladys.variable.setValue);
assert.calledWith(
assert.calledOnceWithExactly(
gladys.variable.setValue,
CONFIGURATION.MQTT_MOSQUITTO_VERSION,
DEFAULT.MOSQUITTO_VERSION,
Expand Down