feat: Collect usage metrics on license renewal (no-changelog) (#7486)

This commit is contained in:
Cornelius Suermann
2023-10-23 21:39:29 +02:00
committed by GitHub
parent 774fe202bf
commit 3ef771ea38
4 changed files with 32 additions and 11 deletions

View File

@@ -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",

View File

@@ -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';
@@ -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({
@@ -65,6 +69,7 @@ export class License {
loadCertStr: async () => this.loadCertStr(),
saveCertStr,
deviceFingerprint: () => this.instanceSettings.instanceId,
collectUsageMetrics,
onFeatureChange,
});
@@ -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');

View File

@@ -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,
});
@@ -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,
});