mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 04:54:18 +02:00
add alias+datastream rollover, and auto rollover on index tpl change (#40)
fixes #37
This commit is contained in:
@@ -37,6 +37,7 @@ func Datastream(conf *cfg.Config) *cli.Command {
|
||||
DatastreamShow(conf),
|
||||
DatastreamCreate(conf),
|
||||
DatastreamDelete(conf),
|
||||
DatastreamRollover(conf),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -138,3 +139,61 @@ func DatastreamDelete(conf *cfg.Config) *cli.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DatastreamRollover(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "rollover",
|
||||
Aliases: []string{"roll"},
|
||||
Usage: "roll over a data stream",
|
||||
UsageText: "rollover <data stream>",
|
||||
|
||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||
complete(cmd, Cindex)
|
||||
},
|
||||
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "wait",
|
||||
Usage: "wait for active shards",
|
||||
Destination: &conf.Wait,
|
||||
Aliases: []string{"w"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "checks conditions but does not perform a rollover",
|
||||
Destination: &conf.Wait,
|
||||
Aliases: []string{"n"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "max-age",
|
||||
Usage: "roll over after max age (eg: 7d, 2m, 8h)",
|
||||
Destination: &conf.MaxAge,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-docs",
|
||||
Usage: "roll over after max docs",
|
||||
Destination: &conf.MaxDocs,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-primary-shard-size",
|
||||
Usage: "roll over when primary shard size reaches size",
|
||||
Destination: &conf.MaxShardSize,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-primary-shard-docs",
|
||||
Usage: "roll over after max docs in primary shard reached",
|
||||
Destination: &conf.MaxShardDocs,
|
||||
},
|
||||
},
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
alias := cmd.Args().Get(0)
|
||||
|
||||
if alias == "" {
|
||||
return errors.New("no data stream specified")
|
||||
}
|
||||
|
||||
return es.DatastreamRollover(conf, alias)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ func IndexAlias(conf *cfg.Config) *cli.Command {
|
||||
IndexAliasCreate(conf),
|
||||
IndexAliasList(conf),
|
||||
IndexAliasDelete(conf),
|
||||
// FIXME: implement IndexAliasShow + IndexAliasAdd
|
||||
//IndexAliasShow(conf),
|
||||
IndexAliasRollover(conf),
|
||||
// FIXME: implement IndexAliasAdd
|
||||
//IndexAliasAdd(conf), // see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-update-aliases
|
||||
},
|
||||
}
|
||||
@@ -91,6 +91,64 @@ func IndexAliasDelete(conf *cfg.Config) *cli.Command {
|
||||
}
|
||||
}
|
||||
|
||||
func IndexAliasRollover(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "rollover",
|
||||
Aliases: []string{"roll"},
|
||||
Usage: "roll over an index alias",
|
||||
UsageText: "rollover <alias>",
|
||||
|
||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||
complete(cmd, Cindex)
|
||||
},
|
||||
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "wait",
|
||||
Usage: "wait for active shards",
|
||||
Destination: &conf.Wait,
|
||||
Aliases: []string{"w"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "checks conditions but does not perform a rollover",
|
||||
Destination: &conf.Wait,
|
||||
Aliases: []string{"n"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "max-age",
|
||||
Usage: "roll over after max age (eg: 7d, 2m, 8h)",
|
||||
Destination: &conf.MaxAge,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-docs",
|
||||
Usage: "roll over after max docs",
|
||||
Destination: &conf.MaxDocs,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-primary-shard-size",
|
||||
Usage: "roll over when primary shard size reaches size",
|
||||
Destination: &conf.MaxShardSize,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-primary-shard-docs",
|
||||
Usage: "roll over after max docs in primary shard reached",
|
||||
Destination: &conf.MaxShardDocs,
|
||||
},
|
||||
},
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
alias := cmd.Args().Get(0)
|
||||
|
||||
if alias == "" {
|
||||
return errors.New("no alias specified")
|
||||
}
|
||||
|
||||
return es.IndexAliasRollover(conf, alias)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func IndexAliasList(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "list",
|
||||
|
||||
@@ -113,6 +113,12 @@ https://www.elastic.co/docs/reference/elasticsearch/index-settings
|
||||
Destination: &conf.AutoCreate,
|
||||
Aliases: []string{"a"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "rollover",
|
||||
Usage: "automatically rollover associated aliases",
|
||||
Destination: &conf.Rollover,
|
||||
Aliases: []string{"R"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "mode",
|
||||
Usage: "index mode, one of: standard, timeseries, logsdb or lookup",
|
||||
@@ -171,8 +177,10 @@ https://www.elastic.co/docs/reference/elasticsearch/index-settings
|
||||
return fmt.Errorf("no name specified")
|
||||
}
|
||||
|
||||
if !slices.Contains([]string{"standard", "timeseries", "logsdb", "lookup"}, conf.Mode) {
|
||||
return errors.New("mode must be one of: standard, timeseries, logsdb or lookup")
|
||||
if conf.Mode != "" {
|
||||
if !slices.Contains([]string{"standard", "timeseries", "logsdb", "lookup"}, conf.Mode) {
|
||||
return errors.New("mode must be one of: standard, timeseries, logsdb or lookup")
|
||||
}
|
||||
}
|
||||
|
||||
mappings := args.Slice()[1:]
|
||||
|
||||
Reference in New Issue
Block a user