mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
refactor(server): telemetry ports env (#13560)
This commit is contained in:
parent
0eabb3ef80
commit
c8f672f494
6 changed files with 80 additions and 18 deletions
|
@ -29,6 +29,11 @@ export interface EnvData {
|
||||||
thirdPartySupportUrl?: string;
|
thirdPartySupportUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bull: {
|
||||||
|
config: QueueOptions;
|
||||||
|
queues: RegisterQueueOptions[];
|
||||||
|
};
|
||||||
|
|
||||||
database: {
|
database: {
|
||||||
url?: string;
|
url?: string;
|
||||||
host: string;
|
host: string;
|
||||||
|
@ -45,6 +50,10 @@ export interface EnvData {
|
||||||
server: string;
|
server: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
network: {
|
||||||
|
trustedProxies: string[];
|
||||||
|
};
|
||||||
|
|
||||||
resourcePaths: {
|
resourcePaths: {
|
||||||
lockFile: string;
|
lockFile: string;
|
||||||
geodata: {
|
geodata: {
|
||||||
|
@ -62,9 +71,9 @@ export interface EnvData {
|
||||||
|
|
||||||
redis: RedisOptions;
|
redis: RedisOptions;
|
||||||
|
|
||||||
bull: {
|
telemetry: {
|
||||||
config: QueueOptions;
|
apiPort: number;
|
||||||
queues: RegisterQueueOptions[];
|
microservicesPort: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
storage: {
|
storage: {
|
||||||
|
|
|
@ -9,6 +9,9 @@ const resetEnv = () => {
|
||||||
for (const env of [
|
for (const env of [
|
||||||
'IMMICH_WORKERS_INCLUDE',
|
'IMMICH_WORKERS_INCLUDE',
|
||||||
'IMMICH_WORKERS_EXCLUDE',
|
'IMMICH_WORKERS_EXCLUDE',
|
||||||
|
'IMMICH_TRUSTED_PROXIES',
|
||||||
|
'IMMICH_API_METRICS_PORT',
|
||||||
|
'IMMICH_MICROSERVICES_METRICS_PORT',
|
||||||
|
|
||||||
'DB_URL',
|
'DB_URL',
|
||||||
'DB_HOSTNAME',
|
'DB_HOSTNAME',
|
||||||
|
@ -178,4 +181,41 @@ describe('getEnv', () => {
|
||||||
expect(getEnv).toThrowError('Invalid worker(s) found: api,microservices,randomservice');
|
expect(getEnv).toThrowError('Invalid worker(s) found: api,microservices,randomservice');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('network', () => {
|
||||||
|
it('should return default network options', () => {
|
||||||
|
const { network } = getEnv();
|
||||||
|
expect(network).toEqual({
|
||||||
|
trustedProxies: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse trusted proxies', () => {
|
||||||
|
process.env.IMMICH_TRUSTED_PROXIES = '10.1.0.0,10.2.0.0, 169.254.0.0/16';
|
||||||
|
const { network } = getEnv();
|
||||||
|
expect(network).toEqual({
|
||||||
|
trustedProxies: ['10.1.0.0', '10.2.0.0', '169.254.0.0/16'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('telemetry', () => {
|
||||||
|
it('should return default ports', () => {
|
||||||
|
const { telemetry } = getEnv();
|
||||||
|
expect(telemetry).toEqual({
|
||||||
|
apiPort: 8081,
|
||||||
|
microservicesPort: 8082,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse custom ports', () => {
|
||||||
|
process.env.IMMICH_API_METRICS_PORT = '2001';
|
||||||
|
process.env.IMMICH_MICROSERVICES_METRICS_PORT = '2002';
|
||||||
|
const { telemetry } = getEnv();
|
||||||
|
expect(telemetry).toEqual({
|
||||||
|
apiPort: 2001,
|
||||||
|
microservicesPort: 2002,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -117,6 +117,13 @@ const getEnv = (): EnvData => {
|
||||||
|
|
||||||
licensePublicKey: isProd ? productionKeys : stagingKeys,
|
licensePublicKey: isProd ? productionKeys : stagingKeys,
|
||||||
|
|
||||||
|
network: {
|
||||||
|
trustedProxies: (process.env.IMMICH_TRUSTED_PROXIES ?? '')
|
||||||
|
.split(',')
|
||||||
|
.map((value) => value.trim())
|
||||||
|
.filter(Boolean),
|
||||||
|
},
|
||||||
|
|
||||||
redis: redisConfig,
|
redis: redisConfig,
|
||||||
|
|
||||||
resourcePaths: {
|
resourcePaths: {
|
||||||
|
@ -138,6 +145,11 @@ const getEnv = (): EnvData => {
|
||||||
ignoreMountCheckErrors: process.env.IMMICH_IGNORE_MOUNT_CHECK_ERRORS === 'true',
|
ignoreMountCheckErrors: process.env.IMMICH_IGNORE_MOUNT_CHECK_ERRORS === 'true',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
telemetry: {
|
||||||
|
apiPort: Number(process.env.IMMICH_API_METRICS_PORT || '') || 8081,
|
||||||
|
microservicesPort: Number(process.env.IMMICH_MICROSERVICES_METRICS_PORT || '') || 8082,
|
||||||
|
},
|
||||||
|
|
||||||
workers,
|
workers,
|
||||||
|
|
||||||
noColor: !!process.env.NO_COLOR,
|
noColor: !!process.env.NO_COLOR,
|
||||||
|
|
|
@ -10,25 +10,17 @@ import { ImmichEnvironment } from 'src/enum';
|
||||||
import { IConfigRepository } from 'src/interfaces/config.interface';
|
import { IConfigRepository } from 'src/interfaces/config.interface';
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
||||||
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||||
import { ApiService } from 'src/services/api.service';
|
import { ApiService } from 'src/services/api.service';
|
||||||
import { isStartUpError } from 'src/services/storage.service';
|
import { isStartUpError } from 'src/services/storage.service';
|
||||||
import { otelStart } from 'src/utils/instrumentation';
|
import { otelStart } from 'src/utils/instrumentation';
|
||||||
import { useSwagger } from 'src/utils/misc';
|
import { useSwagger } from 'src/utils/misc';
|
||||||
|
|
||||||
function parseTrustedProxy(input?: string) {
|
|
||||||
if (!input) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
// Split on ',' char to allow multiple IPs
|
|
||||||
return input.split(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
process.title = 'immich-api';
|
process.title = 'immich-api';
|
||||||
const otelPort = Number.parseInt(process.env.IMMICH_API_METRICS_PORT ?? '8081');
|
|
||||||
const trustedProxies = parseTrustedProxy(process.env.IMMICH_TRUSTED_PROXIES ?? '');
|
|
||||||
|
|
||||||
otelStart(otelPort);
|
const { telemetry, network } = new ConfigRepository().getEnv();
|
||||||
|
otelStart(telemetry.apiPort);
|
||||||
|
|
||||||
const app = await NestFactory.create<NestExpressApplication>(ApiModule, { bufferLogs: true });
|
const app = await NestFactory.create<NestExpressApplication>(ApiModule, { bufferLogs: true });
|
||||||
const logger = await app.resolve<ILoggerRepository>(ILoggerRepository);
|
const logger = await app.resolve<ILoggerRepository>(ILoggerRepository);
|
||||||
|
@ -39,7 +31,7 @@ async function bootstrap() {
|
||||||
|
|
||||||
logger.setContext('Bootstrap');
|
logger.setContext('Bootstrap');
|
||||||
app.useLogger(logger);
|
app.useLogger(logger);
|
||||||
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal', ...trustedProxies]);
|
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal', ...network.trustedProxies]);
|
||||||
app.set('etag', 'strong');
|
app.set('etag', 'strong');
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(json({ limit: '10mb' }));
|
app.use(json({ limit: '10mb' }));
|
||||||
|
|
|
@ -5,13 +5,13 @@ import { serverVersion } from 'src/constants';
|
||||||
import { IConfigRepository } from 'src/interfaces/config.interface';
|
import { IConfigRepository } from 'src/interfaces/config.interface';
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
||||||
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||||
import { isStartUpError } from 'src/services/storage.service';
|
import { isStartUpError } from 'src/services/storage.service';
|
||||||
import { otelStart } from 'src/utils/instrumentation';
|
import { otelStart } from 'src/utils/instrumentation';
|
||||||
|
|
||||||
export async function bootstrap() {
|
export async function bootstrap() {
|
||||||
const otelPort = Number.parseInt(process.env.IMMICH_MICROSERVICES_METRICS_PORT ?? '8082');
|
const { telemetry } = new ConfigRepository().getEnv();
|
||||||
|
otelStart(telemetry.microservicesPort);
|
||||||
otelStart(otelPort);
|
|
||||||
|
|
||||||
const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true });
|
const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true });
|
||||||
const logger = await app.resolve(ILoggerRepository);
|
const logger = await app.resolve(ILoggerRepository);
|
||||||
|
|
|
@ -31,6 +31,10 @@ const envData: EnvData = {
|
||||||
server: 'server-public-key',
|
server: 'server-public-key',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
network: {
|
||||||
|
trustedProxies: [],
|
||||||
|
},
|
||||||
|
|
||||||
redis: {
|
redis: {
|
||||||
host: 'redis',
|
host: 'redis',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
|
@ -56,6 +60,11 @@ const envData: EnvData = {
|
||||||
ignoreMountCheckErrors: false,
|
ignoreMountCheckErrors: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
telemetry: {
|
||||||
|
apiPort: 8081,
|
||||||
|
microservicesPort: 8082,
|
||||||
|
},
|
||||||
|
|
||||||
workers: [ImmichWorker.API, ImmichWorker.MICROSERVICES],
|
workers: [ImmichWorker.API, ImmichWorker.MICROSERVICES],
|
||||||
|
|
||||||
noColor: false,
|
noColor: false,
|
||||||
|
|
Loading…
Reference in a new issue