~bigbes/core-go

ref: c2c2f3848fa9a88d96952ff08f886483f8b9d1f7 core-go/server/server.go -rw-r--r-- 13.4 KiB
ff38670c — Conrad Hoffmann 3 months ago
server: add health endpoint to metrics listener

There are already facilities to run the metrics listener on a fixed
port, so this makes for a useful endpoint to have metrics and a health
check in Kubernetes without exposing them to the world. In the long run,
I would like to remove the metrics endpoint from the public listener,
but that will take more work.
67e65522 — Simon Martin 4 months ago
server: setup router dedicated to webhook processing

This introduces a new chi router to allow processing (in Go) webhook
calls coming from other SourceHut services.

It ensures that incoming messages are signed with the webhook private
key and if so, provides access both to the database and service
configuration.

Signed-off-by: Simon Martin <simon@nasilyan.com>
bbb9e45c — Conrad Hoffmann 4 months ago
server: support multiple bind addresses
3dc39b67 — Simon Martin 8 months ago
server: support setting build version and date information

This is a pre-requisite to the effort to make this information available
via the GraphQL API.

Co-authored-by: Conrad Hoffmann <ch@bitfehler.net>
Signed-off-by: Simon Martin <simon@nasilyan.com>
77b64d23 — Conrad Hoffmann 9 months ago
server: allow setting ports for metrics, pprof

With an eye towards Kubernetes, it is desirable to avoid having the API
pick random ports for anything. This commit introduces additional flags
for the API server to specify the metrics and pprof ports. This change
is backwards-compatible insofar as the default behavior is preserved if
the flags are not used.

The log output is changed to include the full address that the
respective listeners are listening on.

Note that using "0.0.0.0:1234" might not quite work as expected, because
Go [1]. But that does not change the default behavior, so I guess it's
fine.

[1] https://github.com/golang/go/issues/48723
20be483e — Conrad Hoffmann 9 months ago
Don't uppercase error messages
862728a4 — Drew DeVault 9 months ago
server: add error presenter to make context cancellation semantic
33acd1b0 — Drew DeVault 10 months ago
feature: add submodule + middleware for feature flags
398f1a70 — Conrad Hoffmann 10 months ago
Refactor config loading and server initialization

As is, LoadConfig() does some things that are not strictly related to
the configuration, such as parsing command line arguments. This has led
to a proliferation of different ways to load the config based on various
needs and also prevents tools that need a config but are not services to
use custom command line arguments.

This commit aims to decouple config loading from everything else and
do nothing but loading the config files.

On a high level, this commit:
- renames server.NewServer() to server.New()
- moves config.Debug and config.Addr into the server package
- moves crypto.InitCrypto() call into server.New()
- moves command line parsing into server.New(), using passed-in values
  rather than os.Args

The only changes required for services would be changing

   cfg := config.LoadConfig(":5100")
   server := server.NewServer("meta.sr.ht", cfg)

to

   cfg := config.LoadConfig()
   server := server.New("meta.sr.ht", ":5100", cfg, os.Args)

All other tools will be switched to just LoadConfig() and, optionally, a
call to crypto.InitCrypto(). I managed to completely remove some global
state (addr) and at least make the rest private, so that users are
forced to use the designated functions.

The config module gained support for custom FS implementation, mainly
for testing.
80be9ad7 — Conrad Hoffmann 11 months ago
server: enable GraphQL introspection
e5f2298c — Drew DeVault 1 year, 18 days ago
server: log GraphQL queries if running in debug mode
a8516055 — Conrad Hoffmann 1 year, 26 days ago
server: handle CORS in server

Currently CORS is handled in nginx in front of the API. That setup is
not very suitable for Kubernetes. Instead, handle CORS here, so we do
not need any intermediaries between the ingress and the APIs.

The CORS settings are taken from sr.ht-nginx/graphql.conf [1]

[1] https://git.sr.ht/~sircmpwn/sr.ht-nginx/tree/master/item/graphql.conf
ba01be84 — Conrad Hoffmann 1 year, 1 month ago
server: replace deprecated gqlgen code

Most of the gqlgen/handler package, specifically also
`handler.GraphQL()`, has been deprecated [1]. The documentation of the
new package [2] is a bit lacking, but some stuff is covered in the
reference docs [3] [4], and some in the examples [5].

[1] https://pkg.go.dev/github.com/99designs/gqlgen@v0.17.36/handler#GraphQL
[2] https://pkg.go.dev/github.com/99designs/gqlgen@v0.17.36/graphql/handler
[3] https://gqlgen.com/reference/errors/#the-panic-handler
[4] https://gqlgen.com/reference/complexity/#limiting-query-complexity
[5] https://github.com/99designs/gqlgen/blob/master/_examples/fileupload/server/server.go
bdb0f7e8 — Drew DeVault 1 year, 1 month ago
server: disable logging for release mode

This was partially implemented a while ago but we missed the main point
where it matters.
79dad627 — Drew DeVault 1 year, 4 months ago
server: add pprof endpoint

This adds a pprof endpoint to all SourceHut APIs. It picks an
OS-assigned port on localhost to run it on and prints this port to
stdout. This ensures a unique port is selected even if several APIs are
running on a single host.
0bea6849 — Drew DeVault 1 year, 5 months ago
server: enable request logging only in debug mode

To improve the signal:noise ratio in the production logs.
redis: avoid building UniversalOptions for standard mode

This makes it support all options that go-redis recognizes in ParseURL,
by constructing a standard client directly instead of building
UniversalOptions ourselves.
e4b0261f — Drew DeVault 1 year, 6 months ago
Export webhooks public key via api-meta.json
17315205 — Robin Jarry 1 year, 8 months ago
config: factorize integer parsing

Add a new GetInt() function to parse an integer value from a parsed
ini.File. Use that function instead of duplicated code.

Signed-off-by: Robin Jarry <robin@jarry.cc>
7457c44b — Robin Jarry 1 year, 8 months ago
treewide: update to new multi worker dowork api

The work.Queue() implementation has changed and now allows scheduling
tasks from multiple goroutines in parallel. Also, it requires a new
argument for limiting the queue buffer size in order to apply back
pressure.

Define new configuration variables to allow tuning the queue sizes and
number of workers per service:

  [mail]
  # Maximum size of the outgoing email queue (default 512).
  egress-queue-size = 512

  [$service_name]
  # Number of parallel workers per queue (default 1).
  # There are multiple queues (for egress email, webhooks, etc.).
  # This setting is applied on a per-queue basis.
  queue-workers = 1

  [webhooks]
  # Maximum size of the webhooks queue (default 512).
  queue-size = 512

Use these new settings to configure the queues and workers accordingly.

Fix unit tests as well.

Link: https://git.sr.ht/~sircmpwn/dowork/commit/95719cfc0118
Signed-off-by: Robin Jarry <robin@jarry.cc>
Next