-
Notifications
You must be signed in to change notification settings - Fork 13
expose /metrics from vtbackup at http --port #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| Copyright 2022 The Vitess Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| // This plugin imports Prometheus to allow for instrumentation | ||
| // with the Prometheus client library | ||
|
|
||
| import ( | ||
| "vitess.io/vitess/go/stats/prometheusbackend" | ||
| "vitess.io/vitess/go/vt/servenv" | ||
| ) | ||
|
|
||
| func init() { | ||
| servenv.OnRun(func() { | ||
| prometheusbackend.Init("vtbackup") | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,8 @@ import ( | |
| "fmt" | ||
| "math" | ||
| "math/big" | ||
| mathrand "math/rand" | ||
| "os" | ||
| "os/signal" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
|
|
@@ -112,11 +112,12 @@ var ( | |
| initShard string | ||
| concurrency = 4 | ||
| // mysqlctld-like flags | ||
| mysqlPort = 3306 | ||
| mysqlSocket string | ||
| mysqlTimeout = 5 * time.Minute | ||
| initDBSQLFile string | ||
| detachedMode bool | ||
| mysqlPort = 3306 | ||
| mysqlSocket string | ||
| mysqlTimeout = 5 * time.Minute | ||
| initDBSQLFile string | ||
| detachedMode bool | ||
| keepAliveTimeout = 0 * time.Second | ||
| ) | ||
|
|
||
| func registerFlags(fs *pflag.FlagSet) { | ||
|
|
@@ -137,17 +138,32 @@ func registerFlags(fs *pflag.FlagSet) { | |
| fs.DurationVar(&mysqlTimeout, "mysql_timeout", mysqlTimeout, "how long to wait for mysqld startup") | ||
| fs.StringVar(&initDBSQLFile, "init_db_sql_file", initDBSQLFile, "path to .sql file to run after mysql_install_db") | ||
| fs.BoolVar(&detachedMode, "detach", detachedMode, "detached mode - run backups detached from the terminal") | ||
| fs.DurationVar(&keepAliveTimeout, "keep-alive-timeout", keepAliveTimeout, "Wait until timeout elapses after a successful backup before shutting down.") | ||
| } | ||
|
|
||
| func init() { | ||
| mathrand.Seed(time.Now().UnixNano()) | ||
| servenv.RegisterDefaultFlags() | ||
| servenv.RegisterFlags() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think maybe we could do without |
||
| dbconfigs.RegisterFlags(dbconfigs.All...) | ||
| mysqlctl.RegisterFlags() | ||
| servenv.OnParse(registerFlags) | ||
| } | ||
|
|
||
| func main() { | ||
| defer exit.Recover() | ||
| dbconfigs.RegisterFlags(dbconfigs.All...) | ||
| mysqlctl.RegisterFlags() | ||
| servenv.Init() | ||
| servenv.ParseFlags("vtbackup") | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| servenv.OnClose(func() { | ||
| cancel() | ||
| }) | ||
| defer func() { | ||
| servenv.ExitChan <- syscall.SIGTERM | ||
| <-ctx.Done() | ||
| }() | ||
| go servenv.RunDefault() | ||
|
|
||
| if detachedMode { | ||
| // this method will call os.Exit and kill this process | ||
| cmd.DetachFromTerminalAndExit() | ||
|
|
@@ -160,16 +176,6 @@ func main() { | |
| exit.Return(1) | ||
| } | ||
|
|
||
| // Catch SIGTERM and SIGINT so we get a chance to clean up. | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signal handling now done by |
||
| go func() { | ||
| sig := <-sigChan | ||
| log.Infof("Cancelling due to signal: %v", sig) | ||
| cancel() | ||
| }() | ||
|
|
||
| // Open connection backup storage. | ||
| backupStorage, err := backupstorage.GetBackupStorage() | ||
| if err != nil { | ||
|
|
@@ -202,6 +208,15 @@ func main() { | |
| log.Errorf("Couldn't prune old backups: %v", err) | ||
| exit.Return(1) | ||
| } | ||
|
|
||
| if keepAliveTimeout > 0 { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this for local testing, but I think this could also be useful in a K8s context to allow the next Prometheus scrape interval to pass before the process exits. |
||
| log.Infof("Backup was successful, waiting %s before exiting (or until context expires).", keepAliveTimeout) | ||
| select { | ||
| case <-time.After(keepAliveTimeout): | ||
| case <-ctx.Done(): | ||
| } | ||
| } | ||
| log.Info("Exiting.") | ||
| } | ||
|
|
||
| func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage backupstorage.BackupStorage) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we want/need this. Copy-pasted from elsewhere.