mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: add support for log aggregators
This commit is contained in:
@@ -47,6 +47,20 @@ export interface SSLFilePaths {
|
||||
dhparam: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported log formats for config
|
||||
*/
|
||||
type SupportedLogFormatsKeys = 'default' | 'combined' | 'json';
|
||||
|
||||
/**
|
||||
* Map supported formats to stings used in template view
|
||||
*/
|
||||
export const SupportedLogFormats: {[key in SupportedLogFormatsKeys]: string} = {
|
||||
default: 'combined',
|
||||
combined: 'combined',
|
||||
json: 'json',
|
||||
};
|
||||
|
||||
/**
|
||||
* A representation of the config file
|
||||
*/
|
||||
@@ -59,10 +73,14 @@ export interface ConfigFile {
|
||||
* List of hidden routes
|
||||
*/
|
||||
hiddenRoutes: string[];
|
||||
/**
|
||||
* Sets log format (default or json)
|
||||
*/
|
||||
logFormat: SupportedLogFormatsKeys;
|
||||
/**
|
||||
* Enables metrics on /metrics route
|
||||
*/
|
||||
metrics: boolean;
|
||||
metrics?: boolean;
|
||||
/**
|
||||
* List of outdated versions
|
||||
*/
|
||||
@@ -97,6 +115,14 @@ export interface TemplateView {
|
||||
* Listener
|
||||
*/
|
||||
listener: string;
|
||||
/**
|
||||
* Log format to use
|
||||
*/
|
||||
logFormat: string;
|
||||
/**
|
||||
* Custom Log formatters
|
||||
*/
|
||||
logFormatters: string;
|
||||
/**
|
||||
* Local server with listener for /metrics route
|
||||
*/
|
||||
|
||||
19
src/main.ts
19
src/main.ts
@@ -26,6 +26,7 @@ import {
|
||||
protocolHardeningParameters,
|
||||
SSLFilePaths,
|
||||
sslHardeningParameters,
|
||||
SupportedLogFormats,
|
||||
TemplateView,
|
||||
} from './common';
|
||||
|
||||
@@ -244,11 +245,14 @@ ${protocolHardeningParameters}
|
||||
/**
|
||||
* Reads predefined server entry with metrics location
|
||||
*/
|
||||
export async function generateMetricsServer(enableMetrics: boolean): Promise<string> {
|
||||
export async function generateMetricsServer(logFormat: string, enableMetrics?: boolean): Promise<string> {
|
||||
if (!enableMetrics) {
|
||||
return '';
|
||||
}
|
||||
return asyncReadFile('./fixtures/metrics.template', 'utf8');
|
||||
|
||||
return renderTemplate(path.join('fixtures', 'metrics.template'), {
|
||||
logFormat: logFormat,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,6 +306,13 @@ export async function getTemplateView(containers: Dockerode.ContainerInfo[]): Pr
|
||||
});
|
||||
});
|
||||
|
||||
const logFormattingPromise = renderTemplate(path.join('fixtures', 'logFormatters.template'), {});
|
||||
|
||||
const logFormat =
|
||||
configFile.logFormat in SupportedLogFormats
|
||||
? SupportedLogFormats[configFile.logFormat]
|
||||
: SupportedLogFormats.default;
|
||||
|
||||
return {
|
||||
dockerVersionMap: await generateUpstreamMap(
|
||||
configFile.activeVersions,
|
||||
@@ -310,7 +321,9 @@ export async function getTemplateView(containers: Dockerode.ContainerInfo[]): Pr
|
||||
),
|
||||
hiddenRoutes: (await Promise.all(hiddenRoutesPromises)).join(''),
|
||||
listener: generateListener(configFile.sslFilePaths),
|
||||
metrics: await generateMetricsServer(configFile.metrics),
|
||||
logFormat: logFormat,
|
||||
logFormatters: await logFormattingPromise,
|
||||
metrics: await generateMetricsServer(logFormat, configFile.metrics),
|
||||
rateLimitAllowList: generateRateLimitAllowList(configFile.rateLimitAllowList),
|
||||
staticRoute: await renderTemplate(path.join('fixtures', 'staticRoute.template'), {cors}),
|
||||
visibleRoutes: (await Promise.all(visibleRoutesPromises)).join(''),
|
||||
|
||||
Reference in New Issue
Block a user