Skip to content

Commit

Permalink
add collecting Prometheus metrics fot the tldraw app (#4621)
Browse files Browse the repository at this point in the history
* add collecting Prometheus metrics fot the tldraw app

---------

Co-authored-by: Tomasz Wiaderek <[email protected]>
  • Loading branch information
wiaderwek and Tomasz Wiaderek authored Dec 18, 2023
1 parent 555c445 commit 291e2da
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ansible/roles/schulcloud-server-core/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,10 @@
template: tldraw-ingress.yml.j2
apply: yes
when: WITH_TLDRAW is defined and WITH_TLDRAW|bool

- name: TldrawServiceMonitor
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: tldraw-svc-monitor.yml.j2
when: WITH_TLDRAW is defined and WITH_TLDRAW|bool
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ spec:
- containerPort: 3349
name: tldraw-http
protocol: TCP
- containerPort: 9090
name: api-metrics
protocol: TCP
envFrom:
- configMapRef:
name: api-configmap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ spec:
targetPort: 3349
protocol: TCP
name: tldraw-http
- port: {{ PORT_METRICS_SERVER }}
targetPort: 9090
protocol: TCP
name: api-metrics
selector:
app: tldraw-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: tldraw-svc-monitor
namespace: {{ NAMESPACE }}
labels:
app: tldraw-server
spec:
selector:
matchExpressions:
- key: app.kubernetes.io/name
operator: in
values:
- tldraw-server-svc
endpoints:
- path: /metrics
port: api-metrics
21 changes: 15 additions & 6 deletions apps/server/src/apps/tldraw.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { enableOpenApiDocs } from '@shared/controller/swagger';
import { AppStartLoggable } from '@src/apps/helpers/app-start-loggable';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import {
addPrometheusMetricsMiddlewaresIfEnabled,
createAndStartPrometheusMetricsAppIfEnabled,
} from '@src/apps/helpers/prometheus-metrics';

async function bootstrap() {
sourceMapInstall();
Expand All @@ -33,18 +37,23 @@ async function bootstrap() {
// mount instances
const rootExpress = express();

addPrometheusMetricsMiddlewaresIfEnabled(logger, rootExpress);
const port = 3349;
const basePath = '/api/v3';

// exposed alias mounts
rootExpress.use(basePath, nestExpress);
rootExpress.listen(port);

logger.info(
new AppStartLoggable({
appName: 'Tldraw server app',
})
);
rootExpress.listen(port, () => {
logger.info(
new AppStartLoggable({
appName: 'Tldraw server app',
port,
})
);

createAndStartPrometheusMetricsAppIfEnabled(logger);
});
}

void bootstrap();

0 comments on commit 291e2da

Please sign in to comment.