mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-05 13:02:54 +00:00
feat: added prometheus metrics support
This commit is contained in:
@@ -6,6 +6,7 @@ RUN apk update && \
|
||||
apk upgrade && \
|
||||
apk add openssl && \
|
||||
apk add nginx && \
|
||||
apk add nginx-mod-http-vts && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
ADD . /app
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
import {ConfigFile} from '../src/common';
|
||||
|
||||
const config: ConfigFile = {
|
||||
activeVersions: ['1\\.0\\.\\d+','2\\.0\\.\\d+'],
|
||||
activeVersions: ['1\\.0\\.\\d+', '2\\.0\\.\\d+'],
|
||||
hiddenRoutes: ['/bulk'],
|
||||
metrics: false,
|
||||
outdatedVersions: ['0\\.8\\.\\d+', '0\\.5\\.\\d+', '0\\.6\\.\\d+', '0\\.7\\.\\d+'],
|
||||
output: '/etc/nginx/http.d/default.conf',
|
||||
rateLimitAllowList: ['127.0.0.1/32'],
|
||||
|
||||
7
fixtures/metrics.template
Normal file
7
fixtures/metrics.template
Normal file
@@ -0,0 +1,7 @@
|
||||
server {
|
||||
listen 8080;
|
||||
location /metrics {
|
||||
vhost_traffic_status_display;
|
||||
vhost_traffic_status_display_format prometheus;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
load_module modules/ngx_http_vhost_traffic_status_module.so;
|
||||
|
||||
worker_processes 1;
|
||||
|
||||
error_log stderr;
|
||||
@@ -9,6 +11,7 @@ events {
|
||||
}
|
||||
|
||||
http {
|
||||
vhost_traffic_status_zone;
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
access_log /dev/stdout;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{{{ metrics }}}
|
||||
|
||||
{{{ dockerVersionMap }}}
|
||||
|
||||
# create a custom request limit zone which can handle 160,000 IP-Addresses at the same time
|
||||
|
||||
@@ -59,12 +59,16 @@ export interface ConfigFile {
|
||||
* List of hidden routes
|
||||
*/
|
||||
hiddenRoutes: string[];
|
||||
/**
|
||||
* Enables metrics on /metrics route
|
||||
*/
|
||||
metrics: boolean;
|
||||
/**
|
||||
* List of outdated versions
|
||||
*/
|
||||
outdatedVersions: string[];
|
||||
/**
|
||||
* Output?! TODO
|
||||
* Path the generated config will be written to
|
||||
*/
|
||||
output: string;
|
||||
/**
|
||||
@@ -93,6 +97,10 @@ export interface TemplateView {
|
||||
* Listener
|
||||
*/
|
||||
listener: string;
|
||||
/**
|
||||
* Local server with listener for /metrics route
|
||||
*/
|
||||
metrics: string;
|
||||
/**
|
||||
* Allow list for rate limiting
|
||||
*/
|
||||
|
||||
11
src/main.ts
11
src/main.ts
@@ -241,6 +241,16 @@ ${protocolHardeningParameters}
|
||||
return listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads predefined server entry with metrics location
|
||||
*/
|
||||
export async function generateMetricsServer(enableMetrics: boolean): Promise<string> {
|
||||
if (!enableMetrics) {
|
||||
return '';
|
||||
}
|
||||
return asyncReadFile('./fixtures/metrics.template', 'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a mustache template file with given view object
|
||||
*
|
||||
@@ -300,6 +310,7 @@ export async function getTemplateView(containers: Dockerode.ContainerInfo[]): Pr
|
||||
),
|
||||
hiddenRoutes: (await Promise.all(hiddenRoutesPromises)).join(''),
|
||||
listener: generateListener(configFile.sslFilePaths),
|
||||
metrics: await generateMetricsServer(configFile.metrics),
|
||||
rateLimitAllowList: generateRateLimitAllowList(configFile.rateLimitAllowList),
|
||||
staticRoute: await renderTemplate(path.join('fixtures', 'staticRoute.template'), {cors}),
|
||||
visibleRoutes: (await Promise.all(visibleRoutesPromises)).join(''),
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
getGatewayOfStAppsBackend,
|
||||
getTemplateView,
|
||||
generateListener,
|
||||
generateMetricsServer,
|
||||
getContainers,
|
||||
} from '../src/main';
|
||||
import {resolve} from 'path';
|
||||
@@ -399,6 +400,16 @@ Please check if docker is running and Node.js can access the docker socket (/var
|
||||
return true;
|
||||
}
|
||||
|
||||
@test
|
||||
async 'include metrics config'() {
|
||||
expect(await generateMetricsServer(true)).length.to.be.greaterThan(1);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'omit metrics config'() {
|
||||
expect(await generateMetricsServer(false)).to.equal('');
|
||||
}
|
||||
|
||||
@test
|
||||
'create listener faulty config'() {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user