Skip to content
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

add a command line argument to validate the config and exit #1303

Merged
merged 22 commits into from
Feb 16, 2024

Conversation

Victor-M-Giraldo
Copy link
Contributor

closes #1297

Copy link
Contributor

coderabbitai bot commented Feb 8, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

This update introduces a new feature allowing users to validate their configuration files using a --validate command-line argument before the application proceeds with its main functionality. This ensures configurations are correct before deployment, enhancing reliability and preventing potential service disruptions in production environments.

Changes

Files Change Summary
server/app.ts Added conditional block for --validate CLI option

Assessment against linked issues

Objective Addressed Explanation
#1297: Add a --validate CLI argument to validate config and exit

Poem

In the field of green, under the bright lights,
Chiefs and 49ers in a dance of mights.
Amidst the clash, a rabbit hops with glee,
Celebrating code that sets the configs free.
🏈 "To validate," it cheers, "before the play,
Ensures our game runs smooth, come what may!"
Let's hop to victory, with code so bright,
On Super Bowl's eve, under the starlight. 🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 46 lines in your changes are missing coverage. Please review.

Comparison is base (9c169f8) 54.1528% compared to head (390983d) 54.0812%.

Files Patch % Lines
server/ott-config.ts 7.6923% 36 Missing ⚠️
server/app.ts 16.6666% 10 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##             master      #1303        +/-   ##
================================================
- Coverage   54.1528%   54.0812%   -0.0716%     
================================================
  Files           157        157                
  Lines         24634      24674        +40     
  Branches       1442       1443         +1     
================================================
+ Hits          13340      13344         +4     
- Misses        11238      11274        +36     
  Partials         56         56                

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Victor-M-Giraldo Victor-M-Giraldo marked this pull request as ready for review February 10, 2024 19:34
@dyc3

This comment was marked as outdated.

@Victor-M-Giraldo Victor-M-Giraldo changed the title cli arg monolith add a command line argument to validate the config and exit Feb 10, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e8ee382 and bca6118.
Files selected for processing (1)
  • server/app.ts (1 hunks)
Additional comments: 1
server/app.ts (1)
  • 57-65: Ensure that the rest of the application's initialization and shutdown processes are unaffected by the early exit introduced by the --validate flag. This includes verifying that no necessary cleanup or initialization steps are skipped that could lead to resource leaks or other issues when the application is used in normal operation mode.

server/app.ts Outdated Show resolved Hide resolved
server/app.ts Outdated Show resolved Hide resolved
@Victor-M-Giraldo Victor-M-Giraldo marked this pull request as draft February 10, 2024 22:09
server/app.ts Outdated Show resolved Hide resolved
@Victor-M-Giraldo
Copy link
Contributor Author

For clarification, what changes do you want with validateMail?

As is --validate works right now the way you described. Any keys defined that are not in the schema throw an error.

@dyc3
Copy link
Owner

dyc3 commented Feb 12, 2024

Think about the use case. I want to avoid deploying configs that break functionality.

Email is critical for letting users reset their passwords. Failing to have that properly configured so that it works (when it is desired by the deployer) is bad.

server/ott-config.ts Outdated Show resolved Hide resolved
@Victor-M-Giraldo
Copy link
Contributor Author

When using --validate it always exits with code 0 with these changes. I can't find out why. I feel like it's something simple I'm missing.

@dyc3
Copy link
Owner

dyc3 commented Feb 13, 2024

Make sure you are checking the Result. It wont throw an exception.

Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but could be better.

server/ott-config.ts Outdated Show resolved Hide resolved
server/ott-config.ts Show resolved Hide resolved
@Victor-M-Giraldo
Copy link
Contributor Author

Victor-M-Giraldo commented Feb 14, 2024

I think this is way better. I tested it and it looks good. The only problem I'm seeing is with repeat error messages for the mail config. It's because of this in postProcessConfig(). Is it alright if I get rid of that?

Also, the name for validateConf() kind of sucks and is confusing when compared to validateConfig(). Don't know what to rename it to though.

if (conf.get("mail.enabled")) {
		const result = validateMail();
		if (!result.ok) {
			conf.set("mail.enabled", false);
			log.error(result.value.message);
		}
	}

server/app.ts Outdated Show resolved Hide resolved
server/ott-config.ts Outdated Show resolved Hide resolved
server/ott-config.ts Outdated Show resolved Hide resolved
@Victor-M-Giraldo Victor-M-Giraldo marked this pull request as ready for review February 14, 2024 15:54
server/ott-config.ts Outdated Show resolved Hide resolved
server/ott-config.ts Outdated Show resolved Hide resolved
server/ott-config.ts Outdated Show resolved Hide resolved
server/ott-config.ts Show resolved Hide resolved
server/app.ts Outdated Show resolved Hide resolved
server/ott-config.ts Outdated Show resolved Hide resolved
@Victor-M-Giraldo
Copy link
Contributor Author

I don't know if it's better to make validateConfig() return a bool or a Result <T , E> to check the return value. Do you have thoughts on that?

server/ott-config.ts Outdated Show resolved Hide resolved
@dyc3 dyc3 enabled auto-merge (squash) February 16, 2024 22:35
@dyc3 dyc3 disabled auto-merge February 16, 2024 22:35
@dyc3 dyc3 merged commit 0274f95 into dyc3:master Feb 16, 2024
17 of 20 checks passed
Copy link

cypress bot commented Feb 16, 2024

Passing run #1005 ↗︎

0 73 1 0 Flakiness 0

Details:

add a command line argument to validate the config and exit (#1303)
Project: OpenTogetherTube Commit: 0274f95522
Status: Passed Duration: 03:11 💡
Started: Feb 16, 2024 10:59 PM Ended: Feb 16, 2024 11:02 PM

Review all test suite changes for PR #1303 ↗︎

dyc3 added a commit that referenced this pull request Feb 17, 2024
* attempt at adding --validate flag

* changed conf.validate level

* changed back level on validate

* moved conf.validate to try catch

* only load config once

* also take into account validating mail

* remove unused import

* fix lint

* make validateMail return result

* fix lint

* actually check result

* make validateMail read only

* add validateConf()

* change validateConfig()

* made requested changes

* remove unused func

* log correct error messages and correctly force sandbox mode

* fix lint

* validate before config is used for anything

* move process exit calls to app.ts

* changed return value of validateconfig to result

* add logs

---------

Co-authored-by: Carson McManus <[email protected]>
@Victor-M-Giraldo Victor-M-Giraldo deleted the cli-arg-monolith branch February 22, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

monolith: add a command line argument to simply validate the config and exit
2 participants