mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 05:29:30 +00:00
PT-1822 Fixed for CR
This commit is contained in:
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@@ -188,12 +188,12 @@
|
|||||||
revision = "197f4ad8db8d1b04ff408042119176907c971f0a"
|
revision = "197f4ad8db8d1b04ff408042119176907c971f0a"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:1d7e1867c49a6dd9856598ef7c3123604ea3daabf5b83f303ff457bcbc410b1d"
|
digest = "1:c45802472e0c06928cd997661f2af610accd85217023b1d5f6331bebce0671d3"
|
||||||
name = "github.com/pkg/errors"
|
name = "github.com/pkg/errors"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
pruneopts = ""
|
pruneopts = ""
|
||||||
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
|
revision = "614d223910a179a466c1767a985424175c39b465"
|
||||||
version = "v0.8.1"
|
version = "v0.9.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:55dcddb2ba6ab25098ee6b96f176f39305f1fde7ea3d138e7e10bb64a5bf45be"
|
digest = "1:55dcddb2ba6ab25098ee6b96f176f39305f1fde7ea3d138e7e10bb64a5bf45be"
|
||||||
|
@@ -13,11 +13,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
shardingNotEnabledError = 203
|
shardingNotEnabledErrorCode = 203
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CANNOT_GET_QUERY_ERROR = errors.New("cannot get query field from the profile document (it is not a map)")
|
CANNOT_GET_QUERY_ERROR = errors.New("cannot get query field from the profile document (it is not a map)")
|
||||||
|
ShardingNotEnabledError = errors.New("sharding not enabled")
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetReplicasetMembers(ctx context.Context, clientOptions *options.ClientOptions) ([]proto.Members, error) {
|
func GetReplicasetMembers(ctx context.Context, clientOptions *options.ClientOptions) ([]proto.Members, error) {
|
||||||
@@ -95,7 +96,7 @@ func GetReplicasetMembers(ctx context.Context, clientOptions *options.ClientOpti
|
|||||||
membersMap[m.Name] = m
|
membersMap[m.Name] = m
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Disconnect(ctx)
|
client.Disconnect(ctx) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range membersMap {
|
for _, member := range membersMap {
|
||||||
@@ -122,8 +123,8 @@ func GetHostnames(ctx context.Context, client *mongo.Client) ([]string, error) {
|
|||||||
var shardsMap proto.ShardsMap
|
var shardsMap proto.ShardsMap
|
||||||
smRes := client.Database("admin").RunCommand(ctx, primitive.M{"getShardMap": 1})
|
smRes := client.Database("admin").RunCommand(ctx, primitive.M{"getShardMap": 1})
|
||||||
if smRes.Err() != nil {
|
if smRes.Err() != nil {
|
||||||
if e, ok := smRes.Err().(mongo.CommandError); ok && e.Code == shardingNotEnabledError {
|
if e, ok := smRes.Err().(mongo.CommandError); ok && e.Code == shardingNotEnabledErrorCode {
|
||||||
return nil, nil // standalone instance
|
return nil, ShardingNotEnabledError // standalone instance
|
||||||
}
|
}
|
||||||
return nil, errors.Wrap(smRes.Err(), "cannot getShardMap for GetHostnames")
|
return nil, errors.Wrap(smRes.Err(), "cannot getShardMap for GetHostnames")
|
||||||
}
|
}
|
||||||
|
@@ -162,7 +162,7 @@ func TestGetShardedHosts(t *testing.T) {
|
|||||||
t.Errorf("Cannot get a new client for host %s: %s", test.uri, err)
|
t.Errorf("Cannot get a new client for host %s: %s", test.uri, err)
|
||||||
}
|
}
|
||||||
if client == nil {
|
if client == nil {
|
||||||
panic(fmt.Sprintf("i: %d, uri: %s\n", i, test.uri))
|
t.Fatalf("mongodb client is nil i: %d, uri: %s\n", i, test.uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.Connect(ctx); err != nil {
|
if err := client.Connect(ctx); err != nil {
|
||||||
|
@@ -38,13 +38,19 @@ const (
|
|||||||
DefaultRunningOpsSamples = 5
|
DefaultRunningOpsSamples = 5
|
||||||
DefaultOutputFormat = "text"
|
DefaultOutputFormat = "text"
|
||||||
typeMongos = "mongos"
|
typeMongos = "mongos"
|
||||||
|
|
||||||
|
// Exit Codes
|
||||||
|
cannotFormatResults = 1
|
||||||
|
cannotParseCommandLineParameters = 2
|
||||||
|
cannotGetHostInfo = 3
|
||||||
|
cannotGetReplicasetMembers = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Build string = "2020-04-23" // nolint
|
Build string = "2020-04-23" // nolint
|
||||||
GoVersion string = "1.14.1" // nolint
|
GoVersion string = "1.14.1" // nolint
|
||||||
Version string = "3.2.0" // nolint
|
Version string = "3.2.0"
|
||||||
Commit string // nolint
|
Commit string
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimedStats struct {
|
type TimedStats struct {
|
||||||
@@ -158,7 +164,7 @@ func main() {
|
|||||||
opts, err := parseFlags()
|
opts, err := parseFlags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cannot get parameters: %s", err.Error())
|
log.Errorf("cannot get parameters: %s", err.Error())
|
||||||
os.Exit(2)
|
os.Exit(cannotParseCommandLineParameters)
|
||||||
}
|
}
|
||||||
if opts == nil && err == nil {
|
if opts == nil && err == nil {
|
||||||
return
|
return
|
||||||
@@ -206,7 +212,7 @@ func main() {
|
|||||||
defer client.Disconnect(ctx) // nolint
|
defer client.Disconnect(ctx) // nolint
|
||||||
|
|
||||||
hostnames, err := util.GetHostnames(ctx, client)
|
hostnames, err := util.GetHostnames(ctx, client)
|
||||||
if err != nil {
|
if err != nil && errors.Is(err, util.ShardingNotEnabledError) {
|
||||||
log.Errorf("Cannot get hostnames: %s", err)
|
log.Errorf("Cannot get hostnames: %s", err)
|
||||||
}
|
}
|
||||||
log.Debugf("hostnames: %v", hostnames)
|
log.Debugf("hostnames: %v", hostnames)
|
||||||
@@ -217,12 +223,12 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
message := fmt.Sprintf("Cannot get host info for %q: %s", opts.Host, err.Error())
|
message := fmt.Sprintf("Cannot get host info for %q: %s", opts.Host, err.Error())
|
||||||
log.Errorf(message)
|
log.Errorf(message)
|
||||||
os.Exit(2)
|
os.Exit(cannotGetHostInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ci.ReplicaMembers, err = util.GetReplicasetMembers(ctx, clientOptions); err != nil {
|
if ci.ReplicaMembers, err = util.GetReplicasetMembers(ctx, clientOptions); err != nil {
|
||||||
log.Warnf("[Error] cannot get replicaset members: %v\n", err)
|
log.Warnf("[Error] cannot get replicaset members: %v\n", err)
|
||||||
os.Exit(2)
|
os.Exit(cannotGetReplicasetMembers)
|
||||||
}
|
}
|
||||||
log.Debugf("replicaMembers:\n%+v\n", ci.ReplicaMembers)
|
log.Debugf("replicaMembers:\n%+v\n", ci.ReplicaMembers)
|
||||||
|
|
||||||
@@ -270,10 +276,9 @@ func main() {
|
|||||||
out, err := formatResults(ci, opts.OutputFormat)
|
out, err := formatResults(ci, opts.OutputFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Cannot format the results: %s", err.Error())
|
log.Errorf("Cannot format the results: %s", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(cannotFormatResults)
|
||||||
}
|
}
|
||||||
fmt.Println(string(out))
|
fmt.Println(string(out))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatResults(ci *collectedInfo, format string) ([]byte, error) {
|
func formatResults(ci *collectedInfo, format string) ([]byte, error) {
|
||||||
|
Reference in New Issue
Block a user