mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
PT-2235 - pt-mongodb-index-check does not support option --version (#653)
* PT-2235 - pt-mongodb-index-check does not support option --version Changed command version to flag version * PT-2235 - pt-mongodb-index-check does not support option --version Updated documentation
This commit is contained in:
@@ -67,4 +67,6 @@ Available flags
|
||||
+----------------------------+----------------------------------------+
|
||||
| –json | Show output as JSON |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –version | Show version information |
|
||||
+----------------------------+----------------------------------------+
|
||||
|
||||
|
@@ -1,48 +0,0 @@
|
||||
# pt-mongodb-index-check
|
||||
|
||||
|
||||
|
||||
## Introduction
|
||||
|
||||
This tool can perform checks on MongoDB indexes.
|
||||
|
||||
Currently, these checks are available:
|
||||
|
||||
### Duplicated indexes
|
||||
|
||||
Check for indexes that are the prefix of other indexes. For example if we have these 2 indexes
|
||||
|
||||
```
|
||||
db.getSiblingDB("testdb").test_col.createIndex({"f1": 1, "f2": -1, "f3": 1, "f4": 1}, {"name": "idx_01"});
|
||||
db.getSiblingDB("testdb").test_col.createIndex({"f1": 1, "f2": -1, "f3": 1}, {"name": "idx_02"});
|
||||
```
|
||||
|
||||
The index `idx_02` is the prefix of `idx_01` because it has the same keys in the same order so, `idx_02` can be dropped.
|
||||
|
||||
### Unused indexes.
|
||||
|
||||
This check gets the `$indexstats` for all indexes and reports those having `accesses.ops` = 0.
|
||||
|
||||
## Usage
|
||||
|
||||
Run the program as `pt-mongodb-index-check <command> [flags]`
|
||||
|
||||
#### Available commands
|
||||
|
||||
| Command | Description |
|
||||
| ---------------- | ---------------------------------- |
|
||||
| check-duplicated | Run checks for duplicated indexes. |
|
||||
| check-unused | Run check for unused indexes. |
|
||||
| check-all | Run all checks |
|
||||
|
||||
#### Available flags
|
||||
|
||||
| Flag | Description |
|
||||
| ---- | ----------- |
|
||||
|--all-databases|Check in all databases excluding system dbs.|
|
||||
|--databases=DATABASES,...|Comma separated list of databases to check.|
|
||||
|--all-collections|Check in all collections in the selected databases.|
|
||||
|--collections=COLLECTIONS,...|Comma separated list of collections to check.|
|
||||
|--mongodb.uri=<connection string>|Connection URI|
|
||||
|--json|Show output as JSON|
|
||||
|
72
src/go/pt-mongodb-index-check/README.rst
Normal file
72
src/go/pt-mongodb-index-check/README.rst
Normal file
@@ -0,0 +1,72 @@
|
||||
.. _pt-mongodb-index-check:
|
||||
|
||||
=================================
|
||||
:program:`pt-mongodb-index-check`
|
||||
=================================
|
||||
|
||||
Performs checks on MongoDB indexes.
|
||||
|
||||
Checks available
|
||||
================
|
||||
|
||||
Duplicated indexes
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Check for indexes that are the prefix of other indexes. For example if we have these 2 indexes
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
db.getSiblingDB("testdb").test_col.createIndex({"f1": 1, "f2": -1, "f3": 1, "f4": 1}, {"name": "idx_01"});
|
||||
db.getSiblingDB("testdb").test_col.createIndex({"f1": 1, "f2": -1, "f3": 1}, {"name": "idx_02"});
|
||||
|
||||
|
||||
The index ``idx_02`` is the prefix of ``idx_01`` because it has the same
|
||||
keys in the same order so, ``idx_02`` can be dropped.
|
||||
|
||||
Unused indexes.
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
This check gets the ``$indexstats`` for all indexes and reports those
|
||||
having ``accesses.ops`` = 0.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Run the program as ``pt-mongodb-index-check <command> [flags]``
|
||||
|
||||
Available commands
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
================ ==================================
|
||||
Command Description
|
||||
================ ==================================
|
||||
check-duplicated Run checks for duplicated indexes.
|
||||
check-unused Run check for unused indexes.
|
||||
check-all Run all checks
|
||||
================ ==================================
|
||||
|
||||
Available flags
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
+----------------------------+----------------------------------------+
|
||||
| Flag | Description |
|
||||
+============================+========================================+
|
||||
| –all-databases | Check in all databases excluding |
|
||||
| | system dbs. |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –databases=DATABASES,… | Comma separated list of databases to |
|
||||
| | check. |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –all-collections | Check in all collections in the |
|
||||
| | selected databases. |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –collections=COLLECTIONS,… | Comma separated list of collections to |
|
||||
| | check. |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –mongodb.uri= | Connection URI |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –json | Show output as JSON |
|
||||
+----------------------------+----------------------------------------+
|
||||
| –version | Show version information |
|
||||
+----------------------------+----------------------------------------+
|
||||
|
@@ -25,7 +25,7 @@ type cmdlineArgs struct {
|
||||
CheckDuplicated struct{} `cmd:"" name:"check-duplicates" help:"Check for duplicated indexes."`
|
||||
CheckAll struct{} `cmd:"" name:"check-all" help:"Check for unused and duplicated indexes."`
|
||||
ShowHelp struct{} `cmd:"" default:"1"`
|
||||
Version struct{} `cmd:"" name:"version"`
|
||||
Version kong.VersionFlag
|
||||
|
||||
AllDatabases bool `name:"all-databases" xor:"db" help:"Check in all databases excluding system dbs"`
|
||||
Databases []string `name:"databases" xor:"db" help:"Comma separated list of databases to check"`
|
||||
@@ -55,15 +55,9 @@ var (
|
||||
|
||||
func main() {
|
||||
var args cmdlineArgs
|
||||
kongctx := kong.Parse(&args, kong.UsageOnError())
|
||||
|
||||
if kongctx.Command() == "version" {
|
||||
fmt.Println(toolname)
|
||||
fmt.Printf("Version %s\n", Version)
|
||||
fmt.Printf("Build: %s using %s\n", Build, GoVersion)
|
||||
fmt.Printf("Commit: %s\n", Commit)
|
||||
return
|
||||
}
|
||||
kongctx := kong.Parse(&args, kong.UsageOnError(),
|
||||
kong.Vars{"version": fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s",
|
||||
toolname, Version, Build, GoVersion, Commit)})
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
22
src/go/pt-mongodb-index-check/main_test.go
Normal file
22
src/go/pt-mongodb-index-check/main_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
/*
|
||||
Option --version
|
||||
*/
|
||||
func TestVersionOption(t *testing.T) {
|
||||
out, err := exec.Command("../../../bin/"+toolname, "--version").Output()
|
||||
if err != nil {
|
||||
t.Errorf("error executing %s --version: %s", toolname, err.Error())
|
||||
}
|
||||
// We are using MustCompile here, because hard-coded RE should not fail
|
||||
re := regexp.MustCompile(toolname + `\n.*Version v?\d+\.\d+\.\d+\n`)
|
||||
if !re.Match(out) {
|
||||
t.Errorf("%s --version returns wrong result:\n%s", toolname, out)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user