|
1 | | -# index-alignment |
| 1 | +# Codefresh index alignment |
| 2 | + |
| 3 | +## Usage |
| 4 | + |
| 5 | +```shell |
| 6 | +docker run quay.io/codefresh/index-alignment:<version> --help |
| 7 | +``` |
| 8 | +``` |
| 9 | +Options: |
| 10 | + -h, --help display help for command |
| 11 | +
|
| 12 | +Commands: |
| 13 | + dump [options] [Internal] Dump all indexes from a MongoDB instance |
| 14 | + stats [options] Get stats for all collections from a MongoDB instance |
| 15 | + compare [options] Compare indexes from a target MongoDB instance with a recommended dump |
| 16 | + sync [options] Sync indexes from a recommended dump with a target MongoDB instance. The command |
| 17 | + will fail if it is required to create indexes on heavily populated collections and |
| 18 | + the `--force` flag has not been specified |
| 19 | + help [command] display help for command |
| 20 | +``` |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +### Commands |
| 25 | + |
| 26 | +## `compare` |
| 27 | + |
| 28 | +Compare indexes from a target MongoDB instance with a recommended dump. |
| 29 | + |
| 30 | +All logs are written to the STDERR stream, so they can be easily separated from the actual output, which is written to STDOUT. |
| 31 | + |
| 32 | +We recommend redirecting the output of `compare` command to JSON file. |
| 33 | + |
| 34 | +> [!IMPORTANT] |
| 35 | +> The credentials under which the command is run must have read access to all databases controlled by Codefresh. |
| 36 | +
|
| 37 | +``` |
| 38 | +Options: |
| 39 | + -p, --product <product> Codefresh product: classic | gitops |
| 40 | + -u, --uri <uri> MongoDB URI |
| 41 | + -m --db-map [dump-db-name=target-db-name...] Map the databases in the dump with the target databases. We have our own naming convention for the production databases, but it is up to the customers to name their databases (default: ["google_production=codefresh","chart-manager=charts-manager","kubernetes-monitor=k8s-monitor"]) |
| 42 | + -h, --help display help for command |
| 43 | +``` |
| 44 | + |
| 45 | +Example: |
| 46 | + |
| 47 | +```shell |
| 48 | +docker run quay.io/codefresh/index-alignment:<version> compare --product "classic" --uri "<db-uri>" > classic-diff.json |
| 49 | + |
| 50 | +docker run quay.io/codefresh/index-alignment:<version> compare --product "gitops" --uri "<db-uri>" > gitops-diff.json |
| 51 | +``` |
| 52 | + |
| 53 | +## `stats` |
| 54 | + |
| 55 | +Get stats for all collections from a MongoDB instance. Following commands will be executed: |
| 56 | + |
| 57 | +* `dbStats` command ([doc](https://www.mongodb.com/docs/v5.0/reference/command/dbStats/)); |
| 58 | + |
| 59 | +* `$collStats` aggregation ([doc](https://www.mongodb.com/docs/v5.0/reference/operator/aggregation/collStats/)); |
| 60 | + |
| 61 | +* `$planCacheStats` aggregation ([doc](https://www.mongodb.com/docs/v5.0/reference/operator/aggregation/plancachestats/)); |
| 62 | + |
| 63 | +* queries `_id` of the oldest doc in each collection. |
| 64 | + |
| 65 | +> [!IMPORTANT] |
| 66 | +> The credentials under which the command is run must have permissions to execute the commands specified above. |
| 67 | +
|
| 68 | +All logs are written to the STDERR stream, so they can be easily separated from the actual output, which is written to STDOUT. |
| 69 | + |
| 70 | +We recommend redirecting the output of `stats` command to JSON file. |
| 71 | + |
| 72 | +``` |
| 73 | +Options: |
| 74 | + -u, --uri <uri> MongoDB URI |
| 75 | + -h, --help display help for command |
| 76 | +``` |
| 77 | + |
| 78 | +Example: |
| 79 | + |
| 80 | +```shell |
| 81 | +docker run quay.io/codefresh/index-alignment:<version> stats --uri "<db-uri>" > db-stats.json |
| 82 | +``` |
| 83 | + |
| 84 | +## `sync` |
| 85 | + |
| 86 | +> [!CAUTION] |
| 87 | +> This command changes indexes in the target DB, which may have performance impact. |
| 88 | +> |
| 89 | +> We strongly advice to NOT use this command against production DB because of possible performance impact. Instead, use `compare` command to get the diff, then consider eliminating index diff manually during maintainance window. |
| 90 | +
|
| 91 | + |
| 92 | +Sync indexes from a recommended dump with a target MongoDB instance. The command will fail if it is required to create indexes on heavily populated collections and the `--force` flag has not been specified |
| 93 | + |
| 94 | +``` |
| 95 | +Options: |
| 96 | + -p, --product <product> Codefresh product: classic | gitops |
| 97 | + -u, --uri <uri> MongoDB URI |
| 98 | + -f --force Create indexes even on heavily populated collections, which may take a while |
| 99 | + -m --db-map [dump-db-name=target-db-name...] Map the databases in the dump with the target databases. We have our own naming convention for the production databases, but it is up to the customers to name their databases (default: ["google_production=codefresh","chart-manager=charts-manager","kubernetes-monitor=k8s-monitor"]) |
| 100 | + -h, --help display help for command |
| 101 | +``` |
0 commit comments