Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Remove Fastify and web server #282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ There's a multitude of settings you can use to control the plugin server. Use th
| KAFKA_TRUSTED_CERT_B64 | Kafka trusted CA in Base64 | `null` |
| KAFKA_PRODUCER_MAX_QUEUE_SIZE | Kafka producer queue max size before flushing | `20` |
| KAFKA_FLUSH_FREQUENCY_MS | Kafka producer queue max duration before flushing | `500` |
| DISABLE_WEB | whether to disable web server | `true` |
| WEB_PORT | port for web server to listen on | `3008` |
| WEB_HOSTNAME | hostname for web server to listen on | `'0.0.0.0'` |
| LOG_LEVEL | minimum log level | `LogLevel.Info` |
| SENTRY_DSN | Sentry ingestion URL | `null` |
| STATSD_HOST | StatsD host - integration disabled if this is not provided | `null` |
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@types/lru-cache": "^5.1.0",
"adm-zip": "^0.4.16",
"fast-deep-equal": "^3.1.3",
"fastify": "^3.8.0",
"generic-pool": "^3.7.1",
"hot-shots": "^8.2.1",
"ioredis": "^4.19.2",
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { makePiscina } from './worker/piscina'

type Argv = {
config: string
disableWeb: boolean
webPort: number
webHostname: string
concurrency: number
}

Expand Down
9 changes: 0 additions & 9 deletions src/main/pluginsServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Piscina from '@posthog/piscina'
import * as Sentry from '@sentry/node'
import { FastifyInstance } from 'fastify'
import Redis from 'ioredis'
import * as schedule from 'node-schedule'

Expand All @@ -11,7 +10,6 @@ import { createRedis, delay } from '../shared/utils'
import { PluginsServer, PluginsServerConfig, Queue, ScheduleControl } from '../types'
import { startQueue } from './queue'
import { startSchedule } from './services/schedule'
import { startFastifyInstance, stopFastifyInstance } from './web/server'

const { version } = require('../../package.json')

Expand All @@ -37,7 +35,6 @@ export async function startPluginsServer(

let pubSub: Redis.Redis | undefined
let server: PluginsServer | undefined
let fastifyInstance: FastifyInstance | undefined
let pingJob: schedule.Job | undefined
let statsJob: schedule.Job | undefined
let piscina: Piscina | undefined
Expand All @@ -59,9 +56,6 @@ export async function startPluginsServer(
process.exit()
}
status.info('💤', ' Shutting down gracefully...')
if (fastifyInstance && !serverConfig?.DISABLE_WEB) {
await stopFastifyInstance(fastifyInstance!)
}
await queue?.stop()
await pubSub?.quit()
pingJob && schedule.cancelJob(pingJob)
Expand All @@ -84,9 +78,6 @@ export async function startPluginsServer(
;[server, closeServer] = await createServer(serverConfig, null)

piscina = makePiscina(serverConfig)
if (!server.DISABLE_WEB) {
fastifyInstance = await startFastifyInstance(server)
}

scheduleControl = await startSchedule(server, piscina)
queue = await startQueue(server, piscina)
Expand Down
27 changes: 0 additions & 27 deletions src/main/web/server.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export function getDefaultConfig(): PluginsServerConfig {
REDIS_URL: 'redis://127.0.0.1',
BASE_DIR: '.',
PLUGINS_RELOAD_PUBSUB_CHANNEL: 'reload-plugins',
DISABLE_WEB: true,
WEB_PORT: 3008,
WEB_HOSTNAME: '0.0.0.0',
WORKER_CONCURRENCY: coreCount,
TASK_TIMEOUT: 30,
TASKS_PER_WORKER: 10,
Expand Down Expand Up @@ -63,9 +60,6 @@ export function getConfigHelp(): Record<keyof PluginsServerConfig, string> {
REDIS_URL: 'Redis store URL',
BASE_DIR: 'base path for resolving local plugins',
PLUGINS_RELOAD_PUBSUB_CHANNEL: 'Redis channel for reload events',
DISABLE_WEB: 'whether to disable web server',
WEB_PORT: 'port for web server to listen on',
WEB_HOSTNAME: 'hostname for web server to listen on',
WORKER_CONCURRENCY: 'number of concurrent worker threads',
TASK_TIMEOUT: 'How many seconds until tasks are timed out',
TASKS_PER_WORKER: 'number of parallel tasks per worker thread',
Expand Down
3 changes: 0 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export interface PluginsServerConfig extends Record<string, any> {
REDIS_URL: string
BASE_DIR: string
PLUGINS_RELOAD_PUBSUB_CHANNEL: string
DISABLE_WEB: boolean
WEB_PORT: number
WEB_HOSTNAME: string
LOG_LEVEL: LogLevel
SENTRY_DSN: string | null
STATSD_HOST: string | null
Expand Down
22 changes: 11 additions & 11 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { getDefaultConfig, overrideWithEnv } from '../src/shared/config'
test('overrideWithEnv 1', () => {
const defaultConfig = getDefaultConfig()
const env = {
DISABLE_WEB: 'false',
WEB_PORT: '3008',
WEB_HOSTNAME: '0.0.0.0',
CLICKHOUSE_SECURE: 'false',
TASK_TIMEOUT: '177',
KAFKA_HOSTS: 'example.com',
BASE_DIR: undefined,
}
const config = overrideWithEnv(getDefaultConfig(), env)

expect(config.DISABLE_WEB).toEqual(false)
expect(config.WEB_PORT).toEqual(3008)
expect(config.WEB_HOSTNAME).toEqual('0.0.0.0')
expect(config.BASE_DIR).toEqual(defaultConfig.BASE_DIR)
expect(config.CLICKHOUSE_SECURE).toStrictEqual(false)
expect(config.TASK_TIMEOUT).toStrictEqual(177)
expect(config.KAFKA_HOSTS).toStrictEqual('example.com')
expect(config.BASE_DIR).toStrictEqual(defaultConfig.BASE_DIR)
})

test('overrideWithEnv 2', () => {
const defaultConfig = getDefaultConfig()
const env = {
DISABLE_WEB: '1',
WEB_PORT: '3008.12',
CLICKHOUSE_SECURE: '1',
TASK_TIMEOUT: '4.5',
}
const config = overrideWithEnv(getDefaultConfig(), env)

expect(config.DISABLE_WEB).toEqual(true)
expect(config.WEB_PORT).toEqual(3008.12)
expect(config.CLICKHOUSE_SECURE).toStrictEqual(true)
expect(config.TASK_TIMEOUT).toStrictEqual(4.5)
})
Loading