Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rainbow service setup tweaks #821

Merged
merged 7 commits into from
Nov 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion cmd/rainbow/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/usr/bin/rainbow"]

LABEL org.opencontainers.image.source=https://github.com/bluesky-social/indigo
LABEL org.opencontainers.image.description="bsky.app rainbow"
LABEL org.opencontainers.image.description="rainbow atproto firehose fanout service"
LABEL org.opencontainers.image.licenses=MIT
50 changes: 27 additions & 23 deletions cmd/rainbow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package main
import (
"context"
"github.com/bluesky-social/indigo/events"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"time"

"github.com/bluesky-social/indigo/splitter"
"github.com/carlmjohnson/versioninfo"
_ "go.uber.org/automaxprocs"

_ "net/http/pprof"

_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel"
Expand All @@ -26,7 +25,7 @@ import (
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)

var log = logging.Logger("splitter")
var log = logging.Logger("rainbow")

func init() {
// control log level using, eg, GOLOG_LOG_LEVEL=debug
Expand All @@ -39,50 +38,55 @@ func main() {

func run(args []string) {
app := cli.App{
Name: "splitter",
Usage: "firehose proxy",
Name: "rainbow",
Usage: "atproto firehose fan-out daemon",
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "crawl-insecure-ws",
Usage: "when connecting to PDS instances, use ws:// instead of wss://",
Name: "crawl-insecure-ws",
Usage: "when connecting to PDS instances, use ws:// instead of wss://",
EnvVars: []string{"RAINBOW_INSECURE_CRAWL"},
},
&cli.StringFlag{
Name: "splitter-host",
Value: "bsky.network",
Name: "splitter-host",
Value: "bsky.network",
EnvVars: []string{"ATP_RELAY_HOST", "RAINBOW_RELAY_HOST"},
},
&cli.StringFlag{
Name: "persist-db",
Value: "",
Usage: "path to persistence db",
Name: "persist-db",
Value: "./rainbow.db",
Usage: "path to persistence db",
EnvVars: []string{"RAINBOW_DB_PATH"},
},
&cli.StringFlag{
Name: "cursor-file",
Value: "",
Usage: "write upstream cursor number to this file",
Name: "cursor-file",
Value: "./rainbow-cursor",
Usage: "write upstream cursor number to this file",
EnvVars: []string{"RAINBOW_CURSOR_PATH"},
},
&cli.StringFlag{
Name: "api-listen",
Value: ":2480",
Name: "api-listen",
Value: ":2480",
EnvVars: []string{"RAINBOW_API_LISTEN"},
},
&cli.StringFlag{
Name: "metrics-listen",
Value: ":2481",
EnvVars: []string{"SPLITTER_METRICS_LISTEN"},
EnvVars: []string{"RAINBOW_METRICS_LISTEN", "SPLITTER_METRICS_LISTEN"},
},
&cli.Float64Flag{
Name: "persist-hours",
Value: 24 * 7,
EnvVars: []string{"SPLITTER_PERSIST_HOURS"},
Value: 24 * 3,
EnvVars: []string{"RAINBOW_PERSIST_HOURS", "SPLITTER_PERSIST_HOURS"},
Usage: "hours to buffer (float, may be fractional)",
},
&cli.Int64Flag{
Name: "persist-bytes",
Value: 0,
Usage: "max bytes target for event cache, 0 to disable size target trimming",
EnvVars: []string{"SPLITTER_PERSIST_BYTES"},
EnvVars: []string{"RAINBOW_PERSIST_BYTES", "SPLITTER_PERSIST_BYTES"},
},
}

Expand Down
20 changes: 18 additions & 2 deletions splitter/splitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ func (s *Splitter) StartWithListener(listen net.Listener) error {
}
}

// TODO: this API is temporary until we formalize what we want here

e.GET("/xrpc/com.atproto.sync.subscribeRepos", s.EventsHandler)

e.GET("/xrpc/_health", s.HandleHealthCheck)
e.GET("/_health", s.HandleHealthCheck)
e.GET("/", s.HandleHomeMessage)

// In order to support booting on random ports in tests, we need to tell the
// Echo instance it's already got a port, and then use its StartServer
Expand All @@ -218,6 +219,21 @@ func (s *Splitter) HandleHealthCheck(c echo.Context) error {
return c.JSON(200, HealthStatus{Status: "ok"})
}

var homeMessage string = `
_ _
_ _ __ _(_)_ _ | |__ _____ __ __
| '_/ _' | | ' \| '_ \/ _ \ V V /
|_| \__,_|_|_||_|_.__/\___/\_/\_/

This is an atproto [https://atproto.com] firehose fanout service, running the 'rainbow' codebase [https://github.com/bluesky-social/indigo]

The firehose WebSocket path is at: /xrpc/com.atproto.sync.subscribeRepos
`

func (s *Splitter) HandleHomeMessage(c echo.Context) error {
return c.String(http.StatusOK, homeMessage)
}

func (s *Splitter) EventsHandler(c echo.Context) error {
var since *int64
if sinceVal := c.QueryParam("cursor"); sinceVal != "" {
Expand Down
Loading