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 mqttClients to license claims #4732

Merged
merged 6 commits into from
Nov 5, 2024
Merged

Conversation

knolleary
Copy link
Member

Part of #4655

Description

As part of enabling billing for MQTT Client usage, this first step adds them as a licensable claim. This will allow us to provide self-hosted customers with a license for more than the default allocation (Teams=5, Enterprise=20).

This has required a little bit of moving code around to enable. The commits in this PR do the following:

  1. Move the DB models/views/controllers to the core set, out of the EE code base. This ensures the db model for MQTT clients is initialised before the licensing code tries to check the current usage level.
  2. Adds mqttClients as a claim in the license
  3. Adds checks on mqttClient usage to the overage checks
  4. Updates the tests for MQTT Clients

The test updates verify the right limits are applied based on license state. Whilst there, I also updated the existing tests to run using a Team Owner who isn't an Admin (bob, not alice). This is ensures the permissions checks aren't being bypassed by the admin flag.

@hardillb
Copy link
Contributor

hardillb commented Nov 4, 2024

Pushed fixes for tests, will review the rest when the tests pass

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes missing coverage. Please review.

Project coverage is 78.73%. Comparing base (bacc9de) to head (aa7e28b).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
forge/db/models/TeamBrokerClient.js 76.92% 3 Missing ⚠️
forge/routes/api/admin.js 40.00% 3 Missing ⚠️
forge/housekeeper/tasks/licenseOverage.js 66.66% 1 Missing ⚠️
forge/licensing/license-generator.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4732   +/-   ##
=======================================
  Coverage   78.72%   78.73%           
=======================================
  Files         311      311           
  Lines       14672    14697   +25     
  Branches     3355     3363    +8     
=======================================
+ Hits        11551    11572   +21     
- Misses       3121     3125    +4     
Flag Coverage Δ
backend 78.73% <78.94%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hardillb hardillb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple of question

Comment on lines +23 to +42
hooks: function (M, app) {
return {
beforeCreate: async (project, opts) => {
// if the product is licensed, we permit overage
const isLicensed = app.license.active()
if (isLicensed !== true) {
const { mqttClients } = await app.license.usage('mqttClients')
if (mqttClients.count >= mqttClients.limit) {
throw new Error('license limit reached')
}
}
},
afterCreate: async (project, opts) => {
const { mqttClients } = await app.license.usage('mqttClients')
if (mqttClients.count > mqttClients.limit) {
await app.auditLog.Platform.platform.license.overage('system', null, mqttClients)
}
}
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to generate a new license for prod (and staging) before this gets merged?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically no, as we are licensed so allowed to go over the limits at the platform level - but we'll get audit log overage reports. So in practice, we'll want to deploy a new license around the same time as this merging - just doesn't have to be strictly in order.

forge/licensing/license-generator.js Show resolved Hide resolved
forge/licensing/loader.js Show resolved Hide resolved
@knolleary
Copy link
Member Author

Need to add reporting on the license usage to the admin overview page - hold off merge until then.

@knolleary
Copy link
Member Author

Have added mqttClients to /ap1/v1/admin/stats endpoint and include on the Admin Overview page that reports on usage.

Whilst there, also fixed reporting the number of Admin users on the platform. Noticed FFC was reporting 0 admin users via this API. This is because postgres returns booleans as true/false whereas sqlite returns as 1/0 - and the code was looking for 1 explicitly rather than general truthiness.

@hardillb
Copy link
Contributor

hardillb commented Nov 5, 2024

Quick question before merging.

Should the license version have been bumped from 2024-03-04 as it adds a field?

@hardillb hardillb merged commit 019af80 into main Nov 5, 2024
13 checks passed
@hardillb hardillb deleted the mqtt-add-license-enablement branch November 5, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants