Feature: Adds toojet hub telemetry endpoint (#2283)

* adds endpoint for telemetry on tooljet hub

* remove optional params

* enable telemetry only for prod env

* remove org scope
This commit is contained in:
Akshay 2022-02-17 21:49:53 +05:30 committed by GitHub
parent a550018aa9
commit 98d6fb928e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 13 deletions

View file

@ -6,7 +6,7 @@ TOOLJET_HOST=http://localhost:8082
LOCKBOX_MASTER_KEY=0000000000000000000000000000000000000000000000000000000000000000
SECRET_KEY_BASE=replace_with_secret_key_base
## Configure a hostname for the server
## Configure a hostname for the server
SERVER_HOST=<hostname>
# DATABASE CONFIG
@ -16,9 +16,14 @@ PG_USER=<db username>
PG_HOST=<db host>
PG_PASS=<db password>
# Checks every 24 hours to see if a new version of ToolJet is available (Enabled by default. Set 0 to disable)
# Checks every 24 hours to see if a new version of ToolJet is available
# (Enabled by default. Set 0 to disable)
CHECK_FOR_UPDATES=0
# Checks every 24 hours to update app telemetry data to ToolJet hub.
# (Telemetry is enabled by default. Set value to true to disable.)
# DISABLE_APP_TELEMETRY=false
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
@ -45,4 +50,4 @@ SSO_DISABLE_SIGNUP=
SSO_RESTRICTED_DOMAIN=
SSO_GOOGLE_OAUTH2_CLIENT_ID=
SSO_GIT_OAUTH2_CLIENT_ID=
SSO_GIT_OAUTH2_CLIENT_SECRET=
SSO_GIT_OAUTH2_CLIENT_SECRET=

View file

@ -46,7 +46,7 @@ Self-hosted version of ToolJet pings our server to fetch the latest product upda
#### Comment feature enable ( optional )
Use this environment variable to enable/disable the feature that allows you to add comments on the canvas.
Use this environment variable to enable/disable the feature that allows you to add comments on the canvas.
| variable | value |
| -------- | ---------------------- |
@ -135,7 +135,7 @@ Specify application monitoring vendor. Currently supported values - `sentry`.
#### SENTRY DEBUG ( optional )
Prints logs for sentry.
Prints logs for sentry.
| variable | description |
| ---------- | ----------------------------------------- |
@ -167,6 +167,11 @@ Tooljet needs to be configured for custom CA certificate to be able to trust and
| ------------------ | ----------------------------------------------------------------- |
| NODE_EXTRA_CA_CERTS | absolute path to certifcate PEM file ( eg: /ToolJet/ca/cert.pem ) |
#### Disable telemetry ( optional )
Pings our server to update the total user count every 24 hours. You can disable this by setting the value of `DISABLE_TOOLJET_TELEMETRY` environment variable to `true`. This feature is enabled by default.
## ToolJet client
#### Server URL ( optionally required )

View file

@ -13,7 +13,9 @@ export class MetadataController {
const installedVersion = globalThis.TOOLJET_VERSION;
const metadata = await this.metadataService.getMetaData();
await this.metadataService.finishInstallation(metadata, installedVersion, name, email, org);
if (process.env.NODE_ENV == 'production') {
await this.metadataService.finishInstallation(metadata, installedVersion, name, email, org);
}
await this.metadataService.updateMetaData({
onboarded: true,
@ -56,10 +58,16 @@ export class MetadataController {
const updateLastCheckedAt = new Date(data['last_checked'] || null);
const diffTime = (now.getTime() - updateLastCheckedAt.getTime()) / 1000;
if (diffTime > 86400) {
const result = await this.metadataService.checkForUpdates(installedVersion, ignoredVersion);
latestVersion = result.latestVersion;
versionIgnored = false;
if (diffTime > 86400 && process.env.NODE_ENV == 'production') {
if (process.env.CHECK_FOR_UPDATES) {
const result = await this.metadataService.checkForUpdates(installedVersion, ignoredVersion);
latestVersion = result.latestVersion;
versionIgnored = false;
}
if (!process.env.DISABLED_TOOLJET_TELEMETRY) {
await this.metadataService.sendTelemetryData(metadata);
}
}
return {

View file

@ -1,9 +1,11 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { getManager, Repository } from 'typeorm';
import { Metadata } from 'src/entities/metadata.entity';
import { gt } from 'semver';
const got = require('got');
import got from 'got';
import { User } from 'src/entities/user.entity';
@Injectable()
export class MetadataService {
constructor(
@ -30,7 +32,9 @@ export class MetadataService {
async updateMetaData(newOptions: any) {
const metadata = await this.metadataRepository.findOne({});
return await this.metadataRepository.update(metadata.id, { data: { ...metadata.data, ...newOptions } });
return await this.metadataRepository.update(metadata.id, {
data: { ...metadata.data, ...newOptions },
});
}
async finishInstallation(metadata: any, installedVersion: string, name: string, email: string, org: string) {
@ -46,6 +50,18 @@ export class MetadataService {
});
}
async sendTelemetryData(metadata: Metadata) {
const totalUserCount = await getManager().count(User);
return await got('https://hub.tooljet.io/telemetry', {
method: 'post',
json: {
id: metadata.id,
total_users: totalUserCount,
},
});
}
async checkForUpdates(installedVersion: string, ignoredVersion: string) {
const response = await got('https://hub.tooljet.io/updates', {
method: 'post',