-
Notifications
You must be signed in to change notification settings - Fork 455
/
backfill.go
109 lines (87 loc) · 3.3 KB
/
backfill.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: AGPL-3.0-only
package commands
import (
"context"
"fmt"
"os"
"strings"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/sirupsen/logrus"
"github.com/grafana/mimir/pkg/mimirtool/client"
)
type BackfillCommand struct {
clientConfig client.Config
blocks blockList
sleepTime time.Duration
}
type blockList []string
func (l *blockList) Set(value string) error {
st, err := os.Stat(value)
if err != nil {
return fmt.Errorf("directory %q doesn't exist", value)
}
if !st.IsDir() {
return fmt.Errorf("%q must be a directory", value)
}
*l = append(*l, value)
return nil
}
func (l blockList) String() string {
return strings.Join(l, ",")
}
func (l blockList) IsCumulative() bool {
return true
}
func (c *BackfillCommand) Register(app *kingpin.Application, envVars EnvVarNames) {
cmd := app.Command("backfill", "Upload Prometheus TSDB blocks to Grafana Mimir compactor.")
cmd.Action(c.backfill)
cmd.Arg("block-dir", "block to upload").Required().SetValue(&c.blocks)
cmd.Flag("address", "Address of the Grafana Mimir cluster; alternatively, set "+envVars.Address+".").
Envar(envVars.Address).
Required().
StringVar(&c.clientConfig.Address)
cmd.Flag("user",
fmt.Sprintf("Basic auth username to use when contacting Grafana Mimir; alternatively, set %s. If empty, %s is used instead.", envVars.APIUser, envVars.TenantID)).
Default("").
Envar(envVars.APIUser).
StringVar(&c.clientConfig.User)
cmd.Flag("id", "Grafana Mimir tenant ID. Used for X-Scope-OrgID HTTP header. Also used for basic auth if --user is not provided. Alternatively, set "+envVars.TenantID+".").
Envar(envVars.TenantID).
Required().
StringVar(&c.clientConfig.ID)
cmd.Flag("key", "Basic auth password to use when contacting Grafana Mimir; alternatively, set "+envVars.APIKey+".").
Default("").
Envar(envVars.APIKey).
StringVar(&c.clientConfig.Key)
cmd.Flag("tls-ca-path", "TLS CA certificate to verify Grafana Mimir API as part of mTLS; alternatively, set "+envVars.TLSCAPath+".").
Default("").
Envar(envVars.TLSCAPath).
StringVar(&c.clientConfig.TLS.CAPath)
cmd.Flag("tls-cert-path", "TLS client certificate to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set "+envVars.TLSCertPath+".").
Default("").
Envar(envVars.TLSCertPath).
StringVar(&c.clientConfig.TLS.CertPath)
cmd.Flag("tls-key-path", "TLS client certificate private key to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set "+envVars.TLSKeyPath+".").
Default("").
Envar(envVars.TLSKeyPath).
StringVar(&c.clientConfig.TLS.KeyPath)
cmd.Flag("tls-insecure-skip-verify", "Skip TLS certificate verification; alternatively, set "+envVars.TLSInsecureSkipVerify+".").
Default("false").
Envar(envVars.TLSInsecureSkipVerify).
BoolVar(&c.clientConfig.TLS.InsecureSkipVerify)
cmd.Flag("sleep-time", "How long to sleep between checking state of block upload after uploading all files for the block.").
Default("20s").
DurationVar(&c.sleepTime)
}
func (c *BackfillCommand) backfill(_ *kingpin.ParseContext) error {
logrus.WithFields(logrus.Fields{
"blocks": c.blocks.String(),
"user": c.clientConfig.ID,
}).Println("Backfilling")
cli, err := client.New(c.clientConfig)
if err != nil {
return err
}
return cli.Backfill(context.Background(), c.blocks, c.sleepTime)
}