()
| 16 | ) |
| 17 | |
| 18 | func main() { |
| 19 | var ( |
| 20 | configFilename string |
| 21 | dryRun bool |
| 22 | cfg bucket.Config |
| 23 | ) |
| 24 | |
| 25 | logfmt, loglvl := logging.Format{}, logging.Level{} |
| 26 | logfmt.RegisterFlags(flag.CommandLine) |
| 27 | loglvl.RegisterFlags(flag.CommandLine) |
| 28 | cfg.RegisterFlags(flag.CommandLine) |
| 29 | flag.StringVar(&configFilename, "config", "", "Path to bucket config YAML") |
| 30 | flag.BoolVar(&dryRun, "dry-run", false, "Don't make changes; only report what needs to be done") |
| 31 | flag.Usage = func() { |
| 32 | fmt.Fprintf(flag.CommandLine.Output(), "%s is a tool to convert block metadata from Thanos to Cortex.\nPlease see %s for instructions on how to run it.\n\n", os.Args[0], "https://cortexmetrics.io/docs/blocks-storage/migrate-storage-from-thanos-and-prometheus/") |
| 33 | fmt.Fprintf(flag.CommandLine.Output(), "Flags:\n") |
| 34 | flag.PrintDefaults() |
| 35 | } |
| 36 | flag.Parse() |
| 37 | |
| 38 | logger, err := log.NewPrometheusLogger(loglvl, logfmt) |
| 39 | if err != nil { |
| 40 | fatal("failed to create logger: %v", err) |
| 41 | } |
| 42 | |
| 43 | if configFilename != "" { |
| 44 | buf, err := os.ReadFile(configFilename) |
| 45 | if err != nil { |
| 46 | fatal("failed to load config file from %s: %v", configFilename, err) |
| 47 | } |
| 48 | err = yaml.UnmarshalStrict(buf, &cfg) |
| 49 | if err != nil { |
| 50 | fatal("failed to parse config file: %v", err) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if err := cfg.Validate(); err != nil { |
| 55 | fatal("bucket config is invalid: %v", err) |
| 56 | } |
| 57 | |
| 58 | ctx := context.Background() |
| 59 | |
| 60 | converter, err := thanosconvert.NewThanosBlockConverter(ctx, cfg, dryRun, logger) |
| 61 | if err != nil { |
| 62 | fatal("couldn't initialize converter: %v", err) |
| 63 | } |
| 64 | |
| 65 | iterCtx := context.Background() |
| 66 | results, err := converter.Run(iterCtx) |
| 67 | |
| 68 | fmt.Println("Results:") |
| 69 | for user, res := range results { |
| 70 | fmt.Printf("User %s:\n", user) |
| 71 | fmt.Printf(" Converted %d:\n %s", len(res.ConvertedBlocks), strings.Join(res.ConvertedBlocks, ",")) |
| 72 | fmt.Printf(" Unchanged %d:\n %s", len(res.UnchangedBlocks), strings.Join(res.UnchangedBlocks, ",")) |
| 73 | fmt.Printf(" Failed %d:\n %s", len(res.FailedBlocks), strings.Join(res.FailedBlocks, ",")) |
| 74 | } |
| 75 |
nothing calls this directly
no test coverage detected