@budibase/server 2.4.12-alpha.0 → 2.4.12-alpha.2

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.
@@ -1,4 +1,5 @@
1
1
  import appEndpoints from "./applications"
2
+ import metricEndpoints from "./metrics"
2
3
  import queryEndpoints from "./queries"
3
4
  import tableEndpoints from "./tables"
4
5
  import rowEndpoints from "./rows"
@@ -12,7 +13,7 @@ import env from "../../../environment"
12
13
  // below imports don't have declaration files
13
14
  const Router = require("@koa/router")
14
15
  const { RateLimit, Stores } = require("koa2-ratelimit")
15
- import { redis, permissions } from "@budibase/backend-core"
16
+ import { middleware, redis, permissions } from "@budibase/backend-core"
16
17
  const { PermissionType, PermissionLevel } = permissions
17
18
 
18
19
  const PREFIX = "/api/public/v1"
@@ -91,6 +92,13 @@ function addToRouter(endpoints: any) {
91
92
  }
92
93
  }
93
94
 
95
+ function applyAdminRoutes(endpoints: any) {
96
+ addMiddleware(endpoints.read, middleware.builderOrAdmin)
97
+ addMiddleware(endpoints.write, middleware.builderOrAdmin)
98
+ addToRouter(endpoints.read)
99
+ addToRouter(endpoints.write)
100
+ }
101
+
94
102
  function applyRoutes(
95
103
  endpoints: any,
96
104
  permType: string,
@@ -119,6 +127,7 @@ function applyRoutes(
119
127
  addToRouter(endpoints.write)
120
128
  }
121
129
 
130
+ applyAdminRoutes(metricEndpoints)
122
131
  applyRoutes(appEndpoints, PermissionType.APP, "appId")
123
132
  applyRoutes(tableEndpoints, PermissionType.TABLE, "tableId")
124
133
  applyRoutes(userEndpoints, PermissionType.USER, "userId")
@@ -0,0 +1,28 @@
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 }
@@ -0,0 +1,34 @@
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
+ })
@@ -22,6 +22,10 @@ export interface paths {
22
22
  /** Based on application properties (currently only name) search for applications. */
23
23
  post: operations["appSearch"];
24
24
  };
25
+ "/metrics": {
26
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
27
+ get: operations["metricsGet"];
28
+ };
25
29
  "/queries/{queryId}": {
26
30
  /** Queries which have been created within a Budibase app can be executed using this, */
27
31
  post: operations["queryExecute"];
@@ -844,6 +848,17 @@ export interface operations {
844
848
  };
845
849
  };
846
850
  };
851
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
852
+ metricsGet: {
853
+ responses: {
854
+ /** Returns tenant metrics. */
855
+ 200: {
856
+ content: {
857
+ "text/plain": string;
858
+ };
859
+ };
860
+ };
861
+ };
847
862
  /** Queries which have been created within a Budibase app can be executed using this, */
848
863
  queryExecute: {
849
864
  parameters: {