@budibase/server 2.4.42-alpha.4 → 2.4.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/__mocks__/node-fetch.ts +1 -6
  2. package/builder/assets/favicon.e7fc7733.png +0 -0
  3. package/builder/assets/{index.3e01f4fd.js → index.3d64bc07.js} +384 -384
  4. package/builder/assets/index.b0e3aca6.css +6 -0
  5. package/builder/index.html +7 -7
  6. package/dist/api/controllers/application.js +24 -28
  7. package/dist/api/controllers/row/external.js +0 -15
  8. package/dist/api/controllers/row/utils.js +3 -4
  9. package/dist/api/controllers/static/index.js +24 -84
  10. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -34
  11. package/dist/api/controllers/table/utils.js +1 -0
  12. package/dist/api/routes/public/index.js +0 -8
  13. package/dist/app.js +0 -1
  14. package/dist/integrations/redis.js +1 -1
  15. package/dist/package.json +12 -13
  16. package/dist/sdk/users/utils.js +1 -2
  17. package/dist/tsconfig.build.tsbuildinfo +1 -1
  18. package/dist/utilities/global.js +7 -17
  19. package/jest.config.ts +0 -1
  20. package/package.json +13 -14
  21. package/scripts/test.sh +3 -3
  22. package/specs/openapi.json +0 -39
  23. package/specs/openapi.yaml +0 -169
  24. package/specs/resources/application.ts +0 -11
  25. package/specs/resources/index.ts +0 -2
  26. package/src/api/controllers/application.ts +21 -20
  27. package/src/api/controllers/row/external.ts +0 -14
  28. package/src/api/controllers/row/utils.ts +3 -4
  29. package/src/api/controllers/static/index.ts +26 -69
  30. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -34
  31. package/src/api/controllers/table/utils.ts +1 -0
  32. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  33. package/src/api/routes/public/index.ts +1 -10
  34. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  35. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  36. package/src/api/routes/tests/internalSearch.spec.js +7 -8
  37. package/src/app.ts +1 -2
  38. package/src/automations/automationUtils.ts +1 -1
  39. package/src/automations/tests/automation.spec.js +84 -0
  40. package/src/definitions/openapi.ts +0 -15
  41. package/src/integration-test/postgres.spec.ts +52 -46
  42. package/src/integrations/redis.ts +1 -1
  43. package/src/integrations/tests/googlesheets.spec.ts +13 -13
  44. package/src/integrations/tests/redis.spec.ts +5 -9
  45. package/src/middleware/currentapp.ts +2 -2
  46. package/src/sdk/users/utils.ts +1 -4
  47. package/src/tests/jestEnv.ts +0 -1
  48. package/src/tests/jestSetup.ts +1 -5
  49. package/src/tests/utilities/TestConfiguration.ts +0 -13
  50. package/src/tests/utilities/structures.ts +1 -13
  51. package/src/utilities/global.ts +9 -21
  52. package/builder/assets/index.3cb1022d.css +0 -6
  53. package/dist/api/controllers/public/metrics.js +0 -113
  54. package/dist/api/routes/public/metrics.js +0 -30
  55. package/specs/resources/metrics.ts +0 -81
  56. package/src/api/controllers/public/metrics.ts +0 -251
  57. package/src/api/routes/public/metrics.ts +0 -28
  58. package/src/api/routes/public/tests/metrics.spec.js +0 -34
  59. package/src/api/routes/tests/appSync.spec.ts +0 -31
  60. package/src/automations/tests/automation.spec.ts +0 -99
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.convertToOpenMetrics = exports.fetch = void 0;
16
- const backend_core_1 = require("@budibase/backend-core");
17
- const pro_1 = require("@budibase/pro");
18
- const os_1 = __importDefault(require("os"));
19
- function fetch(ctx) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- // *** OPERATING SYSTEM ***
22
- const freeMem = os_1.default.freemem();
23
- const totalMem = os_1.default.totalmem();
24
- const usedMem = totalMem - freeMem;
25
- const uptime = os_1.default.uptime();
26
- // *** APPS ***
27
- const allDatabases = yield backend_core_1.db.getAllDbs();
28
- const devAppIDs = yield backend_core_1.db.getDevAppIDs();
29
- const prodAppIDs = yield backend_core_1.db.getProdAppIDs();
30
- const allAppIds = yield backend_core_1.db.getAllApps({ idsOnly: true });
31
- // *** USERS ***
32
- const usersObject = yield backend_core_1.users.getAllUserIds();
33
- // *** QUOTAS ***
34
- const usage = yield pro_1.quotas.getQuotaUsage();
35
- const license = yield pro_1.licensing.cache.getCachedLicense();
36
- const appsQuotaUsage = usage.usageQuota.apps;
37
- const rowsQuotaUsage = usage.usageQuota.rows;
38
- const pluginsQuotaUsage = usage.usageQuota.plugins;
39
- const userGroupsQuotaUsage = usage.usageQuota.userGroups;
40
- const queryQuotaUsage = usage.monthly.current.queries;
41
- const automationsQuotaUsage = usage.monthly.current.automations;
42
- const appsQuotaLimit = license.quotas.usage.static.apps.value;
43
- const rowsQuotaLimit = license.quotas.usage.static.rows.value;
44
- const userGroupsQuotaLimit = license.quotas.usage.static.userGroups.value;
45
- const pluginsQuotaLimit = license.quotas.usage.static.plugins.value;
46
- const queryQuotaLimit = license.quotas.usage.monthly.queries.value;
47
- const automationsQuotaLimit = license.quotas.usage.monthly.automations.value;
48
- // *** BUILD THE OUTPUT STRING ***
49
- var outputString = "";
50
- // **** budibase_os_uptime ****
51
- outputString += convertToOpenMetrics("budibase_os_uptime", "Time in seconds that the host operating system has been up", "counter", uptime);
52
- // **** budibase_os_free_mem ****
53
- outputString += convertToOpenMetrics("budibase_os_free_mem", "Bytes of memory free for usage on the host operating system", "gauge", freeMem);
54
- // **** budibase_os_total_mem ****
55
- outputString += convertToOpenMetrics("budibase_os_total_mem", "Total bytes of memory on the host operating system", "gauge", totalMem);
56
- // **** budibase_os_used_mem ****
57
- outputString += convertToOpenMetrics("budibase_os_used_mem", "Total bytes of memory in use on the host operating system", "gauge", usedMem);
58
- // **** budibase_os_load1 ****
59
- outputString += convertToOpenMetrics("budibase_os_load1", "Host operating system load average", "gauge", os_1.default.loadavg()[0]);
60
- // **** budibase_os_load5 ****
61
- outputString += convertToOpenMetrics("budibase_os_load5", "Host operating system load average", "gauge", os_1.default.loadavg()[1]);
62
- // **** budibase_os_load15 ****
63
- outputString += convertToOpenMetrics("budibase_os_load15", "Host operating system load average", "gauge", os_1.default.loadavg()[2]);
64
- // **** budibase_tenant_user_count ****
65
- outputString += convertToOpenMetrics("budibase_tenant_user_count", "The number of users created", "gauge", usersObject.length);
66
- // **** budibase_tenant_app_count ****
67
- outputString += convertToOpenMetrics("budibase_tenant_app_count", "The number of apps created by a user", "gauge", allAppIds.length);
68
- // **** budibase_tenant_production_app_count ****
69
- outputString += convertToOpenMetrics("budibase_tenant_production_app_count", "The number of apps a user has published", "gauge", prodAppIDs.length);
70
- // **** budibase_tenant_dev_app_count ****
71
- outputString += convertToOpenMetrics("budibase_tenant_dev_app_count", "The number of apps a user has unpublished in development", "gauge", devAppIDs.length);
72
- // **** budibase_tenant_db_count ****
73
- outputString += convertToOpenMetrics("budibase_tenant_db_count", "The number of couchdb databases including global tables such as _users", "gauge", allDatabases.length);
74
- // **** budibase_quota_usage_apps ****
75
- outputString += convertToOpenMetrics("budibase_quota_usage_apps", "The number of apps created", "gauge", appsQuotaUsage);
76
- // **** budibase_quota_limit_apps ****
77
- outputString += convertToOpenMetrics("budibase_quota_limit_apps", "The limit on the number of apps that can be created", "gauge", appsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : appsQuotaLimit);
78
- // **** budibase_quota_usage_rows ****
79
- outputString += convertToOpenMetrics("budibase_quota_usage_rows", "The number of database rows used from the quota", "gauge", rowsQuotaUsage);
80
- // **** budibase_quota_limit_rows ****
81
- outputString += convertToOpenMetrics("budibase_quota_limit_rows", "The limit on the number of rows that can be created", "gauge", rowsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : rowsQuotaLimit);
82
- // **** budibase_quota_usage_plugins ****
83
- outputString += convertToOpenMetrics("budibase_quota_usage_plugins", "The number of plugins in use", "gauge", pluginsQuotaUsage);
84
- // **** budibase_quota_limit_plugins ****
85
- outputString += convertToOpenMetrics("budibase_quota_limit_plugins", "The limit on the number of plugins that can be created", "gauge", pluginsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : pluginsQuotaLimit);
86
- // **** budibase_quota_usage_user_groups ****
87
- outputString += convertToOpenMetrics("budibase_quota_usage_user_groups", "The number of user groups created", "gauge", userGroupsQuotaUsage);
88
- // **** budibase_quota_limit_user_groups ****
89
- outputString += convertToOpenMetrics("budibase_quota_limit_user_groups", "The limit on the number of user groups that can be created", "gauge", userGroupsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : userGroupsQuotaLimit);
90
- // **** budibase_quota_usage_queries ****
91
- outputString += convertToOpenMetrics("budibase_quota_usage_queries", "The number of queries used in the current month", "gauge", queryQuotaUsage);
92
- // **** budibase_quota_limit_queries ****
93
- outputString += convertToOpenMetrics("budibase_quota_limit_queries", "The limit on the number of queries for the current month", "gauge", queryQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : queryQuotaLimit);
94
- // **** budibase_quota_usage_automations ****
95
- outputString += convertToOpenMetrics("budibase_quota_usage_automations", "The number of automations used in the current month", "gauge", automationsQuotaUsage);
96
- // **** budibase_quota_limit_automations ****
97
- outputString += convertToOpenMetrics("budibase_quota_limit_automations", "The limit on the number of automations that can be created", "gauge", automationsQuotaLimit == -1
98
- ? Number.MAX_SAFE_INTEGER
99
- : automationsQuotaLimit);
100
- ctx.body = outputString;
101
- ctx.set("Content-Type", "text/plain");
102
- });
103
- }
104
- exports.fetch = fetch;
105
- function convertToOpenMetrics(metricName, metricHelp, metricType, metricValue) {
106
- return `# HELP ${metricName} ${metricHelp}.
107
- # TYPE ${metricName} ${metricType}
108
- ${metricName} ${metricValue}\n`;
109
- }
110
- exports.convertToOpenMetrics = convertToOpenMetrics;
111
- exports.default = {
112
- fetch,
113
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const metrics_1 = __importDefault(require("../../controllers/public/metrics"));
7
- const Endpoint_1 = __importDefault(require("./utils/Endpoint"));
8
- const read = [];
9
- /**
10
- * @openapi
11
- * /metrics:
12
- * get:
13
- * operationId: metricsGet
14
- * summary: Retrieve Budibase tenant metrics
15
- * description: Output metrics in OpenMetrics format compatible with Prometheus
16
- * tags:
17
- * - metrics
18
- * responses:
19
- * 200:
20
- * description: Returns tenant metrics.
21
- * content:
22
- * text/plain:
23
- * schema:
24
- * type: string
25
- * examples:
26
- * metrics:
27
- * $ref: '#/components/examples/metrics'
28
- */
29
- read.push(new Endpoint_1.default("get", "/metrics", metrics_1.default.fetch));
30
- exports.default = { read };
@@ -1,81 +0,0 @@
1
- import Resource from "./utils/Resource"
2
-
3
- const metricsResponse =
4
- "# HELP budibase_os_uptime Time in seconds that the host operating system has been up.\n" +
5
- "# TYPE budibase_os_uptime counter\n" +
6
- "budibase_os_uptime 54958\n" +
7
- "# HELP budibase_os_free_mem Bytes of memory free for usage on the host operating system.\n" +
8
- "# TYPE budibase_os_free_mem gauge\n" +
9
- "budibase_os_free_mem 804507648\n" +
10
- "# HELP budibase_os_total_mem Total bytes of memory on the host operating system.\n" +
11
- "# TYPE budibase_os_total_mem gauge\n" +
12
- "budibase_os_total_mem 16742404096\n" +
13
- "# HELP budibase_os_used_mem Total bytes of memory in use on the host operating system.\n" +
14
- "# TYPE budibase_os_used_mem gauge\n" +
15
- "budibase_os_used_mem 15937896448\n" +
16
- "# HELP budibase_os_load1 Host operating system load average.\n" +
17
- "# TYPE budibase_os_load1 gauge\n" +
18
- "budibase_os_load1 1.91\n" +
19
- "# HELP budibase_os_load5 Host operating system load average.\n" +
20
- "# TYPE budibase_os_load5 gauge\n" +
21
- "budibase_os_load5 1.75\n" +
22
- "# HELP budibase_os_load15 Host operating system load average.\n" +
23
- "# TYPE budibase_os_load15 gauge\n" +
24
- "budibase_os_load15 1.56\n" +
25
- "# HELP budibase_tenant_user_count The number of users created.\n" +
26
- "# TYPE budibase_tenant_user_count gauge\n" +
27
- "budibase_tenant_user_count 1\n" +
28
- "# HELP budibase_tenant_app_count The number of apps created by a user.\n" +
29
- "# TYPE budibase_tenant_app_count gauge\n" +
30
- "budibase_tenant_app_count 2\n" +
31
- "# HELP budibase_tenant_production_app_count The number of apps a user has published.\n" +
32
- "# TYPE budibase_tenant_production_app_count gauge\n" +
33
- "budibase_tenant_production_app_count 1\n" +
34
- "# HELP budibase_tenant_dev_app_count The number of apps a user has unpublished in development.\n" +
35
- "# TYPE budibase_tenant_dev_app_count gauge\n" +
36
- "budibase_tenant_dev_app_count 1\n" +
37
- "# HELP budibase_tenant_db_count The number of couchdb databases including global tables such as _users.\n" +
38
- "# TYPE budibase_tenant_db_count gauge\n" +
39
- "budibase_tenant_db_count 3\n" +
40
- "# HELP budibase_quota_usage_apps The number of apps created.\n" +
41
- "# TYPE budibase_quota_usage_apps gauge\n" +
42
- "budibase_quota_usage_apps 1\n" +
43
- "# HELP budibase_quota_limit_apps The limit on the number of apps that can be created.\n" +
44
- "# TYPE budibase_quota_limit_apps gauge\n" +
45
- "budibase_quota_limit_apps 9007199254740991\n" +
46
- "# HELP budibase_quota_usage_rows The number of database rows used from the quota.\n" +
47
- "# TYPE budibase_quota_usage_rows gauge\n" +
48
- "budibase_quota_usage_rows 0\n" +
49
- "# HELP budibase_quota_limit_rows The limit on the number of rows that can be created.\n" +
50
- "# TYPE budibase_quota_limit_rows gauge\n" +
51
- "budibase_quota_limit_rows 9007199254740991\n" +
52
- "# HELP budibase_quota_usage_plugins The number of plugins in use.\n" +
53
- "# TYPE budibase_quota_usage_plugins gauge\n" +
54
- "budibase_quota_usage_plugins 0\n" +
55
- "# HELP budibase_quota_limit_plugins The limit on the number of plugins that can be created.\n" +
56
- "# TYPE budibase_quota_limit_plugins gauge\n" +
57
- "budibase_quota_limit_plugins 9007199254740991\n" +
58
- "# HELP budibase_quota_usage_user_groups The number of user groups created.\n" +
59
- "# TYPE budibase_quota_usage_user_groups gauge\n" +
60
- "budibase_quota_usage_user_groups 0\n" +
61
- "# HELP budibase_quota_limit_user_groups The limit on the number of user groups that can be created.\n" +
62
- "# TYPE budibase_quota_limit_user_groups gauge\n" +
63
- "budibase_quota_limit_user_groups 9007199254740991\n" +
64
- "# HELP budibase_quota_usage_queries The number of queries used in the current month.\n" +
65
- "# TYPE budibase_quota_usage_queries gauge\n" +
66
- "budibase_quota_usage_queries 0\n" +
67
- "# HELP budibase_quota_limit_queries The limit on the number of queries for the current month.\n" +
68
- "# TYPE budibase_quota_limit_queries gauge\n" +
69
- "budibase_quota_limit_queries 9007199254740991\n" +
70
- "# HELP budibase_quota_usage_automations The number of automations used in the current month.\n" +
71
- "# TYPE budibase_quota_usage_automations gauge\n" +
72
- "budibase_quota_usage_automations 0\n" +
73
- "# HELP budibase_quota_limit_automations The limit on the number of automations that can be created.\n" +
74
- "# TYPE budibase_quota_limit_automations gauge\n" +
75
- "budibase_quota_limit_automations 9007199254740991\n"
76
-
77
- export default new Resource().setExamples({
78
- metrics: {
79
- value: metricsResponse,
80
- },
81
- })
@@ -1,251 +0,0 @@
1
- import { Ctx } from "@budibase/types"
2
- import { users as userCore, db as dbCore } from "@budibase/backend-core"
3
- import { quotas, licensing } from "@budibase/pro"
4
-
5
- import os from "os"
6
-
7
- export async function fetch(ctx: Ctx) {
8
- // *** OPERATING SYSTEM ***
9
- const freeMem = os.freemem()
10
- const totalMem = os.totalmem()
11
- const usedMem = totalMem - freeMem
12
- const uptime = os.uptime()
13
-
14
- // *** APPS ***
15
- const allDatabases = await dbCore.getAllDbs()
16
- const devAppIDs = await dbCore.getDevAppIDs()
17
- const prodAppIDs = await dbCore.getProdAppIDs()
18
- const allAppIds = await dbCore.getAllApps({ idsOnly: true })
19
-
20
- // *** USERS ***
21
- const usersObject = await userCore.getAllUserIds()
22
-
23
- // *** QUOTAS ***
24
- const usage = await quotas.getQuotaUsage()
25
- const license = await licensing.cache.getCachedLicense()
26
- const appsQuotaUsage = usage.usageQuota.apps
27
- const rowsQuotaUsage = usage.usageQuota.rows
28
- const pluginsQuotaUsage = usage.usageQuota.plugins
29
- const userGroupsQuotaUsage = usage.usageQuota.userGroups
30
- const queryQuotaUsage = usage.monthly.current.queries
31
- const automationsQuotaUsage = usage.monthly.current.automations
32
- const appsQuotaLimit = license.quotas.usage.static.apps.value
33
- const rowsQuotaLimit = license.quotas.usage.static.rows.value
34
- const userGroupsQuotaLimit = license.quotas.usage.static.userGroups.value
35
- const pluginsQuotaLimit = license.quotas.usage.static.plugins.value
36
- const queryQuotaLimit = license.quotas.usage.monthly.queries.value
37
- const automationsQuotaLimit = license.quotas.usage.monthly.automations.value
38
-
39
- // *** BUILD THE OUTPUT STRING ***
40
- var outputString = ""
41
-
42
- // **** budibase_os_uptime ****
43
- outputString += convertToOpenMetrics(
44
- "budibase_os_uptime",
45
- "Time in seconds that the host operating system has been up",
46
- "counter",
47
- uptime
48
- )
49
-
50
- // **** budibase_os_free_mem ****
51
- outputString += convertToOpenMetrics(
52
- "budibase_os_free_mem",
53
- "Bytes of memory free for usage on the host operating system",
54
- "gauge",
55
- freeMem
56
- )
57
-
58
- // **** budibase_os_total_mem ****
59
- outputString += convertToOpenMetrics(
60
- "budibase_os_total_mem",
61
- "Total bytes of memory on the host operating system",
62
- "gauge",
63
- totalMem
64
- )
65
-
66
- // **** budibase_os_used_mem ****
67
- outputString += convertToOpenMetrics(
68
- "budibase_os_used_mem",
69
- "Total bytes of memory in use on the host operating system",
70
- "gauge",
71
- usedMem
72
- )
73
-
74
- // **** budibase_os_load1 ****
75
- outputString += convertToOpenMetrics(
76
- "budibase_os_load1",
77
- "Host operating system load average",
78
- "gauge",
79
- os.loadavg()[0]
80
- )
81
-
82
- // **** budibase_os_load5 ****
83
- outputString += convertToOpenMetrics(
84
- "budibase_os_load5",
85
- "Host operating system load average",
86
- "gauge",
87
- os.loadavg()[1]
88
- )
89
- // **** budibase_os_load15 ****
90
- outputString += convertToOpenMetrics(
91
- "budibase_os_load15",
92
- "Host operating system load average",
93
- "gauge",
94
- os.loadavg()[2]
95
- )
96
-
97
- // **** budibase_tenant_user_count ****
98
- outputString += convertToOpenMetrics(
99
- "budibase_tenant_user_count",
100
- "The number of users created",
101
- "gauge",
102
- usersObject.length
103
- )
104
-
105
- // **** budibase_tenant_app_count ****
106
- outputString += convertToOpenMetrics(
107
- "budibase_tenant_app_count",
108
- "The number of apps created by a user",
109
- "gauge",
110
- allAppIds.length
111
- )
112
-
113
- // **** budibase_tenant_production_app_count ****
114
- outputString += convertToOpenMetrics(
115
- "budibase_tenant_production_app_count",
116
- "The number of apps a user has published",
117
- "gauge",
118
- prodAppIDs.length
119
- )
120
-
121
- // **** budibase_tenant_dev_app_count ****
122
- outputString += convertToOpenMetrics(
123
- "budibase_tenant_dev_app_count",
124
- "The number of apps a user has unpublished in development",
125
- "gauge",
126
- devAppIDs.length
127
- )
128
-
129
- // **** budibase_tenant_db_count ****
130
- outputString += convertToOpenMetrics(
131
- "budibase_tenant_db_count",
132
- "The number of couchdb databases including global tables such as _users",
133
- "gauge",
134
- allDatabases.length
135
- )
136
-
137
- // **** budibase_quota_usage_apps ****
138
- outputString += convertToOpenMetrics(
139
- "budibase_quota_usage_apps",
140
- "The number of apps created",
141
- "gauge",
142
- appsQuotaUsage
143
- )
144
-
145
- // **** budibase_quota_limit_apps ****
146
- outputString += convertToOpenMetrics(
147
- "budibase_quota_limit_apps",
148
- "The limit on the number of apps that can be created",
149
- "gauge",
150
- appsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : appsQuotaLimit
151
- )
152
-
153
- // **** budibase_quota_usage_rows ****
154
- outputString += convertToOpenMetrics(
155
- "budibase_quota_usage_rows",
156
- "The number of database rows used from the quota",
157
- "gauge",
158
- rowsQuotaUsage
159
- )
160
-
161
- // **** budibase_quota_limit_rows ****
162
- outputString += convertToOpenMetrics(
163
- "budibase_quota_limit_rows",
164
- "The limit on the number of rows that can be created",
165
- "gauge",
166
- rowsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : rowsQuotaLimit
167
- )
168
-
169
- // **** budibase_quota_usage_plugins ****
170
- outputString += convertToOpenMetrics(
171
- "budibase_quota_usage_plugins",
172
- "The number of plugins in use",
173
- "gauge",
174
- pluginsQuotaUsage
175
- )
176
-
177
- // **** budibase_quota_limit_plugins ****
178
- outputString += convertToOpenMetrics(
179
- "budibase_quota_limit_plugins",
180
- "The limit on the number of plugins that can be created",
181
- "gauge",
182
- pluginsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : pluginsQuotaLimit
183
- )
184
-
185
- // **** budibase_quota_usage_user_groups ****
186
- outputString += convertToOpenMetrics(
187
- "budibase_quota_usage_user_groups",
188
- "The number of user groups created",
189
- "gauge",
190
- userGroupsQuotaUsage
191
- )
192
-
193
- // **** budibase_quota_limit_user_groups ****
194
- outputString += convertToOpenMetrics(
195
- "budibase_quota_limit_user_groups",
196
- "The limit on the number of user groups that can be created",
197
- "gauge",
198
- userGroupsQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : userGroupsQuotaLimit
199
- )
200
-
201
- // **** budibase_quota_usage_queries ****
202
- outputString += convertToOpenMetrics(
203
- "budibase_quota_usage_queries",
204
- "The number of queries used in the current month",
205
- "gauge",
206
- queryQuotaUsage
207
- )
208
-
209
- // **** budibase_quota_limit_queries ****
210
- outputString += convertToOpenMetrics(
211
- "budibase_quota_limit_queries",
212
- "The limit on the number of queries for the current month",
213
- "gauge",
214
- queryQuotaLimit == -1 ? Number.MAX_SAFE_INTEGER : queryQuotaLimit
215
- )
216
-
217
- // **** budibase_quota_usage_automations ****
218
- outputString += convertToOpenMetrics(
219
- "budibase_quota_usage_automations",
220
- "The number of automations used in the current month",
221
- "gauge",
222
- automationsQuotaUsage
223
- )
224
-
225
- // **** budibase_quota_limit_automations ****
226
- outputString += convertToOpenMetrics(
227
- "budibase_quota_limit_automations",
228
- "The limit on the number of automations that can be created",
229
- "gauge",
230
- automationsQuotaLimit == -1
231
- ? Number.MAX_SAFE_INTEGER
232
- : automationsQuotaLimit
233
- )
234
- ctx.body = outputString
235
- ctx.set("Content-Type", "text/plain")
236
- }
237
-
238
- export function convertToOpenMetrics(
239
- metricName: string,
240
- metricHelp: string,
241
- metricType: string,
242
- metricValue: number
243
- ) {
244
- return `# HELP ${metricName} ${metricHelp}.
245
- # TYPE ${metricName} ${metricType}
246
- ${metricName} ${metricValue}\n`
247
- }
248
-
249
- export default {
250
- fetch,
251
- }
@@ -1,28 +0,0 @@
1
- import controller from "../../controllers/public/metrics"
2
- import Endpoint from "./utils/Endpoint"
3
-
4
- const read = []
5
-
6
- /**
7
- * @openapi
8
- * /metrics:
9
- * get:
10
- * operationId: metricsGet
11
- * summary: Retrieve Budibase tenant metrics
12
- * description: Output metrics in OpenMetrics format compatible with Prometheus
13
- * tags:
14
- * - metrics
15
- * responses:
16
- * 200:
17
- * description: Returns tenant metrics.
18
- * content:
19
- * text/plain:
20
- * schema:
21
- * type: string
22
- * examples:
23
- * metrics:
24
- * $ref: '#/components/examples/metrics'
25
- */
26
- read.push(new Endpoint("get", "/metrics", controller.fetch))
27
-
28
- export default { read }
@@ -1,34 +0,0 @@
1
- const setup = require("../../tests/utilities")
2
-
3
- jest.setTimeout(30000)
4
-
5
- describe("/metrics", () => {
6
- let request = setup.getRequest()
7
- let config = setup.getConfig()
8
-
9
- afterAll(setup.afterAll)
10
-
11
- // For some reason this cannot be a beforeAll or the test "should be able to update the user" fail
12
- beforeEach(async () => {
13
- await config.init()
14
- })
15
-
16
- describe("get", () => {
17
- it("returns a list of metrics", async () => {
18
- const res = await request
19
- .get(`/api/public/v1/metrics`)
20
- .set(config.defaultHeaders())
21
- .expect("Content-Type", /text\/plain/)
22
- .expect(200)
23
- expect(res.text).toContain("budibase_tenant_user_count")
24
- })
25
-
26
- it("endpoint should not be publicly exposed", async () => {
27
- await request
28
- .get(`/api/public/v1/metrics`)
29
- .set(config.publicHeaders())
30
- .expect(403)
31
- })
32
- })
33
-
34
- })
@@ -1,31 +0,0 @@
1
- import * as setup from "./utilities"
2
- import { roles, db as dbCore } from "@budibase/backend-core"
3
-
4
- describe("/api/applications/:appId/sync", () => {
5
- let request = setup.getRequest()
6
- let config = setup.getConfig()
7
- let app
8
-
9
- afterAll(setup.afterAll)
10
-
11
- beforeAll(async () => {
12
- app = await config.init()
13
- // create some users which we will use throughout the tests
14
- await config.createUser({
15
- email: "sync1@test.com",
16
- roles: {
17
- [app._id!]: roles.BUILTIN_ROLE_IDS.BASIC,
18
- },
19
- })
20
- })
21
-
22
- async function getUserMetadata() {
23
- const { rows } = await config.searchRows(dbCore.InternalTable.USER_METADATA)
24
- return rows
25
- }
26
-
27
- it("make sure that user metadata is correctly sync'd", async () => {
28
- const rows = await getUserMetadata()
29
- expect(rows.length).toBe(1)
30
- })
31
- })
@@ -1,99 +0,0 @@
1
- jest.mock("../../threads/automation")
2
- jest.mock("../../utilities/redis", () => ({
3
- init: jest.fn(),
4
- checkTestFlag: () => {
5
- return false
6
- },
7
- }))
8
-
9
- jest.spyOn(global.console, "error")
10
-
11
- import "../../environment"
12
- import * as automation from "../index"
13
- import * as thread from "../../threads/automation"
14
- import * as triggers from "../triggers"
15
- import { basicAutomation } from "../../tests/utilities/structures"
16
- import { wait } from "../../utilities"
17
- import { makePartial } from "../../tests/utilities"
18
- import { cleanInputValues } from "../automationUtils"
19
- import * as setup from "./utilities"
20
- import { Automation } from "@budibase/types"
21
-
22
- describe("Run through some parts of the automations system", () => {
23
- let config = setup.getConfig()
24
-
25
- beforeAll(async () => {
26
- await automation.init()
27
- await config.init()
28
- })
29
-
30
- afterAll(async () => {
31
- await automation.shutdown()
32
- setup.afterAll()
33
- })
34
-
35
- it("should be able to init in builder", async () => {
36
- const automation: Automation = {
37
- ...basicAutomation(),
38
- appId: config.appId,
39
- }
40
- const fields: any = { a: 1, appId: config.appId }
41
- await triggers.externalTrigger(automation, fields)
42
- await wait(100)
43
- expect(thread.execute).toHaveBeenCalled()
44
- })
45
-
46
- it("should check coercion", async () => {
47
- const table = await config.createTable()
48
- const automation: any = basicAutomation()
49
- automation.definition.trigger.inputs.tableId = table._id
50
- automation.definition.trigger.stepId = "APP"
51
- automation.definition.trigger.inputs.fields = { a: "number" }
52
- const fields: any = {
53
- appId: config.getAppId(),
54
- fields: {
55
- a: "1",
56
- },
57
- }
58
- await triggers.externalTrigger(automation, fields)
59
- await wait(100)
60
- expect(thread.execute).toHaveBeenCalledWith(
61
- makePartial({
62
- data: {
63
- event: {
64
- fields: {
65
- a: 1,
66
- },
67
- },
68
- },
69
- }),
70
- expect.any(Function)
71
- )
72
- })
73
-
74
- it("should be able to clean inputs with the utilities", () => {
75
- // can't clean without a schema
76
- let output = cleanInputValues({ a: "1" })
77
- expect(output.a).toBe("1")
78
- output = cleanInputValues(
79
- { a: "1", b: "true", c: "false", d: 1, e: "help" },
80
- {
81
- properties: {
82
- a: {
83
- type: "number",
84
- },
85
- b: {
86
- type: "boolean",
87
- },
88
- c: {
89
- type: "boolean",
90
- },
91
- },
92
- }
93
- )
94
- expect(output.a).toBe(1)
95
- expect(output.b).toBe(true)
96
- expect(output.c).toBe(false)
97
- expect(output.d).toBe(1)
98
- })
99
- })