Skip to content

Commit

Permalink
feat: Collect usage metrics on license renewal (no-changelog) (n8n-io…
Browse files Browse the repository at this point in the history
  • Loading branch information
csuermann authored Oct 23, 2023
1 parent 774fe20 commit 3ef771e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
"dependencies": {
"@n8n/client-oauth2": "workspace:*",
"@n8n_io/license-sdk": "~2.6.1",
"@n8n_io/license-sdk": "~2.7.1",
"@oclif/command": "^1.8.16",
"@oclif/config": "^1.18.17",
"@oclif/core": "^1.16.4",
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
UNLIMITED_LICENSE_QUOTA,
} from './constants';
import Container, { Service } from 'typedi';
import { WorkflowRepository } from '@/databases/repositories';
import type { BooleanLicenseFeature, N8nInstanceType, NumericLicenseFeature } from './Interfaces';
import type { RedisServicePubSubPublisher } from './services/redis/RedisServicePubSubPublisher';
import { RedisService } from './services/redis.service';
Expand Down Expand Up @@ -51,6 +52,9 @@ export class License {
const onFeatureChange = isMainInstance
? async (features: TFeatures) => this.onFeatureChange(features)
: async () => {};
const collectUsageMetrics = isMainInstance
? async () => this.collectUsageMetrics()
: async () => [];

try {
this.manager = new LicenseManager({
Expand All @@ -65,6 +69,7 @@ export class License {
loadCertStr: async () => this.loadCertStr(),
saveCertStr,
deviceFingerprint: () => this.instanceSettings.instanceId,
collectUsageMetrics,
onFeatureChange,
});

Expand All @@ -76,6 +81,15 @@ export class License {
}
}

async collectUsageMetrics() {
return [
{
name: 'activeWorkflows',
value: await Container.get(WorkflowRepository).count({ where: { active: true } }),
},
];
}

async loadCertStr(): Promise<TLicenseBlock> {
// if we have an ephemeral license, we don't want to load it from the database
const ephemeralLicense = config.get('license.cert');
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/test/unit/License.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('License', () => {
loadCertStr: expect.any(Function),
saveCertStr: expect.any(Function),
onFeatureChange: expect.any(Function),
collectUsageMetrics: expect.any(Function),
server: MOCK_SERVER_URL,
tenantId: 1,
});
Expand All @@ -61,6 +62,7 @@ describe('License', () => {
loadCertStr: expect.any(Function),
saveCertStr: expect.any(Function),
onFeatureChange: expect.any(Function),
collectUsageMetrics: expect.any(Function),
server: MOCK_SERVER_URL,
tenantId: 1,
});
Expand Down
25 changes: 15 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ef771e

Please sign in to comment.