work on flags
This commit is contained in:
@@ -8,10 +8,13 @@ import (
|
||||
|
||||
"git.k-space.ee/k-space/logmower-shipper/pkg/file"
|
||||
"git.k-space.ee/k-space/logmower-shipper/pkg/globals"
|
||||
"git.k-space.ee/k-space/logmower-shipper/pkg/lines"
|
||||
m "git.k-space.ee/k-space/logmower-shipper/pkg/mongo"
|
||||
"git.k-space.ee/k-space/logmower-shipper/pkg/sender"
|
||||
"git.k-space.ee/k-space/logmower-shipper/pkg/util"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/urfave/cli/v2"
|
||||
mongoOpt "go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var App = &cli.App{
|
||||
@@ -20,39 +23,42 @@ var App = &cli.App{
|
||||
Authors: []*cli.Author{{Name: "jtagcat"}, {Name: "codemowers.io"}},
|
||||
|
||||
Description: "Collect and ship kubernetes logs",
|
||||
// Usage: "rubykana <input>",
|
||||
// TODO: #2: yaml
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{Name: "simulate", Aliases: []string{"dry-run"}, Usage: "Do not write to database"},
|
||||
&cli.StringFlag{Name: "log-directory", Usage: "Directory to watch for logs", Value: "/var/log/containers"},
|
||||
&cli.IntFlag{Name: "max-record-size", Value: 128 * 1024, Usage: "Maximum record size in bytes"},
|
||||
&cli.IntFlag{Name: "max-record-size", EnvVars: []string{"MAX_RECORD_SIZE"}, Value: 128 * 1024, Usage: "Maximum record size in bytes"},
|
||||
&cli.IntFlag{Name: "bulk-insertion-size", EnvVars: []string{"BULK_INSERTION_SIZE"}, Value: 1000, Usage: "MongoDB bulk insertion size in records"},
|
||||
&cli.Uint64Flag{Name: "max-connection-pool-size", EnvVars: []string{"MAX_CONNECTION_POOL_SIZE"}, Value: 1, Usage: "Max MongoDB connection pool size"},
|
||||
//
|
||||
//TODO: &cli.BoolFlag{Name: "normalize-log-level", Usage: "Normalize log.level values to Syslog defined keywords"},
|
||||
//TODO: &cli.BoolFlag{Name: "parse-json"},
|
||||
//
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "namespace", EnvVars: []string{"KUBE_NAMESPACE"}, Usage: "whitelist filter for filenames"},
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "pod-prefix", EnvVars: []string{"KUBE_NODE_NAME"}, Usage: "blacklist filter for filenames"},
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "namespace", EnvVars: []string{"NAMESPACE"}, Usage: "whitelist filter for filenames"},
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "exclude-pod-prefixes", EnvVars: []string{"EXCLUDE_POD_PREFIXES"}, Usage: "blacklist filter for filenames", Value: cli.NewStringSlice("logmower-")},
|
||||
//
|
||||
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGODB_URI"}, Usage: "mongodb://foo:bar@host:27017/database", Required: true},
|
||||
},
|
||||
Before: func(ctx *cli.Context) error {
|
||||
globals.BufferLimitBytes = ctx.Int("max-record-size")
|
||||
if globals.BufferLimitBytes < 1 {
|
||||
lines.BufferLimitBytes = ctx.Int("max-record-size")
|
||||
if lines.BufferLimitBytes < 1 {
|
||||
return fmt.Errorf("max-record-size must be positive")
|
||||
}
|
||||
|
||||
globals.Simulate = ctx.Bool("simulate")
|
||||
sender.Simulate = ctx.Bool("simulate")
|
||||
sender.MaxBatchItems = ctx.Int("bulk-insertion-size")
|
||||
|
||||
return nil
|
||||
},
|
||||
|
||||
Action: func(ctx *cli.Context) error {
|
||||
whitelistNamespaces, blacklistPodPrefixes := sliceToMap(ctx.StringSlice("namespace")), ctx.StringSlice("pod-prefix")
|
||||
whitelistNamespaces, blacklistPodPrefixes := sliceToMap(ctx.StringSlice("namespace")), ctx.StringSlice("exclude-pod-prefixes")
|
||||
var wg sync.WaitGroup
|
||||
|
||||
log.Printf("%s %s starting", ctx.App.Name, ctx.App.Version)
|
||||
|
||||
db, err := m.Initialize(ctx.Context, ctx.String("mongo-uri"))
|
||||
db, err := m.Initialize(ctx.Context, ctx.String("mongo-uri"), mongoOpt.Client().
|
||||
SetMaxPoolSize(ctx.Uint64("max-connection-pool-size")))
|
||||
if err != nil {
|
||||
return fmt.Errorf("initializing database connection: %w", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user