-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feat: Raccoon CLI #92
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
0680791
cmd: add basic CLI harness
turtleDev dcf9d90
cmd: wip on server flags
turtleDev 17cfb24
cmd: server: bind flags for event acknowledgement
turtleDev a80e037
cmd: server: add kafka client flags
turtleDev c393338
cli: remove usused comments
turtleDev c3a481e
cmd: simplify boolean flags
turtleDev 1d9eea7
cmd: fix --event.ack parsing
turtleDev 36fa95b
config: kafka: make bootstrap server config required
turtleDev 3c19fe0
cmd: fix duration flags not propagating values to config
turtleDev a123ad6
cmd: chore: allow flags on root command
turtleDev ceda933
ci: update tests to use raccoon cli
turtleDev 98bed57
ci: fix compose not starting raccoon server
turtleDev d8d5029
chore: update config tests
turtleDev a8625be
wip: migration to salt/config
turtleDev 9be8641
config: replace use of time.Duration values with ints
turtleDev 6839586
config: WIP validation
turtleDev c7a392c
config: refactor validation + add fallbacks
turtleDev 4138a3f
docs: kinesis: mark kinesis credentials file required
turtleDev bc7de1f
config: purge utils
turtleDev 6e5b674
chore: tidy deps
turtleDev 5f925d6
config: chore: use consolidate config values
turtleDev f42f4bc
wip: config: salt/config integration
turtleDev c47efbb
config: refactor config to comply with salt/config
turtleDev 9527560
config: revamp error validation
turtleDev aaaf3bf
config: fix defaults
turtleDev 7442e94
config: fix tags on publisher config
turtleDev 42d9fe3
config: purge tests
turtleDev 881d56a
config: add default for server.websocket.conn.group.default
turtleDev 2c58e3e
docs: fix ping/pong and write timeout defaults
turtleDev bdd7eff
config: move WORKER_KAFKA_DELIVERY_CHANNEL_SIZE to kafka publisher
turtleDev da3e91d
cmd: server: add flag for config file
turtleDev 93e95ba
config: update cors to use comma separated values
turtleDev 04a4d02
ci: add testing yaml config
turtleDev 8d39df8
chore: add sample raccoon config
turtleDev 1c128d8
cli: integrate salt/cmdx
turtleDev d55de64
config: make kafka config type-concrete
turtleDev 9f70396
misc: fix panic on server shutdown when prometheus metrics are enabled
turtleDev 5c8f661
ci: update test environment
turtleDev 5e43b94
docker: make image act as a CLI
turtleDev a44ba4c
chore: removed unused configs
turtleDev d828316
config: kafka: omit empty configs
turtleDev db00cf5
cmd: add dynamically generated cli flags
turtleDev 7f14b58
cmd: remove duration flag parser
turtleDev 3a499e7
cmd: server: simplify flag parsing
turtleDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM debian:bookworm-slim | ||
WORKDIR /app | ||
COPY raccoon . | ||
CMD ["./raccoon"] | ||
ENTRYPOINT [ "/app/raccoon" ] |
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,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/raystack/salt/cmdx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func New() *cobra.Command { | ||
root := &cobra.Command{ | ||
Use: "raccoon", | ||
Short: "Scalable event ingestion tool", | ||
SilenceUsage: true, | ||
CompletionOptions: cobra.CompletionOptions{ | ||
DisableDefaultCmd: true, | ||
}, | ||
Args: cobra.NoArgs, | ||
Long: heredoc.Doc(` | ||
Raccoon is a high-throughput, low-latency service to collect | ||
events in real-time from your web, mobile apps, and services | ||
using multiple network protocols.`), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
Annotations: map[string]string{ | ||
"group": "core", | ||
"help:learn": heredoc.Doc(` | ||
Use 'raccoon <command> --help' for more information about a command. | ||
Read the manual at https://raystack.github.io/raccoon/ | ||
`), | ||
"help:feedback": heredoc.Doc(` | ||
Open an issue here https://github.com/raystack/raccoon/issues | ||
`), | ||
}, | ||
} | ||
|
||
cmdx.SetHelp(root) | ||
root.AddCommand(cmdx.SetCompletionCmd("raccoon")) | ||
root.AddCommand(cmdx.SetRefCmd(root)) | ||
|
||
root.AddCommand(serverCommand()) | ||
return root | ||
} |
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,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
|
||
"github.com/raystack/raccoon/app" | ||
"github.com/raystack/raccoon/config" | ||
"github.com/raystack/raccoon/logger" | ||
"github.com/raystack/raccoon/metrics" | ||
"github.com/raystack/raccoon/middleware" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func serverCommand() *cobra.Command { | ||
var configFile = "config.yaml" | ||
command := &cobra.Command{ | ||
Use: "server", | ||
Short: "Start raccoon server", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := config.Load(configFile) | ||
if err != nil { | ||
return err | ||
} | ||
middleware.Load() | ||
metrics.Setup() | ||
defer metrics.Close() | ||
logger.SetLevel(config.Log.Level) | ||
return app.Run() | ||
}, | ||
} | ||
command.Flags().SortFlags = false | ||
command.Flags().StringVarP(&configFile, "config", "c", configFile, "path to config file") | ||
for _, cfg := range config.Walk() { | ||
bindFlag(command.Flags(), cfg.Ref, cfg.Meta) | ||
} | ||
return command | ||
} | ||
|
||
func bindFlag(flag *pflag.FlagSet, ref any, meta reflect.StructField) { | ||
|
||
flagName := meta.Tag.Get("cmdx") | ||
desc := meta.Tag.Get("desc") | ||
|
||
switch v := ref.(type) { | ||
case *config.AckType: | ||
flag.Var(ackTypeFlag{v}, flagName, desc) | ||
case *string: | ||
flag.StringVar(v, flagName, *v, desc) | ||
case *int: | ||
flag.IntVar(v, flagName, *v, desc) | ||
case *int64: | ||
flag.Int64Var(v, flagName, *v, desc) | ||
case *uint32: | ||
flag.Uint32Var(v, flagName, *v, desc) | ||
case *bool: | ||
flag.BoolVar(v, flagName, *v, desc) | ||
case *[]string: | ||
flag.StringSliceVar(v, flagName, *v, desc) | ||
default: | ||
msg := fmt.Sprintf("unsupport flag of type %T", ref) | ||
panic(msg) | ||
} | ||
} | ||
|
||
type ackTypeFlag struct { | ||
value *config.AckType | ||
} | ||
|
||
func (af ackTypeFlag) String() string { | ||
if af.value == nil { | ||
return "0" | ||
} | ||
return fmt.Sprintf("%d", *af.value) | ||
} | ||
|
||
func (af ackTypeFlag) Set(raw string) error { | ||
v, err := strconv.ParseInt(raw, 10, 0) | ||
if err != nil { | ||
return fmt.Errorf("error parsing bool: %w", err) | ||
} | ||
*af.value = config.AckType(v) | ||
return nil | ||
} | ||
|
||
func (af ackTypeFlag) Type() string { | ||
return "int" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@turtleDev Let's use salt/cmdx for cli.