mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-26 06:17:21 +02:00
Some checks failed
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (22.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (24.14.1) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (25.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Lint (push) Has been cancelled
CI: Master (Build, Test, Lint) / Performance (push) Has been cancelled
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Prepare Docker (coverage) (push) Has been cancelled
Util: Update Node Popularity / approve-and-automerge (push) Has been cancelled
Test: E2E Coverage Weekly / E2E (coverage) (push) Has been cancelled
Test: E2E Coverage Weekly / Aggregate Coverage (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (beta) (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (stable) (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (v1) (push) Has been cancelled
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { GenericContainer, Wait } from 'testcontainers';
|
|
import type { StartedNetwork } from 'testcontainers';
|
|
|
|
import { TEST_CONTAINER_IMAGES } from '../test-containers';
|
|
import type { PostgresResult } from './postgres';
|
|
import type { Service, ServiceResult, StartContext } from './types';
|
|
|
|
const HOSTNAME = 'postgres-exporter';
|
|
export const EXPORTER_PORT = 9187;
|
|
|
|
export interface PostgresExporterMeta {
|
|
host: string;
|
|
port: number;
|
|
}
|
|
|
|
export type PostgresExporterResult = ServiceResult<PostgresExporterMeta>;
|
|
|
|
/**
|
|
* Postgres-internal stats exposed as Prometheus metrics for VictoriaMetrics.
|
|
* Opt-in via `config.services.postgresExporter` — only useful for benchmarks.
|
|
*/
|
|
export const postgresExporter: Service<PostgresExporterResult> = {
|
|
description: 'Postgres Exporter',
|
|
dependsOn: ['postgres'],
|
|
|
|
async start(
|
|
network: StartedNetwork,
|
|
projectName: string,
|
|
_options?: unknown,
|
|
ctx?: StartContext,
|
|
): Promise<PostgresExporterResult> {
|
|
const pgResult = ctx?.serviceResults.postgres as PostgresResult | undefined;
|
|
if (!pgResult) {
|
|
throw new Error('Postgres service must start before postgres-exporter');
|
|
}
|
|
|
|
const { username, password, database } = pgResult.meta;
|
|
const dsn = `postgresql://${username}:${password}@postgres:5432/${database}?sslmode=disable`;
|
|
|
|
const container = await new GenericContainer(TEST_CONTAINER_IMAGES.postgresExporter)
|
|
.withName(`${projectName}-${HOSTNAME}`)
|
|
.withNetwork(network)
|
|
.withNetworkAliases(HOSTNAME)
|
|
.withLabels({
|
|
'com.docker.compose.project': projectName,
|
|
'com.docker.compose.service': HOSTNAME,
|
|
})
|
|
.withEnvironment({
|
|
DATA_SOURCE_NAME: dsn,
|
|
})
|
|
.withExposedPorts(EXPORTER_PORT)
|
|
// stat_bgwriter collector is off by default in v0.17.x.
|
|
.withCommand(['--collector.stat_bgwriter'])
|
|
.withWaitStrategy(
|
|
Wait.forHttp('/metrics', EXPORTER_PORT).forStatusCode(200).withStartupTimeout(30000),
|
|
)
|
|
.withReuse()
|
|
.start();
|
|
|
|
return {
|
|
container,
|
|
meta: {
|
|
host: HOSTNAME,
|
|
port: EXPORTER_PORT,
|
|
},
|
|
};
|
|
},
|
|
};
|