-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate vtorc to use cobra commands (#13917)
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
172 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Copyright 2023 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 cli | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/acl" | ||
_flag "vitess.io/vitess/go/internal/flag" | ||
"vitess.io/vitess/go/viperutil" | ||
viperdebug "vitess.io/vitess/go/viperutil/debug" | ||
"vitess.io/vitess/go/vt/log" | ||
"vitess.io/vitess/go/vt/servenv" | ||
"vitess.io/vitess/go/vt/vtorc/config" | ||
"vitess.io/vitess/go/vt/vtorc/inst" | ||
"vitess.io/vitess/go/vt/vtorc/logic" | ||
"vitess.io/vitess/go/vt/vtorc/server" | ||
) | ||
|
||
var ( | ||
configFile string | ||
Main = &cobra.Command{ | ||
Use: "vtorc", | ||
Short: "", // TODO | ||
Args: cobra.NoArgs, | ||
Version: servenv.AppVersion.String(), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
_flag.TrickGlog() | ||
|
||
watchCancel, err := viperutil.LoadConfig() | ||
if err != nil { | ||
return fmt.Errorf("%s: failed to read in config: %s", cmd.Name(), err) | ||
} | ||
|
||
servenv.OnTerm(watchCancel) | ||
servenv.HTTPHandleFunc("/debug/config", viperdebug.HandlerFunc) | ||
return nil | ||
}, | ||
Run: run, | ||
} | ||
) | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
servenv.Init() | ||
config.UpdateConfigValuesFromFlags() | ||
inst.RegisterStats() | ||
|
||
log.Info("starting vtorc") | ||
if len(configFile) > 0 { | ||
config.ForceRead(configFile) | ||
} else { | ||
config.Read("/etc/vtorc.conf.json", "conf/vtorc.conf.json", "vtorc.conf.json") | ||
} | ||
if config.Config.AuditToSyslog { | ||
inst.EnableAuditSyslog() | ||
} | ||
config.MarkConfigurationLoaded() | ||
|
||
// Log final config values to debug if something goes wrong. | ||
config.LogConfigValues() | ||
server.StartVTOrcDiscovery() | ||
|
||
server.RegisterVTOrcAPIEndpoints() | ||
servenv.OnRun(func() { | ||
addStatusParts() | ||
}) | ||
|
||
// For backward compatability, we require that VTOrc functions even when the --port flag is not provided. | ||
// In this case, it should function like before but without the servenv pages. | ||
// Therefore, currently we don't check for the --port flag to be necessary, but release 16+ that check | ||
// can be added to always have the serenv page running in VTOrc. | ||
servenv.RunDefault() | ||
} | ||
|
||
// addStatusParts adds UI parts to the /debug/status page of VTOrc | ||
func addStatusParts() { | ||
servenv.AddStatusPart("Recent Recoveries", logic.TopologyRecoveriesTemplate, func() any { | ||
recoveries, _ := logic.ReadRecentRecoveries(false, 0) | ||
return recoveries | ||
}) | ||
} | ||
|
||
func init() { | ||
servenv.RegisterDefaultFlags() | ||
servenv.RegisterFlags() | ||
|
||
Main.Flags().AddFlagSet(servenv.GetFlagSetFor("vtorc")) | ||
|
||
// glog flags, no better way to do this | ||
_flag.PreventGlogVFlagFromClobberingVersionFlagShorthand(Main.Flags()) | ||
Main.Flags().AddGoFlag(flag.Lookup("logtostderr")) | ||
Main.Flags().AddGoFlag(flag.Lookup("alsologtostderr")) | ||
Main.Flags().AddGoFlag(flag.Lookup("stderrthreshold")) | ||
Main.Flags().AddGoFlag(flag.Lookup("log_dir")) | ||
|
||
logic.RegisterFlags(Main.Flags()) | ||
server.RegisterFlags(Main.Flags()) | ||
config.RegisterFlags(Main.Flags()) | ||
acl.RegisterFlags(Main.Flags()) | ||
Main.Flags().StringVar(&configFile, "config", "", "config file name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2023 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 | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/internal/docgen" | ||
"vitess.io/vitess/go/cmd/vtorc/cli" | ||
) | ||
|
||
func main() { | ||
var dir string | ||
cmd := cobra.Command{ | ||
Use: "docgen [-d <dir>]", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return docgen.GenerateMarkdownTree(cli.Main, dir) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&dir, "dir", "d", "doc", "output directory to write documentation") | ||
_ = cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.