From 35b376dae5a58dbbcf1bd39902ba3f836a654e36 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 9 Oct 2025 18:36:03 -0700 Subject: [PATCH] update rainbow to cli/v3 --- cmd/rainbow/main.go | 62 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/cmd/rainbow/main.go b/cmd/rainbow/main.go index b6b26df9..08b0afb2 100644 --- a/cmd/rainbow/main.go +++ b/cmd/rainbow/main.go @@ -18,7 +18,7 @@ import ( "github.com/bluesky-social/indigo/util/svcutil" "github.com/earthboundkid/versioninfo/v2" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" @@ -36,7 +36,7 @@ func main() { func run(args []string) error { - app := cli.App{ + app := cli.Command{ Name: "rainbow", Usage: "atproto firehose fan-out daemon", Version: versioninfo.Short(), @@ -47,94 +47,94 @@ func run(args []string) error { &cli.StringFlag{ Name: "log-level", Usage: "log verbosity level (eg: warn, info, debug)", - EnvVars: []string{"RAINBOW_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"}, + Sources: cli.EnvVars("RAINBOW_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"), }, &cli.StringFlag{ Name: "upstream-host", Value: "http://localhost:2470", Usage: "URL (schema and hostname, no path) of the upstream host (eg, relay)", - EnvVars: []string{"ATP_RELAY_HOST", "RAINBOW_RELAY_HOST"}, + Sources: cli.EnvVars("ATP_RELAY_HOST", "RAINBOW_RELAY_HOST"), }, &cli.StringFlag{ Name: "persist-db", Value: "./rainbow.db", Usage: "path to persistence db", - EnvVars: []string{"RAINBOW_DB_PATH"}, + Sources: cli.EnvVars("RAINBOW_DB_PATH"), }, &cli.StringFlag{ Name: "cursor-file", Value: "./rainbow-cursor", Usage: "write upstream cursor number to this file", - EnvVars: []string{"RAINBOW_CURSOR_PATH"}, + Sources: cli.EnvVars("RAINBOW_CURSOR_PATH"), }, &cli.StringFlag{ Name: "api-listen", Value: ":2480", - EnvVars: []string{"RAINBOW_API_LISTEN"}, + Sources: cli.EnvVars("RAINBOW_API_LISTEN"), }, &cli.StringFlag{ Name: "metrics-listen", Value: ":2481", - EnvVars: []string{"RAINBOW_METRICS_LISTEN", "SPLITTER_METRICS_LISTEN"}, + Sources: cli.EnvVars("RAINBOW_METRICS_LISTEN", "SPLITTER_METRICS_LISTEN"), }, &cli.Float64Flag{ Name: "persist-hours", Value: 24 * 3, - EnvVars: []string{"RAINBOW_PERSIST_HOURS", "SPLITTER_PERSIST_HOURS"}, + Sources: cli.EnvVars("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{"RAINBOW_PERSIST_BYTES", "SPLITTER_PERSIST_BYTES"}, + Sources: cli.EnvVars("RAINBOW_PERSIST_BYTES", "SPLITTER_PERSIST_BYTES"), }, &cli.StringSliceFlag{ // TODO: better name for this argument Name: "next-crawler", Usage: "forward POST requestCrawl to these hosts (schema and host, no path) in addition to upstream-host. Comma-separated or multiple flags", - EnvVars: []string{"RAINBOW_NEXT_CRAWLER", "RELAY_NEXT_CRAWLER"}, + Sources: cli.EnvVars("RAINBOW_NEXT_CRAWLER", "RELAY_NEXT_CRAWLER"), }, &cli.StringFlag{ Name: "collectiondir-host", Value: "http://localhost:2510", Usage: "host (schema and hostname, no path) of upstream collectiondir instance, for com.atproto.sync.listReposByCollection", - EnvVars: []string{"RAINBOW_COLLECTIONDIR_HOST"}, + Sources: cli.EnvVars("RAINBOW_COLLECTIONDIR_HOST"), }, &cli.StringFlag{ Name: "env", Usage: "operating environment (eg, 'prod', 'test')", Value: "dev", - EnvVars: []string{"ENVIRONMENT"}, + Sources: cli.EnvVars("ENVIRONMENT"), }, &cli.BoolFlag{ Name: "enable-otel-otlp", Usage: "enables OTEL OTLP exporter endpoint", - EnvVars: []string{"RAINBOW_ENABLE_OTEL_OTLP", "ENABLE_OTEL_OTLP"}, + Sources: cli.EnvVars("RAINBOW_ENABLE_OTEL_OTLP", "ENABLE_OTEL_OTLP"), }, &cli.StringFlag{ Name: "otel-otlp-endpoint", Usage: "OTEL traces export endpoint", Value: "http://localhost:4318", - EnvVars: []string{"OTEL_EXPORTER_OTLP_ENDPOINT"}, + Sources: cli.EnvVars("OTEL_EXPORTER_OTLP_ENDPOINT"), }, } - return app.Run(args) + return app.Run(context.Background(), args) } -func runSplitter(cctx *cli.Context) error { +func runSplitter(ctx context.Context, cmd *cli.Command) error { // Trap SIGINT to trigger a shutdown. signals := make(chan os.Signal, 1) signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) - logger := svcutil.ConfigLogger(cctx, os.Stdout).With("system", "rainbow") + logger := svcutil.ConfigLogger(cmd, os.Stdout).With("system", "rainbow") // Enable OTLP HTTP exporter // For relevant environment variables: // https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace#readme-environment-variables - if cctx.Bool("enable-otel-otlp") { - ep := cctx.String("otel-otlp-endpoint") + if cmd.Bool("enable-otel-otlp") { + ep := cmd.String("otel-otlp-endpoint") logger.Info("setting up trace exporter", "endpoint", ep) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -152,7 +152,7 @@ func runSplitter(cctx *cli.Context) error { } }() - env := cctx.String("env") + env := cmd.String("env") tp := tracesdk.NewTracerProvider( tracesdk.WithBatcher(exp), tracesdk.WithResource(resource.NewWithAttributes( @@ -166,10 +166,10 @@ func runSplitter(cctx *cli.Context) error { otel.SetTracerProvider(tp) } - persistPath := cctx.String("persist-db") - upstreamHost := cctx.String("upstream-host") - collectionDirHost := cctx.String("collectiondir-host") - nextCrawlers := cctx.StringSlice("next-crawler") + persistPath := cmd.String("persist-db") + upstreamHost := cmd.String("upstream-host") + collectionDirHost := cmd.String("collectiondir-host") + nextCrawlers := cmd.StringSlice("next-crawler") var spl *splitter.Splitter var err error @@ -177,14 +177,14 @@ func runSplitter(cctx *cli.Context) error { logger.Info("building splitter with storage at", "path", persistPath) ppopts := pebblepersist.PebblePersistOptions{ DbPath: persistPath, - PersistDuration: time.Duration(float64(time.Hour) * cctx.Float64("persist-hours")), + PersistDuration: time.Duration(float64(time.Hour) * cmd.Float64("persist-hours")), GCPeriod: 5 * time.Minute, - MaxBytes: uint64(cctx.Int64("persist-bytes")), + MaxBytes: uint64(cmd.Int64("persist-bytes")), } conf := splitter.SplitterConfig{ UpstreamHost: upstreamHost, CollectionDirHost: collectionDirHost, - CursorFile: cctx.String("cursor-file"), + CursorFile: cmd.String("cursor-file"), PebbleOptions: &ppopts, UserAgent: fmt.Sprintf("rainbow/%s (atproto-relay)", versioninfo.Short()), } @@ -194,7 +194,7 @@ func runSplitter(cctx *cli.Context) error { conf := splitter.SplitterConfig{ UpstreamHost: upstreamHost, CollectionDirHost: collectionDirHost, - CursorFile: cctx.String("cursor-file"), + CursorFile: cmd.String("cursor-file"), } spl, err = splitter.NewSplitter(conf, nextCrawlers) } @@ -205,7 +205,7 @@ func runSplitter(cctx *cli.Context) error { } // set up metrics endpoint - metricsListen := cctx.String("metrics-listen") + metricsListen := cmd.String("metrics-listen") go func() { if err := spl.StartMetrics(metricsListen); err != nil { logger.Error("failed to start metrics endpoint", "err", err) @@ -216,7 +216,7 @@ func runSplitter(cctx *cli.Context) error { runErr := make(chan error, 1) go func() { - err := spl.StartAPI(cctx.String("api-listen")) + err := spl.StartAPI(cmd.String("api-listen")) runErr <- err }() -- 2.51.2