Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8c2da24
build: init project
masontikhonov Feb 2, 2025
872ab6b
feat: add `dump` command
masontikhonov Feb 2, 2025
293d10d
build: add dump of prod indexes
masontikhonov Feb 2, 2025
f1afb74
build: clear indexes before dump
masontikhonov Feb 2, 2025
1293ee8
refactor: improve logs
masontikhonov Feb 2, 2025
a9022f4
refactor: add newline in the end of the dump
masontikhonov Feb 2, 2025
a02cf6a
feat: add `compare` and `sync` commands
masontikhonov Feb 11, 2025
0e6ffb7
docs: add docs
masontikhonov Feb 11, 2025
09c1ee7
build: add Dockerfile
masontikhonov Feb 11, 2025
8370430
tests: add `sync` tests
masontikhonov Feb 11, 2025
40641f0
ci: add pipeline yaml
masontikhonov Feb 11, 2025
607a10d
refactor: cleanup classic indexes
masontikhonov Mar 10, 2025
ff982ed
refactor: fix typo
masontikhonov Mar 16, 2025
5d01e6c
feat: add `--force` flag
masontikhonov Mar 16, 2025
a2f43dd
ci: update pipeline
masontikhonov Mar 16, 2025
e61aede
ci: fix pipeline, update docs
masontikhonov Mar 16, 2025
581ba1b
ci: fix repo in package.json
masontikhonov May 4, 2025
dc88d1f
docs: improve `--db-map` help
masontikhonov May 4, 2025
0322b83
docs: improve `sync` documentation
masontikhonov May 4, 2025
e77b9f5
ci: remove redundant pipeline
masontikhonov May 4, 2025
ddb4937
docs: document `isIndexEqual()`
masontikhonov May 4, 2025
72cc473
docs: document Logger behavior
masontikhonov May 4, 2025
2d6504c
docs: document `syncIndexes()` function
masontikhonov May 4, 2025
6b6e395
Revert "ci: remove redundant pipeline"
masontikhonov May 4, 2025
9e0b29e
test: fix tests
masontikhonov May 4, 2025
c835a82
ci: fix test coverage scprit
masontikhonov May 4, 2025
429d6b2
build: bump `mongodb`
masontikhonov May 4, 2025
010676a
ci: build `amd64/arm64` image
masontikhonov May 4, 2025
bced08d
build: add full dump
masontikhonov May 5, 2025
ff21a60
feat: add `stats` command
masontikhonov May 7, 2025
9fa88ab
fix(stats): fix getting oldest doc
masontikhonov May 7, 2025
4f49f2e
remove legacy databases
mikhail-klimko May 16, 2025
cd9f060
remove legacy databases
mikhail-klimko May 16, 2025
2372aae
feat: add planCache stats
masontikhonov May 18, 2025
cd817f0
feat(stats): add indexStats stats
masontikhonov May 21, 2025
7fd249f
feat: update index dump
masontikhonov May 28, 2025
ae29f40
refactor: reorganize code
masontikhonov Jun 2, 2025
d29792e
feat: add default DB mapping `google_production=codefresh`
masontikhonov Jun 3, 2025
ab90d64
feat: add ignore overrides
masontikhonov Jun 3, 2025
5000088
feat: add ignore-list for classic
masontikhonov Jun 3, 2025
b4b118c
fix: fix comparison for abscent DBs
masontikhonov Jun 3, 2025
a84bc58
fix: improve ignorelists
masontikhonov Jun 3, 2025
a6f9db9
feat: ignore `payments` db
masontikhonov Jun 4, 2025
0796a89
fix: map `charts-manager`
masontikhonov Jun 4, 2025
1763ea1
fix: map `kubernetes-monitor`
masontikhonov Jun 5, 2025
f5a9ca1
fix: ingnore build TTL indexes in target DB
masontikhonov Jun 5, 2025
70f3516
fix: ignore `payments-accounts-archive` in dump
masontikhonov Jun 5, 2025
77ec04a
feat: extend “heavy collections” list
masontikhonov Jun 5, 2025
3969d53
refactor: rename variables
masontikhonov Jun 30, 2025
c2c9c24
docs: improve docs
masontikhonov Jun 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
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
4 changes: 4 additions & 0 deletions .gitattributes
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
134 changes: 134 additions & 0 deletions .gitignore
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
21 changes: 21 additions & 0 deletions Dockerfile
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"]
102 changes: 101 additions & 1 deletion README.md
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
```
Loading