-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This results in some complications. See the README and the new `main.js` entrypoint.
- Loading branch information
Showing
15 changed files
with
303 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
FROM node:18-slim as app-builder | ||
FROM node:20-slim as app-builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN npm install \ | ||
&& npm run build \ | ||
&& npm install --omit=dev | ||
|
||
FROM gcr.io/distroless/nodejs18-debian11 | ||
FROM gcr.io/distroless/nodejs20-debian12 | ||
WORKDIR /app | ||
COPY package.json . | ||
COPY main.js . | ||
COPY --from=app-builder /app/build build | ||
COPY --from=app-builder /app/node_modules node_modules | ||
ENTRYPOINT ["/nodejs/bin/node", "build"] | ||
ENTRYPOINT ["/nodejs/bin/node", "main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
!tailwind.config.js | ||
!vite.config.ts | ||
!demo/Dockerfile.neogrok* | ||
!main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// This is the main "production" entrypoint into neogrok. It wraps the SvelteKit | ||
// server to do some additional things. Note that the vite dev server used by | ||
// SvelteKit bypasses this module entirely, as it's a fundamentally different | ||
// entrypoint. | ||
// | ||
// See https://kit.svelte.dev/docs/adapter-node#custom-server for details. | ||
|
||
import { createServer } from "node:http"; | ||
import { register } from "prom-client"; | ||
import { handler } from "./build/handler.js"; | ||
import { env } from "./build/env.js"; | ||
|
||
// These are copied straight out of the default SvelteKit entrypoint. | ||
const path = env("SOCKET_PATH", false); | ||
const host = env("HOST", "0.0.0.0"); | ||
const port = env("PORT", !path && "3000"); | ||
|
||
const abortController = new AbortController(); | ||
// The default SvelteKit node server does not handle standard "well-behaved http | ||
// server signals". | ||
process.once("SIGTERM", () => { | ||
console.log( | ||
"Received SIGTERM, draining connections in an attempt to gracefully shut down...", | ||
); | ||
abortController.abort(); | ||
}); | ||
process.once("SIGINT", () => { | ||
console.log( | ||
"Received SIGINT, draining connections in an attempt to gracefully shut down...", | ||
); | ||
abortController.abort(); | ||
}); | ||
|
||
// @ts-expect-error the polka handler has an additional `next` property that is | ||
// not actually used by the implementation. | ||
const server = createServer(handler); | ||
server.listen({ host, port, path, signal: abortController.signal }, () => { | ||
console.log(`Listening on ${path ? path : host + ":" + port}`); | ||
}); | ||
|
||
// Support binding a prometheus /metrics server on a different port/path, so | ||
// that it is not exposed on the site. | ||
const promPath = env("PROMETHEUS_SOCKET_PATH", false); | ||
const promHost = env("PROMETHEUS_HOST", "0.0.0.0"); | ||
const promPort = env("PROMETHEUS_PORT", false); | ||
if (promPort && promPort === port) { | ||
throw new Error( | ||
`PROMETHEUS_PORT ${promPort} cannot be the same as PORT ${port}`, | ||
); | ||
} | ||
if (promPath && promPath === path) { | ||
throw new Error( | ||
`PROMETHEUS_SOCKET_PATH ${promPath} cannot be the same as SOCKET_PATH ${path}`, | ||
); | ||
} | ||
if (promPort || promPath) { | ||
const promServer = createServer((req, res) => { | ||
if (req.method === "GET" && req.url?.endsWith("/metrics")) { | ||
res.statusCode = 200; | ||
res.setHeader("content-type", register.contentType); | ||
register.metrics().then( | ||
(body) => res.end(body), | ||
(err) => { | ||
console.error("failed to generate prometheus /metrics response", err); | ||
res.writeHead(500, "Internal Server Error"); | ||
res.end(); | ||
}, | ||
); | ||
} else { | ||
res.writeHead(404, "Not found"); | ||
res.end("Not found"); | ||
} | ||
}); | ||
promServer.listen( | ||
{ | ||
host: promHost, | ||
port: promPort, | ||
path: promPath, | ||
signal: abortController.signal, | ||
}, | ||
() => { | ||
console.log( | ||
`Prometheus listening on ${ | ||
promPath ? promPath : promHost + ":" + promPort | ||
}`, | ||
); | ||
}, | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { dev } from "$app/environment"; | ||
import { | ||
Counter, | ||
Gauge, | ||
collectDefaultMetrics, | ||
Registry, | ||
register, | ||
} from "prom-client"; | ||
|
||
// The global registry persists across HMR reloads of this module, throwing on | ||
// every reload due to duplicate names. So, in dev, use a registry scoped to | ||
// this module. In prod, we can't do that as the entrypoint to the application, | ||
// which mounts the prom /metrics server there, can't import from sveltekit | ||
// application chunks. Thankfully, there is no HMR in prod, so we can just use | ||
// the global registry in that case. | ||
export const registry = dev ? new Registry() : register; | ||
|
||
collectDefaultMetrics({ register: registry }); | ||
export const zoektRequestCount = new Counter({ | ||
name: "zoekt_http_requests_total", | ||
help: "Count of http requests made to zoekt", | ||
labelNames: ["path", "status"], | ||
registers: [registry], | ||
}); | ||
export const zoektRequestDuration = new Counter({ | ||
name: "zoekt_http_request_seconds_total", | ||
help: "Duration of http requests made to zoekt", | ||
labelNames: ["path", "status"], | ||
registers: [registry], | ||
}); | ||
export const zoektRequestConcurrency = new Gauge({ | ||
name: "zoekt_http_requests", | ||
help: "Gauge of concurrent requests being made to zoekt", | ||
labelNames: ["path"], | ||
registers: [registry], | ||
}); | ||
|
||
export const neogrokRequestCount = new Counter({ | ||
name: "neogrok_http_requests_total", | ||
help: "Count of http requests handled by neogrok", | ||
labelNames: ["route", "status"], | ||
registers: [registry], | ||
}); | ||
export const neogrokRequestDuration = new Counter({ | ||
name: "neogrok_http_request_seconds_total", | ||
help: "Duration of http requests handled by neogrok", | ||
labelNames: ["route", "status"], | ||
registers: [registry], | ||
}); | ||
export const neogrokRequestConcurrency = new Gauge({ | ||
name: "neogrok_http_requests", | ||
help: "Gauge of concurrent requests being handled by neogrok", | ||
labelNames: ["route"], | ||
registers: [registry], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.