Skip to content

Commit

Permalink
chore: stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
microwavekonijn committed Sep 25, 2023
1 parent 9677475 commit 9fef9e4
Show file tree
Hide file tree
Showing 24 changed files with 1,532 additions and 1,241 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ yarn-error.log
/.nyc_output
/packages/graphql
build/config\.gypi

# data
/data
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# syntax=docker/dockerfile:1

# Workspace
FROM node:20-alpine as workspace

WORKDIR /workspace
Expand All @@ -15,23 +16,25 @@ COPY . .

RUN pnpm -r i --frozen-lockfile --offline --silent

# Builds app
FROM workspace as build-default

ARG APP_NAME

RUN pnpm nx build $APP_NAME
RUN pnpm -F $APP_NAME --prod deploy /app

FROM node:20-alpine
# Release app(default template)
FROM node:20-alpine as release-default

WORKDIR /app

COPY --from=workspace /app .
COPY --from=build-default /app .

ENV APP_PORT 3000

EXPOSE $APP_PORT

CMD ["node", "dist/main"]
ENTRYPOINT ["node", "dist/main"]

HEALTHCHECK --interval=12s --timeout=12s --start-period=30s \
CMD wget --no-verbose --tries=1 --spider http://localhost:$APP_PORT/health || exit 1

22 changes: 11 additions & 11 deletions apps/stream-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
"dependencies": {
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/common": "^10.2.4",
"@nestjs/config": "^3.0.1",
"@nestjs/core": "^10.2.4",
"@nestjs/microservices": "^10.2.4",
"@nestjs/platform-fastify": "^10.2.4",
"@nestjs/terminus": "^10.0.1",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/microservices": "^10.2.5",
"@nestjs/platform-fastify": "^10.2.5",
"@nestjs/terminus": "^10.1.1",
"@nss/ess-concerns": "workspace:*",
"@nss/utils": "workspace:*",
"@willsoto/nestjs-prometheus": "^5.3.0",
"@willsoto/nestjs-prometheus": "^5.5.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"cache-manager": "^5.2.3",
Expand All @@ -40,12 +40,12 @@
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/amqplib": "^0.10.1",
"@types/node": "^20.5.9",
"@types/node": "^20.6.2",
"@types/validator": "^13.11.1",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
Expand Down
5 changes: 3 additions & 2 deletions apps/stream-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { ServiceTrackerModule } from './service-tracker/service-tracker.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { config } from './config';
import { PrometheusModule } from '@willsoto/nestjs-prometheus';
import { Logger, LoggerModule } from '@nss/utils';
import { envSplit, Logger, LoggerModule } from '@nss/utils';
import { CacheModule } from '@nestjs/cache-manager';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
expandVariables: true,
envFilePath: envSplit('ENV_PATHS', ['.env']),
load: [config],
}),
LoggerModule.forRootAsync({
Expand All @@ -23,7 +24,7 @@ import { CacheModule } from '@nestjs/cache-manager';
}),
inject: [ConfigService],
}),
PrometheusModule.register(),
PrometheusModule.register({ global: true }),
CacheModule.register({ isGlobal: true }),
RecentCharactersModule,
ServiceTrackerModule,
Expand Down
5 changes: 4 additions & 1 deletion apps/stream-api/src/census/factories/stream.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export class StreamFactory {
constructor(private readonly config: ConfigService) {}

createStream(environment: PS2Environment): CensusClient {
return new CensusClient(this.config.get('ess.serviceId'), environment);
return new CensusClient(
this.config.getOrThrow('ess.serviceId'),
environment,
);
}
}
26 changes: 13 additions & 13 deletions apps/stream-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
},
"dependencies": {
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/common": "^10.2.4",
"@nestjs/config": "^3.0.1",
"@nestjs/core": "^10.2.4",
"@nestjs/microservices": "^10.2.4",
"@nestjs/platform-fastify": "^10.2.4",
"@nestjs/terminus": "^10.0.1",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/microservices": "^10.2.5",
"@nestjs/platform-fastify": "^10.2.5",
"@nestjs/terminus": "^10.1.1",
"@nss/utils": "workspace:*",
"@willsoto/nestjs-prometheus": "^5.3.0",
"@willsoto/nestjs-prometheus": "^5.5.0",
"axios": "^1.5.0",
"bcryptjs": "^2.4.3",
"cache-manager": "^5.2.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"fastify": "^4.22.2",
"fastify": "^4.23.2",
"ioredis": "^5.3.2",
"prom-client": "^14.2.0",
"reflect-metadata": "^0.1.13",
Expand All @@ -37,12 +37,12 @@
},
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/bcryptjs": "^2.4.3",
"@types/node": "^20.5.9",
"@types/bcryptjs": "^2.4.4",
"@types/node": "^20.6.2",
"@types/validator": "^13.11.1",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
Expand Down
5 changes: 3 additions & 2 deletions apps/stream-auth/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AuthModule } from './auth/auth.module';
import { HealthModule } from './health/health.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { config } from './config';
import { LoggerModule } from '@nss/utils';
import { envSplit, LoggerModule } from '@nss/utils';
import { PrometheusModule } from '@willsoto/nestjs-prometheus';
import { CacheModule } from '@nestjs/cache-manager';

Expand All @@ -12,6 +12,7 @@ import { CacheModule } from '@nestjs/cache-manager';
ConfigModule.forRoot({
isGlobal: true,
expandVariables: true,
envFilePath: envSplit('ENV_PATHS', ['.env']),
load: [config],
}),
LoggerModule.forRootAsync({
Expand All @@ -22,7 +23,7 @@ import { CacheModule } from '@nestjs/cache-manager';
}),
inject: [ConfigService],
}),
PrometheusModule.register(),
PrometheusModule.register({ global: true }),
CacheModule.register({ isGlobal: true }),
AuthModule,
HealthModule,
Expand Down
22 changes: 11 additions & 11 deletions apps/stream-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"start": "node dist/main"
},
"dependencies": {
"@nestjs/common": "^10.2.4",
"@nestjs/config": "^3.0.1",
"@nestjs/core": "^10.2.4",
"@nestjs/microservices": "^10.2.4",
"@nestjs/platform-fastify": "^10.2.4",
"@nestjs/terminus": "^10.0.1",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/microservices": "^10.2.5",
"@nestjs/platform-fastify": "^10.2.5",
"@nestjs/terminus": "^10.1.1",
"@nss/ess-concerns": "workspace:*",
"@nss/rabbitmq": "workspace:*",
"@nss/utils": "workspace:*",
"@willsoto/nestjs-prometheus": "^5.3.0",
"@willsoto/nestjs-prometheus": "^5.5.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"prom-client": "^14.2.0",
Expand All @@ -38,12 +38,12 @@
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/amqplib": "^0.10.1",
"@types/node": "^20.5.9",
"@types/node": "^20.6.2",
"@types/validator": "^13.11.1",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
Expand Down
5 changes: 3 additions & 2 deletions apps/stream-collector/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { config } from './config';
import { PublisherModule } from './publisher/publisher.module';
import { PrometheusModule } from '@willsoto/nestjs-prometheus';
import { Logger, LoggerModule } from '@nss/utils';
import { envSplit, Logger, LoggerModule } from '@nss/utils';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
expandVariables: true,
envFilePath: envSplit('ENV_PATHS', ['.env']),
load: [config],
}),
LoggerModule.forRootAsync({
Expand All @@ -21,7 +22,7 @@ import { Logger, LoggerModule } from '@nss/utils';
}),
inject: [ConfigService],
}),
PrometheusModule.register(),
PrometheusModule.register({ global: true }),
HealthModule,
PublisherModule,
],
Expand Down
9 changes: 8 additions & 1 deletion apps/stream-collector/src/census/census.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CensusMetricsService } from './services/census-metrics.service';
import { StreamClientFactory } from './factories/stream-client.factory';
import { Stream } from 'ps2census';
import {
essConnectionClockOffsetSeconds,
essConnectionHeartbeatOffsetSeconds,
essConnectionStartTimeSeconds,
essConnectionStateCount,
Expand Down Expand Up @@ -74,7 +75,7 @@ import { EssAdapter } from './adapters/ess.adapter';
useFactory: (factory: StreamClientFactory, config: ConfigService) =>
Object.freeze(
config
.get('ess.serviceIds')
.getOrThrow('ess.serviceIds')
.map((serviceId) => factory.create(serviceId)),
),
inject: [StreamClientFactory, ConfigService],
Expand Down Expand Up @@ -128,6 +129,12 @@ import { EssAdapter } from './adapters/ess.adapter';
help: 'Counter that tracks how many times a subscription to a connection has been altered',
labelNames: ['connection'],
}),

makeGaugeProvider({
name: essConnectionClockOffsetSeconds,
help: 'Clock offset between ess and system',
labelNames: ['connection'],
}),
],
exports: [CONNECTIONS, StreamIndicator],
})
Expand Down
28 changes: 14 additions & 14 deletions apps/stream-manifold/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
"start": "node dist/main"
},
"dependencies": {
"@nestjs/common": "^10.2.4",
"@nestjs/config": "^3.0.1",
"@nestjs/core": "^10.2.4",
"@nestjs/microservices": "^10.2.4",
"@nestjs/platform-fastify": "^10.2.4",
"@nestjs/platform-ws": "^10.2.4",
"@nestjs/terminus": "^10.0.1",
"@nestjs/websockets": "^10.2.4",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/microservices": "^10.2.5",
"@nestjs/platform-fastify": "^10.2.5",
"@nestjs/platform-ws": "^10.2.5",
"@nestjs/terminus": "^10.1.1",
"@nestjs/websockets": "^10.2.5",
"@nss/ess-concerns": "workspace:*",
"@nss/rabbitmq": "workspace:*",
"@nss/utils": "workspace:*",
"@willsoto/nestjs-prometheus": "^5.3.0",
"@willsoto/nestjs-prometheus": "^5.5.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"class-transformer": "^0.5.1",
Expand All @@ -37,21 +37,21 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"ws": "^8.13.0"
"ws": "^8.14.1"
},
"optionalDependencies": {
"bufferutil": "^4.0.7"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/amqplib": "^0.10.1",
"@types/node": "^20.5.9",
"@types/node": "^20.6.2",
"@types/supertest": "^2.0.12",
"@types/validator": "^13.11.1",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
Expand Down
5 changes: 3 additions & 2 deletions apps/stream-manifold/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { config } from './config';
import { PrometheusModule } from '@willsoto/nestjs-prometheus';
import { RabbitMqModule } from '@nss/rabbitmq';
import { LoggerModule } from '@nss/utils';
import { envSplit, LoggerModule } from '@nss/utils';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
expandVariables: true,
envFilePath: envSplit('ENV_PATHS', ['.env']),
load: [config],
}),
LoggerModule.forRootAsync({
Expand All @@ -22,7 +23,7 @@ import { LoggerModule } from '@nss/utils';
}),
inject: [ConfigService],
}),
PrometheusModule.register(),
PrometheusModule.register({ global: true }),
RabbitMqModule.forRootAsync({
global: true,
useFactory: (config: ConfigService) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export class StreamChannelFactory {
create(): ChannelWrapper {
return this.rabbit.createChannel({
setup: async (channel: Channel) => {
const { queue } = await channel.assertQueue(null, {
const { queue } = await channel.assertQueue('', {
exclusive: true,
});

await Promise.all([
channel.bindQueue(
queue,
this.config.get('rabbitmq.streamExchangeName'),
null,
'',
),
channel.consume(queue, (message) =>
this.handleMessage(message, channel),
Expand Down
4 changes: 4 additions & 0 deletions apps/stream-manifold/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ async function bootstrap() {
app.flushLogs();
app.useWebSocketAdapter(new WsAdapter(app));
app.enableShutdownHooks();
// Mimics the behaviour of ESS on http
app.useGlobalFilters({
catch() {},
});

process.on('uncaughtException', (err) => {
logger.error(err, 'UncaughtException');
Expand Down
Loading

0 comments on commit 9fef9e4

Please sign in to comment.