Files
esctl/cmd/datastream.go

221 lines
5.4 KiB
Go
Raw Normal View History

/*
Copyright © 2026 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"context"
"errors"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
"github.com/urfave/cli/v3"
)
func Datastream(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "datastream",
Aliases: []string{"ds"},
Usage: "manage data streams",
Commands: []*cli.Command{
DatastreamList(conf),
DatastreamShow(conf),
DatastreamCreate(conf),
DatastreamDelete(conf),
DatastreamRollover(conf),
},
}
}
func DatastreamList(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "list indicies",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "max",
Usage: "max number of items to process",
Destination: &conf.MaxItems,
Aliases: []string{"m"},
},
&cli.BoolFlag{
Name: "hidden",
Usage: "include hidden data streams",
Destination: &conf.Hidden,
Aliases: []string{"H"},
},
&cli.StringSliceFlag{
Name: "filter",
Usage: "show only data streams matching the filter",
Destination: &conf.Filter,
Aliases: []string{"F"},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.DatastreamList(conf)
},
}
}
func DatastreamShow(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "show",
Aliases: []string{"sh"},
Usage: "show details about an data stream",
Action: func(ctx context.Context, cmd *cli.Command) error {
index := cmd.Args().Get(0)
if index == "" {
return errors.New("no data stream specified")
}
return es.DatastreamShow(conf, cmd.Args().Get(0))
},
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(conf, cmd, Cdatastream)
},
}
}
func DatastreamCreate(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "create",
Aliases: []string{"+"},
Usage: "create a new data stream",
UsageText: "create [options] <name>",
Action: func(ctx context.Context, cmd *cli.Command) error {
index := cmd.Args().Get(0)
if index == "" {
return errors.New("no data stream specified")
}
return es.DatastreamCreate(conf, cmd.Args().Get(0))
},
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(conf, cmd, Cdatastream)
},
}
}
func DatastreamDelete(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "delete",
Aliases: []string{"rm"},
Usage: "delete a data stream",
UsageText: "delete [options] <name>",
Action: func(ctx context.Context, cmd *cli.Command) error {
index := cmd.Args().Get(0)
if index == "" {
return errors.New("no data stream specified")
}
return es.DatastreamDelete(conf, cmd.Args().Get(0))
},
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(conf, cmd, Cdatastream)
},
}
}
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(conf, 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)
},
}
}
2026-06-22 13:52:02 +02:00
func DatastreamIlm(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "ilm",
Usage: "show ilm status",
UsageText: "ds ilm <name>",
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(conf, cmd, Cdatastream)
2026-06-22 13:52:02 +02:00
},
Action: func(ctx context.Context, cmd *cli.Command) error {
ds := cmd.Args().Get(0)
if ds == "" {
return errors.New("no ds name specified")
}
return es.IlmExplain(conf, ds)
},
}
}