-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
coreServices, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
|
||
export const healthCheckPlugin = createBackendPlugin({ | ||
pluginId: 'healthcheck', | ||
register(reg) { | ||
reg.registerInit({ | ||
deps: { | ||
rootHttpRouter: coreServices.rootHttpRouter, | ||
rootHealth: coreServices.rootHealth, | ||
}, | ||
async init({ rootHttpRouter, rootHealth }) { | ||
rootHttpRouter.use('/healthcheck', async (_, res) => { | ||
const { status, payload } = await rootHealth.getLiveness(); | ||
res.status(status).json(payload); | ||
}); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './authProvidersModule'; | ||
export * from './rbacDynamicPluginsModule'; | ||
export * from './healthcheck'; | ||
export * from './metrics'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
coreServices, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
import promBundle from 'express-prom-bundle'; | ||
import * as url from 'url'; | ||
|
||
const rootRegEx = new RegExp('^/([^/]*)/.*'); | ||
const apiRegEx = new RegExp('^/api/([^/]*)/.*'); | ||
|
||
function normalizePath(req: any): string { | ||
const path = url.parse(req.originalUrl || req.url).pathname || '/'; | ||
|
||
// Capture /api/ and the plugin name | ||
if (apiRegEx.test(path)) { | ||
return path.replace(apiRegEx, '/api/$1'); | ||
} | ||
|
||
// Only the first path segment at root level | ||
return path.replace(rootRegEx, '/$1'); | ||
} | ||
|
||
export const metricsPlugin = createBackendPlugin({ | ||
pluginId: 'metrics', | ||
register(reg) { | ||
reg.registerInit({ | ||
deps: { | ||
rootHttpRouter: coreServices.rootHttpRouter, | ||
}, | ||
async init({ rootHttpRouter }) { | ||
rootHttpRouter.use( | ||
'/metrics', | ||
promBundle({ | ||
includeMethod: true, | ||
includePath: true, | ||
// Using includePath alone is problematic, as it will include path labels with high | ||
// cardinality (e.g. path params). Instead we would have to template them. However, this | ||
// is difficult, as every backend plugin might use different routes. Instead we only take | ||
// the first directory of the path, to have at least an idea how each plugin performs: | ||
normalizePath, | ||
promClient: { collectDefaultMetrics: {} }, | ||
}), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |