-
Notifications
You must be signed in to change notification settings - Fork 0
fest: create basic script for index drift detection and elimination #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
8c2da24
build: init project
masontikhonov 872ab6b
feat: add `dump` command
masontikhonov 293d10d
build: add dump of prod indexes
masontikhonov f1afb74
build: clear indexes before dump
masontikhonov 1293ee8
refactor: improve logs
masontikhonov a9022f4
refactor: add newline in the end of the dump
masontikhonov a02cf6a
feat: add `compare` and `sync` commands
masontikhonov 0e6ffb7
docs: add docs
masontikhonov 09c1ee7
build: add Dockerfile
masontikhonov 8370430
tests: add `sync` tests
masontikhonov 40641f0
ci: add pipeline yaml
masontikhonov 607a10d
refactor: cleanup classic indexes
masontikhonov ff982ed
refactor: fix typo
masontikhonov 5d01e6c
feat: add `--force` flag
masontikhonov a2f43dd
ci: update pipeline
masontikhonov e61aede
ci: fix pipeline, update docs
masontikhonov 581ba1b
ci: fix repo in package.json
masontikhonov dc88d1f
docs: improve `--db-map` help
masontikhonov 0322b83
docs: improve `sync` documentation
masontikhonov e77b9f5
ci: remove redundant pipeline
masontikhonov ddb4937
docs: document `isIndexEqual()`
masontikhonov 72cc473
docs: document Logger behavior
masontikhonov 2d6504c
docs: document `syncIndexes()` function
masontikhonov 6b6e395
Revert "ci: remove redundant pipeline"
masontikhonov 9e0b29e
test: fix tests
masontikhonov c835a82
ci: fix test coverage scprit
masontikhonov 429d6b2
build: bump `mongodb`
masontikhonov 010676a
ci: build `amd64/arm64` image
masontikhonov bced08d
build: add full dump
masontikhonov ff21a60
feat: add `stats` command
masontikhonov 9fa88ab
fix(stats): fix getting oldest doc
masontikhonov 4f49f2e
remove legacy databases
mikhail-klimko cd9f060
remove legacy databases
mikhail-klimko 2372aae
feat: add planCache stats
masontikhonov cd817f0
feat(stats): add indexStats stats
masontikhonov 7fd249f
feat: update index dump
masontikhonov ae29f40
refactor: reorganize code
masontikhonov d29792e
feat: add default DB mapping `google_production=codefresh`
masontikhonov ab90d64
feat: add ignore overrides
masontikhonov 5000088
feat: add ignore-list for classic
masontikhonov b4b118c
fix: fix comparison for abscent DBs
masontikhonov a84bc58
fix: improve ignorelists
masontikhonov a6f9db9
feat: ignore `payments` db
masontikhonov 0796a89
fix: map `charts-manager`
masontikhonov 1763ea1
fix: map `kubernetes-monitor`
masontikhonov f5a9ca1
fix: ingnore build TTL indexes in target DB
masontikhonov 70f3516
fix: ignore `payments-accounts-archive` in dump
masontikhonov 77ec04a
feat: extend “heavy collections” list
masontikhonov 3969d53
refactor: rename variables
masontikhonov c2c9c24
docs: improve docs
masontikhonov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
|
|
||
| [*.{js,json,yml}] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 |
This file contains hidden or 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,4 @@ | ||
| /.yarn/** linguist-vendored | ||
| /.yarn/releases/* binary | ||
| /.yarn/plugins/**/* binary | ||
| /.pnp.* binary linguist-generated |
This file contains hidden or 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,134 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| lerna-debug.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # Diagnostic reports (https://nodejs.org/api/report.html) | ||
| report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
|
||
| # Runtime data | ||
| pids | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # Directory for instrumented libs generated by jscoverage/JSCover | ||
| lib-cov | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage | ||
| *.lcov | ||
|
|
||
| # nyc test coverage | ||
| .nyc_output | ||
|
|
||
| # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
| .grunt | ||
|
|
||
| # Bower dependency directory (https://bower.io/) | ||
| bower_components | ||
|
|
||
| # node-waf configuration | ||
| .lock-wscript | ||
|
|
||
| # Compiled binary addons (https://nodejs.org/api/addons.html) | ||
| build/Release | ||
|
|
||
| # Dependency directories | ||
| node_modules/ | ||
| jspm_packages/ | ||
|
|
||
| # Snowpack dependency directory (https://snowpack.dev/) | ||
| web_modules/ | ||
|
|
||
| # TypeScript cache | ||
| *.tsbuildinfo | ||
|
|
||
| # Optional npm cache directory | ||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
| .eslintcache | ||
|
|
||
| # Optional stylelint cache | ||
| .stylelintcache | ||
|
|
||
| # Microbundle cache | ||
| .rpt2_cache/ | ||
| .rts2_cache_cjs/ | ||
| .rts2_cache_es/ | ||
| .rts2_cache_umd/ | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # parcel-bundler cache (https://parceljs.org/) | ||
| .cache | ||
| .parcel-cache | ||
|
|
||
| # Next.js build output | ||
| .next | ||
| out | ||
|
|
||
| # Nuxt.js build / generate output | ||
| .nuxt | ||
| dist | ||
|
|
||
| # Gatsby files | ||
| .cache/ | ||
| # Comment in the public line in if your project uses Gatsby and not Next.js | ||
| # https://nextjs.org/blog/next-9-1#public-directory-support | ||
| # public | ||
|
|
||
| # vuepress build output | ||
| .vuepress/dist | ||
|
|
||
| # vuepress v2.x temp and cache directory | ||
| .temp | ||
| .cache | ||
|
|
||
| # Docusaurus cache and generated files | ||
| .docusaurus | ||
|
|
||
| # Serverless directories | ||
| .serverless/ | ||
|
|
||
| # FuseBox cache | ||
| .fusebox/ | ||
|
|
||
| # DynamoDB Local files | ||
| .dynamodb/ | ||
|
|
||
| # TernJS port file | ||
| .tern-port | ||
|
|
||
| # Stores VSCode versions used for testing VSCode extensions | ||
| .vscode-test | ||
|
|
||
| # yarn v2 | ||
| .yarn/cache | ||
| .yarn/unplugged | ||
| .yarn/build-state.yml | ||
| .yarn/install-state.gz | ||
| .pnp.* | ||
|
|
||
| !indexes/** | ||
|
|
||
| .DS_Store |
This file contains hidden or 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 @@ | ||
| v22 |
This file contains hidden or 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 @@ | ||
| nodeLinker: node-modules |
This file contains hidden or 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,21 @@ | ||
| FROM node:22-alpine AS base | ||
| WORKDIR /app | ||
| RUN corepack enable | ||
| COPY package.json yarn.lock .yarnrc.yml ./ | ||
|
|
||
| FROM base AS build | ||
| COPY . . | ||
| RUN yarn workspaces focus --all \ | ||
| && yarn build | ||
|
|
||
| FROM base AS prod-dependencies | ||
| RUN yarn workspaces focus --all --production | ||
|
|
||
| FROM base AS production | ||
| COPY --chown=node:node package.json . | ||
| COPY --chown=node:node --from=prod-dependencies /app/node_modules ./node_modules | ||
| COPY --chown=node:node --from=build /app/dist ./dist | ||
| COPY --chown=node:node ./indexes ./indexes | ||
|
|
||
| USER node | ||
| ENTRYPOINT ["node", "dist/index.js"] |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,101 @@ | ||
| # index-alignment | ||
| # Codefresh index alignment | ||
|
|
||
| ## Usage | ||
|
|
||
| ```shell | ||
| docker run quay.io/codefresh/index-alignment:<version> --help | ||
| ``` | ||
| ``` | ||
| Options: | ||
| -h, --help display help for command | ||
|
|
||
| Commands: | ||
| dump [options] [Internal] Dump all indexes from a MongoDB instance | ||
| stats [options] Get stats for all collections from a MongoDB instance | ||
| compare [options] Compare indexes from a target MongoDB instance with a recommended dump | ||
| sync [options] 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 | ||
| help [command] display help for command | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ### Commands | ||
|
|
||
| ## `compare` | ||
|
|
||
| Compare indexes from a target MongoDB instance with a recommended dump. | ||
|
|
||
| All logs are written to the STDERR stream, so they can be easily separated from the actual output, which is written to STDOUT. | ||
|
|
||
| We recommend redirecting the output of `compare` command to JSON file. | ||
|
|
||
| > [!IMPORTANT] | ||
| > The credentials under which the command is run must have read access to all databases controlled by Codefresh. | ||
|
|
||
| ``` | ||
| Options: | ||
| -p, --product <product> Codefresh product: classic | gitops | ||
| -u, --uri <uri> MongoDB URI | ||
| -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"]) | ||
| -h, --help display help for command | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| ```shell | ||
| docker run quay.io/codefresh/index-alignment:<version> compare --product "classic" --uri "<db-uri>" > classic-diff.json | ||
|
|
||
| docker run quay.io/codefresh/index-alignment:<version> compare --product "gitops" --uri "<db-uri>" > gitops-diff.json | ||
| ``` | ||
|
|
||
| ## `stats` | ||
|
|
||
| Get stats for all collections from a MongoDB instance. Following commands will be executed: | ||
|
|
||
| * `dbStats` command ([doc](https://www.mongodb.com/docs/v5.0/reference/command/dbStats/)); | ||
|
|
||
| * `$collStats` aggregation ([doc](https://www.mongodb.com/docs/v5.0/reference/operator/aggregation/collStats/)); | ||
|
|
||
| * `$planCacheStats` aggregation ([doc](https://www.mongodb.com/docs/v5.0/reference/operator/aggregation/plancachestats/)); | ||
|
|
||
| * queries `_id` of the oldest doc in each collection. | ||
|
|
||
| > [!IMPORTANT] | ||
| > The credentials under which the command is run must have permissions to execute the commands specified above. | ||
|
|
||
| All logs are written to the STDERR stream, so they can be easily separated from the actual output, which is written to STDOUT. | ||
|
|
||
| We recommend redirecting the output of `stats` command to JSON file. | ||
|
|
||
| ``` | ||
| Options: | ||
| -u, --uri <uri> MongoDB URI | ||
| -h, --help display help for command | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| ```shell | ||
| docker run quay.io/codefresh/index-alignment:<version> stats --uri "<db-uri>" > db-stats.json | ||
| ``` | ||
|
|
||
| ## `sync` | ||
|
|
||
| > [!CAUTION] | ||
| > This command changes indexes in the target DB, which may have performance impact. | ||
| > | ||
| > 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. | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
| ``` | ||
| Options: | ||
| -p, --product <product> Codefresh product: classic | gitops | ||
| -u, --uri <uri> MongoDB URI | ||
| -f --force Create indexes even on heavily populated collections, which may take a while | ||
| -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"]) | ||
| -h, --help display help for command | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.