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

Config files #97

Merged
merged 3 commits into from
Feb 17, 2024
Merged

Config files #97

merged 3 commits into from
Feb 17, 2024

Conversation

nylonee
Copy link
Owner

@nylonee nylonee commented Feb 16, 2024

We want to change up how we provide config in Watchlistarr. This paves the way for:

  1. Providing an API to allow dynamic configuration changes
  2. Making it easier to maintain and share config

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration utility to enhance reading settings from YAML files, supporting the creation of default templates and flattening nested structures.
    • Added SnakeYAML library dependency to assist with YAML file operations.
  • Improvements
    • Improved server configuration handling by updating the method for configuration updates and utilizing a more comprehensive property reader.
  • Refactor
    • Modified Dockerfile commands order for a more efficient multi-stage build process.
  • Chores
    • Updated .gitignore to exclude the config/ directory from version control.

Copy link

coderabbitai bot commented Feb 16, 2024

Warning

Rate Limit Exceeded

@nylonee has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 minutes and 59 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between f1913cd and 84e1c9b.

Walkthrough

The project has seen updates across configuration management, build dependencies, and Docker optimization. Notably, the handling of configuration settings has been refined with a new approach to reading from both system properties and files, improving flexibility and reliability. Additionally, a dependency on SnakeYAML has been introduced for YAML parsing, and the Dockerfile has been optimized for a more efficient build process.

Changes

File(s) Summary of Changes
.gitignore, docker/Dockerfile Ignored config/ directory in .gitignore. Reordered COPY and RUN commands in Dockerfile for optimization.
build.sbt Added SnakeYAML library dependency, version 2.0.
src/main/scala/Server.scala Updated to use FileAndSystemPropertyReader, changed configuration handling to Ref[IO, Configuration].
src/main/scala/configuration/...PropertyReader.scala Introduced FileAndSystemPropertyReader for YAML config file reading, updated SystemPropertyReader.

🐰✨
In the code's warren, beneath the digital sky,
A change was made, with a soft, contented sigh.
Configs now dance, with a YAML-flavored twist,
Through Docker's layers, like morning mist.
"To efficiency and clarity!" the rabbit did decree,
Hopping away, as happy as can be.
🌟📜🚀

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

@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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8394741 and 4d3c205.
Files ignored due to path filters (1)
  • src/main/resources/config-template.yaml is excluded by: !**/*.yaml
Files selected for processing (6)
  • .gitignore (1 hunks)
  • build.sbt (2 hunks)
  • docker/Dockerfile (1 hunks)
  • src/main/scala/Server.scala (2 hunks)
  • src/main/scala/configuration/FileAndSystemPropertyReader.scala (1 hunks)
  • src/main/scala/configuration/SystemPropertyReader.scala (1 hunks)
Additional comments: 4
src/main/scala/configuration/SystemPropertyReader.scala (1)
  • 4-4: The implementation of getConfigOption correctly overrides the method from ConfigurationReader and safely wraps the system property lookup in an Option, which is a good practice for handling potentially null values from Java APIs in Scala.
build.sbt (1)
  • 19-25: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-44]

The addition of SnakeYAML version 2.0 as a dependency in build.sbt aligns with the PR's objectives of enhancing configuration management through YAML file parsing. Ensure that this version is compatible with the project's Scala version and other dependencies.

src/main/scala/Server.scala (2)
  • 4-4: Replacing SystemPropertyReader with FileAndSystemPropertyReader in the import statement aligns with the PR's objectives of enhancing configuration management by reading from both system properties and YAML files.
  • 21-30: The changes to directly return IO[Configuration] and update method parameters to accept Ref[IO, Configuration] are good practices in functional programming. They simplify the code and improve the handling of real-time configuration updates, aligning with the PR's objectives.

docker/Dockerfile Show resolved Hide resolved
Comment on lines +15 to +52
private lazy val data: Map[String, String] = {
val yaml = new Yaml()
val configDirPath = "config"
val configFile = new File(s"$configDirPath/config.yaml")

try {
// Ensure parent config folder exists
val parentDir = configFile.getParentFile
if (!parentDir.exists()) parentDir.mkdirs()

if (!configFile.exists()) {
val resourceStream = getClass.getClassLoader.getResourceAsStream("config-template.yaml")
if (resourceStream != null) {
try {
Files.copy(resourceStream, Paths.get(configFile.toURI), StandardCopyOption.REPLACE_EXISTING)
logger.info(s"Created config file in ${configFile.getPath}")
} finally {
resourceStream.close()
}
} else {
logger.debug("config-template.yaml resource not found")
}
}

if (configFile.exists()) {
val inputStream = new FileInputStream(configFile)
val result = yaml.load[util.Map[String, Object]](inputStream).asScala
inputStream.close()
flattenYaml(Map.from(result))
} else {
Map.empty[String, String]
}
} catch {
case e: Exception =>
logger.debug(s"Failed to read from config.yaml: ${e.getMessage}")
Map.empty[String, String]
}
}
Copy link

Choose a reason for hiding this comment

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

The implementation of configuration reading from YAML files and system properties in FileAndSystemPropertyReader is well-structured and aligns with the PR's objectives. Consider using Scala's Using trait or a similar pattern for resource management to ensure that resources like file streams are always properly closed, even in the case of exceptions.

- val inputStream = new FileInputStream(configFile)
- val result = yaml.load[util.Map[String, Object]](inputStream).asScala
- inputStream.close()
+ Using.resource(new FileInputStream(configFile)) { inputStream =>
+   val result = yaml.load[util.Map[String, Object]](inputStream).asScala
+   // Processing continues here
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
private lazy val data: Map[String, String] = {
val yaml = new Yaml()
val configDirPath = "config"
val configFile = new File(s"$configDirPath/config.yaml")
try {
// Ensure parent config folder exists
val parentDir = configFile.getParentFile
if (!parentDir.exists()) parentDir.mkdirs()
if (!configFile.exists()) {
val resourceStream = getClass.getClassLoader.getResourceAsStream("config-template.yaml")
if (resourceStream != null) {
try {
Files.copy(resourceStream, Paths.get(configFile.toURI), StandardCopyOption.REPLACE_EXISTING)
logger.info(s"Created config file in ${configFile.getPath}")
} finally {
resourceStream.close()
}
} else {
logger.debug("config-template.yaml resource not found")
}
}
if (configFile.exists()) {
val inputStream = new FileInputStream(configFile)
val result = yaml.load[util.Map[String, Object]](inputStream).asScala
inputStream.close()
flattenYaml(Map.from(result))
} else {
Map.empty[String, String]
}
} catch {
case e: Exception =>
logger.debug(s"Failed to read from config.yaml: ${e.getMessage}")
Map.empty[String, String]
}
}
private lazy val data: Map[String, String] = {
val yaml = new Yaml()
val configDirPath = "config"
val configFile = new File(s"$configDirPath/config.yaml")
try {
// Ensure parent config folder exists
val parentDir = configFile.getParentFile
if (!parentDir.exists()) parentDir.mkdirs()
if (!configFile.exists()) {
val resourceStream = getClass.getClassLoader.getResourceAsStream("config-template.yaml")
if (resourceStream != null) {
try {
Files.copy(resourceStream, Paths.get(configFile.toURI), StandardCopyOption.REPLACE_EXISTING)
logger.info(s"Created config file in ${configFile.getPath}")
} finally {
resourceStream.close()
}
} else {
logger.debug("config-template.yaml resource not found")
}
}
if (configFile.exists()) {
Using.resource(new FileInputStream(configFile)) { inputStream =>
val result = yaml.load[util.Map[String, Object]](inputStream).asScala
// Processing continues here
}
} else {
Map.empty[String, String]
}
} catch {
case e: Exception =>
logger.debug(s"Failed to read from config.yaml: ${e.getMessage}")
Map.empty[String, String]
}
}

@@ -0,0 +1,40 @@
## Watchlistarr Configuration
Copy link
Owner Author

Choose a reason for hiding this comment

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

Let's add more meat into this, and trim down the README

Copy link

@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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4d3c205 and f1913cd.
Files ignored due to path filters (1)
  • src/main/resources/config-template.yaml is excluded by: !**/*.yaml
Files selected for processing (1)
  • README.md (3 hunks)
Files skipped from review due to trivial changes (1)
  • README.md

@nylonee nylonee merged commit bd0236a into main Feb 17, 2024
2 checks passed
@nylonee nylonee deleted the config-file branch February 17, 2024 14:17
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.

None yet

1 participant