Merge pull request #1013 from percona/PMM-11406-percona-toolkit-update

PMM-11406 Better check to prevent errors from missing fields.
This commit is contained in:
Sveta Smirnova
2025-11-12 21:41:55 +03:00
committed by GitHub
13 changed files with 60 additions and 59 deletions

View File

@@ -8731,7 +8731,7 @@ type: string; default: Query
group: Actions
Comma sepatated list of commands that will be watched/killed if they ran for
Comma separated list of commands that will be watched/killed if they ran for
more than L<"--busy-time"> seconds. Default: C<Query>
By default, L<"--busy-time"> kills only C<Query> commands but in some cases, it

View File

@@ -11668,7 +11668,7 @@ sub check_orig_table {
Cxn => $cxn,
tbl => $orig_tbl,
chunk_size => $o->get('chunk-size'),
chunk_indx => $o->get('chunk-index'),
chunk_index => $o->get('chunk-index'),
OptionParser => $o,
TableParser => $tp,
);
@@ -13512,7 +13512,7 @@ New rows will use the user defined default value if specified for the column.
=item --only-same-schema-fks
Check foreigns keys only on tables on the same schema than the original table.
This option is dangerous since if you have FKs refenrencing tables in other
This option is dangerous since if you have FKs referencing tables in other
schemas, they won't be detected.

View File

@@ -6239,7 +6239,7 @@ sub _get_value {
unless $found_value;
}
else {
die "Event does not have attribute $attrib and there are no alterantes";
die "Event does not have attribute $attrib and there are no alternates";
}
return $value;

View File

@@ -12591,7 +12591,7 @@ sub create_repl_table {
#
# Required Arguments:
# * tbl - Standard tbl hashref
# * sth - Sth with EXLAIN <statement>
# * sth - Sth with EXPLAIN <statement>
# * vals - Values for sth, if any
#
# Returns:

View File

@@ -6082,7 +6082,7 @@ as tmp_table_size.
severity: warn
These are the recommended minimum version for each major release: 3.23, 4.1.20,
5.0.37, 5.1.30, 5.5.8, 5.6.10, 5.7.9, 8.0.11. This optiion does not complain
5.0.37, 5.1.30, 5.5.8, 5.6.10, 5.7.9, 8.0.11. This option does not complain
about Innovation releases.
=item end-of-life mysql version

View File

@@ -20,7 +20,7 @@
{
# Package: Diskstats
# This package implements most of the logic in the old shell pt-diskstats;
# it parses data from /proc/diskstats, calculcates deltas, and prints those.
# it parses data from /proc/diskstats, calculates deltas, and prints those.
package Diskstats;

View File

@@ -1193,7 +1193,7 @@ sub _get_value {
unless $found_value;
}
else {
die "Event does not have attribute $attrib and there are no alterantes";
die "Event does not have attribute $attrib and there are no alternates";
}
return $value;

View File

@@ -1254,7 +1254,7 @@ sub remove_functions {
# GROUP BY and ORDER BY specify a list of identifiers.
#
# Parameters:
# $idents - Arrayref of indentifiers
# $idents - Arrayref of identifiers
#
# Returns:
# Arrayref of hashes with each identifier's parts, depending on what kind

View File

@@ -79,8 +79,8 @@ sub new {
#
# TCP requests and responses form "sessions", which can be in one of these
# statuses:
# [Q]uerying - The remote host is sending the query to the server.
# [R]esponding - The server is replying back to the remote host.
# Querying - The remote host is sending the query to the server.
# Responding - The server is replying back to the remote host.
sub parse_event {
my ( $self, %args ) = @_;
my @required_args = qw(next_event tell);

View File

@@ -178,7 +178,7 @@ sub parse_event {
# Otherwise, we need to compute the running sums and keep looping.
else {
if ( $self->{in_prg} ) {
# $self->{current_ts} is intitially 0, which would seem likely to
# $self->{current_ts} is initially 0, which would seem likely to
# skew this computation. But $self->{in_prg} will be 0 also, and
# $self->{current_ts} will get set immediately after this, so
# anytime this if() block runs, it'll be OK.

View File

@@ -460,7 +460,7 @@ sub pingback {
# If the server has suggestions for items, it sends them back in
# the same format: ITEM:TYPE:SUGGESTION\n. ITEM:TYPE is mostly for
# debugging; the tool just repports the suggestions.
# debugging; the tool just reports the suggestions.
$items = parse_server_response(
response => $response->{content},
split_vars => 0,

View File

@@ -208,7 +208,7 @@ func main() {
if err != nil {
log.Infof("cannot check version updates: %s", err.Error())
} else if advice != "" {
log.Infof(advice)
log.Infof("%s", advice)
}
}
@@ -373,24 +373,6 @@ func getHostInfo(ctx context.Context, client *mongo.Client) (*hostInfo, error) {
return nil, errors.Wrap(err, "GetHostInfo.hostInfo")
}
cmdOpts := proto.CommandLineOptions{}
query := primitive.D{{Key: "getCmdLineOpts", Value: 1}}
err := client.Database("admin").RunCommand(ctx, query).Decode(&cmdOpts)
if err != nil {
return nil, errors.Wrap(err, "cannot get command line options")
}
ss := proto.ServerStatus{}
query = primitive.D{{Key: "serverStatus", Value: 1}}
if err := client.Database("admin").RunCommand(ctx, query).Decode(&ss); err != nil {
return nil, errors.Wrap(err, "GetHostInfo.serverStatus")
}
pi := procInfo{}
if err := getProcInfo(int32(ss.Pid), &pi); err != nil {
pi.Error = err
}
nodeType, _ := getNodeType(ctx, client)
procCount, _ := countMongodProcesses()
@@ -398,24 +380,41 @@ func getHostInfo(ctx context.Context, client *mongo.Client) (*hostInfo, error) {
Hostname: hi.System.Hostname,
HostOsType: hi.Os.Type,
HostSystemCPUArch: hi.System.CpuArch,
DBPath: "", // Sets default. It will be overridden later if necessary
ProcessName: ss.Process,
ProcProcessCount: procCount,
Version: ss.Version,
NodeType: nodeType,
ProcPath: pi.Path,
ProcUserName: pi.UserName,
ProcCreateTime: pi.CreateTime,
CmdlineArgs: cmdOpts.Argv,
}
if ss.Repl != nil {
i.ReplicasetName = ss.Repl.SetName
ProcProcessCount: procCount,
NodeType: nodeType,
CmdlineArgs: nil,
}
if cmdOpts.Parsed.Storage.DbPath != "" {
i.DBPath = cmdOpts.Parsed.Storage.DbPath
var cmdOpts proto.CommandLineOptions
query := primitive.D{{Key: "getCmdLineOpts", Value: 1}}
err := client.Database("admin").RunCommand(ctx, query).Decode(&cmdOpts)
if err == nil {
if len(cmdOpts.Argv) > 0 {
i.CmdlineArgs = cmdOpts.Argv
}
if cmdOpts.Parsed.Storage.DbPath != "" {
i.DBPath = cmdOpts.Parsed.Storage.DbPath
}
}
var ss proto.ServerStatus
query = primitive.D{{Key: "serverStatus", Value: 1}}
err = client.Database("admin").RunCommand(ctx, query).Decode(&ss)
if err == nil {
i.ProcessName = ss.Process
i.Version = ss.Version
if ss.Repl != nil {
i.ReplicasetName = ss.Repl.SetName
}
pi := procInfo{}
if err := getProcInfo(int32(ss.Pid), &pi); err != nil {
pi.Error = err
} else {
i.ProcPath = pi.Path
i.ProcUserName = pi.UserName
i.ProcCreateTime = pi.CreateTime
}
}
return i, nil

View File

@@ -8,9 +8,9 @@ import (
"time"
"github.com/pborman/getopt"
"github.com/stretchr/testify/require"
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
)
func TestGetHostInfo(t *testing.T) {
@@ -49,6 +49,18 @@ func TestGetHostInfo(t *testing.T) {
}
}
func TestGetHostInfoResult(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
client, err := tu.TestClient(ctx, tu.MongoDBShard1PrimaryPort)
require.NoError(t, err, "cannot get a new MongoDB client")
host, err := getHostInfo(ctx, client)
require.NoError(t, err, "getHostInfo error")
require.NotEmpty(t, host)
}
func TestClusterWideInfo(t *testing.T) {
testCases := []struct {
name string
@@ -85,16 +97,6 @@ func TestClusterWideInfo(t *testing.T) {
}
}
func addToCounters(ss proto.ServerStatus, increment int64) proto.ServerStatus {
ss.Opcounters.Command += increment
ss.Opcounters.Delete += increment
ss.Opcounters.GetMore += increment
ss.Opcounters.Insert += increment
ss.Opcounters.Query += increment
ss.Opcounters.Update += increment
return ss
}
func TestParseArgs(t *testing.T) {
tests := []struct {
args []string