Skip to content

Commit

Permalink
move from prom-client to OpenTelemetry metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <[email protected]>
  • Loading branch information
JessicaJHee committed Nov 8, 2024
1 parent 096947a commit 5b9e1f9
Show file tree
Hide file tree
Showing 8 changed files with 1,351 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ ENV GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE=''
# The `--no-node-snapshot` node option enables the usage of the backstage scaffolder on nodejs 20
# https://github.com/backstage/backstage/issues/20661

ENTRYPOINT ["node", "packages/backend", "--no-node-snapshot", "--config", "app-config.yaml", "--config", "app-config.example.yaml", "--config", "app-config.example.production.yaml"]
ENTRYPOINT ["node", "--require", "./instrumentation.ts", "packages/backend", "--no-node-snapshot", "--config", "app-config.yaml", "--config", "app-config.example.yaml", "--config", "app-config.example.production.yaml"]

# append Brew metadata here
9 changes: 6 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"role": "backend"
},
"scripts": {
"start": "backstage-cli package start",
"start": "backstage-cli package start --require ./src/instrumentation.ts",
"start:prometheus": "docker run --mount type=bind,source=./prometheus.yml,destination=/etc/prometheus/prometheus.yml --publish published=9090,target=9090,protocol=tcp prom/prometheus",
"build": "backstage-cli package build",
"lint:check": "backstage-cli package lint",
"lint:fix": "backstage-cli package lint --fix",
Expand Down Expand Up @@ -49,10 +50,12 @@
"@janus-idp/backstage-plugin-rbac-backend": "5.2.1",
"@janus-idp/backstage-plugin-rbac-node": "1.8.0",
"@janus-idp/backstage-scaffolder-backend-module-annotator": "2.2.0",
"@opentelemetry/auto-instrumentations-node": "^0.50.2",
"@opentelemetry/exporter-prometheus": "^0.53.0",
"@opentelemetry/instrumentation-runtime-node": "^0.9.0",
"@opentelemetry/sdk-node": "^0.53.0",
"app": "*",
"express-prom-bundle": "6.6.0",
"global-agent": "3.0.0",
"prom-client": "15.1.3",
"undici": "6.19.8",
"winston": "3.14.2",
"winston-daily-rotate-file": "5.0.0"
Expand Down
21 changes: 21 additions & 0 deletions packages/backend/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is an example configuration file for Prometheus, that is set to scrape
# the metrics endpoint exposed by the example backend.
#
# If you want to run a docker based Prometheus instance locally to try it out,
# run the following command in the Backstage root:
#
# docker run --mount type=bind,source=./packages/backend/prometheus.yml,destination=/etc/prometheus/prometheus.yml --publish published=9090,target=9090,protocol=tcp prom/prometheus
#
# After this, you have a Prometheus instance on http://localhost:9090

global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
# This target address specifically works on Docker for MacOS - you may
# need to change it to another host depending on your OS and Docker
# engine.
- targets: ['host.docker.internal:9464']
1 change: 0 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ backend.add(
}),
);

backend.add(metricsPlugin);
backend.add(healthCheckPlugin);

backend.add(import('@backstage/plugin-app-backend/alpha'));
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { NodeSDK } = require('@opentelemetry/sdk-node');
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node');
const {
RuntimeNodeInstrumentation,
} = require('@opentelemetry/instrumentation-runtime-node');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

// Metrics on exported to localhost:9464/metrics
const prometheus = new PrometheusExporter();
const sdk = new NodeSDK({
metricReader: prometheus,
instrumentations: [
getNodeAutoInstrumentations(),
new RuntimeNodeInstrumentation(),
],
});

sdk.start();
1 change: 0 additions & 1 deletion packages/backend/src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './authProvidersModule';
export * from './rbacDynamicPluginsModule';
export * from './healthcheck';
export * from './metrics';
49 changes: 0 additions & 49 deletions packages/backend/src/modules/metrics.ts

This file was deleted.

Loading

0 comments on commit 5b9e1f9

Please sign in to comment.