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

refactor(config): refactor config package #6782

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

grandwizard28
Copy link
Collaborator

@grandwizard28 grandwizard28 commented Jan 8, 2025

Summary

refactor config package and get rid of upstream dependency on opentelemetry-collector


Important

Refactor configuration package to remove opentelemetry-collector dependency, introduce new SQL store with migrations, and update server initialization.

  • Configuration Refactor:
    • Replaces opentelemetry-collector dependency with koanf and viper for configuration management.
    • Introduces pkg/config for configuration handling with support for environment and file providers.
    • Adds pkg/signoz for managing application-wide configuration.
  • Database and Migrations:
    • Implements new SQL store in pkg/sqlstore with migration support using bun.
    • Adds migration files in pkg/sqlstore/migrations for various components like agents, dashboards, and integrations.
    • Refactors database initialization in dao/factory.go and dao/sqlite/connection.go to use new SQL store.
  • Server and Application Changes:
    • Updates server.go to use new configuration and SQL store.
    • Refactors logparsingpipeline and opamp components to align with new configuration and database setup.
    • Removes old migration logic from migrate/migate.go.

This description was created by Ellipsis for 2060905. It will automatically update as commits are pushed.

Copy link

github-actions bot commented Jan 8, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

1 similar comment
Copy link

github-actions bot commented Jan 8, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to ae5ba2b in 1 minute and 44 seconds

More details
  • Looked at 1775 lines of code in 34 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. pkg/config/conf.go:28
  • Draft comment:
    The comment on line 28 is misleading. It should clarify that the function merges the input configuration at a specified path within the current configuration.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The comment on line 28 incorrectly states that the function merges the current configuration with the input configuration. This is misleading as the function actually merges the input configuration at a specified path within the current configuration.
2. pkg/config/uri.go:10
  • Draft comment:
    The comment on line 10 is misleading. It should clarify that the regex matches a specific format of URI, not the entire URI definition.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The comment on line 10 in pkg/config/uri.go is misleading. It states that the regex complies with the URI definition, but it only matches a specific format of URI. This should be clarified.
3. pkg/web/config.go:10
  • Draft comment:
    The comment on line 10 is outdated. It should reflect that the Config satisfies the new config.Config interface, not confmap.Config.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The comment on line 10 in pkg/web/config.go is misleading. It states that the Config satisfies the confmap.Config interface, but it should be updated to reflect the new config.Config interface.
4. pkg/web/router/router.go:1
  • Draft comment:
    Avoid using the component/index.tsx file structure approach, as it makes it difficult to debug and find components using global search tools like VS Code.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_XloMbrlpzoO23qs6


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

path := filepath.Join(web.cfg.Directory, req.URL.Path)

// check whether a file exists or is a directory at the given path
fi, err := os.Stat(path)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the path constructed from user input is validated to prevent directory traversal attacks. This can be done by resolving the input path with respect to a safe directory and then checking that the resulting path is still within the intended directory.

  1. Define a constant for the safe directory.
  2. Resolve the input path with respect to the safe directory using filepath.Abs.
  3. Check that the resolved path starts with the safe directory path.
  4. If the path is invalid, return an error response.
Suggested changeset 1
pkg/web/router/router.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/web/router/router.go b/pkg/web/router/router.go
--- a/pkg/web/router/router.go
+++ b/pkg/web/router/router.go
@@ -7,2 +7,3 @@
 	"path/filepath"
+	"strings"
 	"time"
@@ -73,7 +74,11 @@
 func (web *router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
-	// Join internally call path.Clean to prevent directory traversal
-	path := filepath.Join(web.cfg.Directory, req.URL.Path)
+	// Resolve the user-provided path with respect to the safe directory
+	absPath, err := filepath.Abs(filepath.Join(web.cfg.Directory, req.URL.Path))
+	if err != nil || !strings.HasPrefix(absPath, web.cfg.Directory) {
+		http.Error(rw, "Invalid file path", http.StatusBadRequest)
+		return
+	}
 
 	// check whether a file exists or is a directory at the given path
-	fi, err := os.Stat(path)
+	fi, err := os.Stat(absPath)
 	if os.IsNotExist(err) || fi.IsDir() {
EOF
@@ -7,2 +7,3 @@
"path/filepath"
"strings"
"time"
@@ -73,7 +74,11 @@
func (web *router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// Join internally call path.Clean to prevent directory traversal
path := filepath.Join(web.cfg.Directory, req.URL.Path)
// Resolve the user-provided path with respect to the safe directory
absPath, err := filepath.Abs(filepath.Join(web.cfg.Directory, req.URL.Path))
if err != nil || !strings.HasPrefix(absPath, web.cfg.Directory) {
http.Error(rw, "Invalid file path", http.StatusBadRequest)
return
}

// check whether a file exists or is a directory at the given path
fi, err := os.Stat(path)
fi, err := os.Stat(absPath)
if os.IsNotExist(err) || fi.IsDir() {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
// func (conf *Conf) Unmarshal(input any) error {

// return conf.Koanf.UnmarshalWithConf("", input, koanf.UnmarshalConf{
// Tag: "mapstructure",
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this

vikrantgupta25
vikrantgupta25 previously approved these changes Jan 9, 2025
Copy link

github-actions bot commented Jan 9, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 4c94386 in 1 minute and 31 seconds

More details
  • Looked at 2466 lines of code in 40 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. pkg/signoz/signoz.go:24
  • Draft comment:
    Add error handling for unrecognized cache providers to prevent potential nil pointer dereference.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.
2. pkg/signoz/signoz.go:46
  • Draft comment:
    Add error handling for web initialization to prevent potential nil pointer dereference.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.
3. pkg/signoz/signoz.go:57
  • Draft comment:
    Add error handling for sqlStore initialization to prevent potential nil pointer dereference.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
4. pkg/query-service/app/server.go:27
  • Draft comment:
    Avoid using the component/index.tsx file structure approach, as it makes it difficult to debug and find components using global search tools like VS Code.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_SdvgtI8IbXj32Z5C


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Jan 9, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 5d26d2b in 1 minute and 8 seconds

More details
  • Looked at 170 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. pkg/query-service/app/integrations/manager.go:126
  • Draft comment:
    Removing error handling for NewInstalledIntegrationsSqliteRepo can lead to runtime errors if the database is not properly initialized. Consider re-adding error handling to ensure robustness.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
  1. Without seeing NewInstalledIntegrationsSqliteRepo implementation, I can't be certain if it can fail. 2. The change suggests the function was modified to not return an error anymore. 3. If the function signature changed, then error handling would be unnecessary. 4. The code compiles, suggesting the function signature must have changed. 5. The PR author likely made this change intentionally after determining errors weren't possible.
    I don't have access to the NewInstalledIntegrationsSqliteRepo implementation or its changes. The comment could be valid if that function can still fail at runtime.
    Since the code compiles, the function signature must have changed to not return an error. The PR author likely determined error handling wasn't needed and simplified the API.
    Without seeing the NewInstalledIntegrationsSqliteRepo implementation or its changes, I cannot verify if error handling is actually needed. The comment makes assumptions without full context.
2. pkg/query-service/app/integrations/test_utils.go:18
  • Draft comment:
    Removing error handling for NewInstalledIntegrationsSqliteRepo can lead to runtime errors if the database is not properly initialized. Consider re-adding error handling to ensure robustness. This is also applicable in NewTestIntegrationsManager.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    This is a test utility function, and test utilities often simplify error handling for cleaner tests. The database is created using NewQueryServiceDBForTests which likely handles setup validation. Since this is test code, a panic on initialization failure is actually preferable to error propagation. The comment seems to be applying production code standards to test code.
    I could be wrong about the database initialization being validated in NewQueryServiceDBForTests. There could be valid reasons to handle errors even in test code.
    Even if the database initialization isn't fully validated elsewhere, having a test utility panic on setup failure is a valid and common pattern - it fails fast and makes test failures more obvious.
    The comment should be deleted as it's applying overly strict standards to test code where simplified error handling is acceptable and often preferred.
3. pkg/query-service/app/integrations/manager.go:126
  • Draft comment:
    The NewInstalledIntegrationsSqliteRepo function no longer returns an error, so the error handling in NewManager is unnecessary and should be removed.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_BOx5CKlqmlQpyfHW


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Jan 9, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 0c3af05 in 1 minute and 5 seconds

More details
  • Looked at 106 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 drafted comments based on config settings.
1. ee/query-service/app/server.go:210
  • Draft comment:
    The removal of the 'engine' parameter from the NewLogParsingPipelinesController function call is consistent with the refactoring goal. Ensure that this parameter is not used elsewhere in the function.
  • Reason this comment was not posted:
    Confidence changes required: 20%
    The removal of the 'engine' parameter from the function signature is consistent across all instances where the function is called. This change aligns with the refactoring goal of removing unnecessary parameters.
2. pkg/query-service/agentConf/manager.go:42
  • Draft comment:
    The removal of the 'DBEngine' field from the ManagerOptions struct is consistent with the refactoring goal. Ensure that this field is not used elsewhere in the code.
  • Reason this comment was not posted:
    Confidence changes required: 20%
    The removal of the 'DBEngine' field from the ManagerOptions struct is consistent across all instances where the struct is used. This change aligns with the refactoring goal of removing unnecessary fields.
3. pkg/query-service/app/logparsingpipeline/controller.go:30
  • Draft comment:
    The removal of the 'engine' parameter from the NewLogParsingPipelinesController function call is consistent with the refactoring goal. Ensure that this parameter is not used elsewhere in the function.
  • Reason this comment was not posted:
    Confidence changes required: 20%
    The removal of the 'engine' parameter from the function signature is consistent across all instances where the function is called. This change aligns with the refactoring goal of removing unnecessary parameters.
4. pkg/query-service/tests/integration/logparsingpipeline_test.go:487
  • Draft comment:
    The removal of the 'DBEngine' field from the ManagerOptions struct is consistent with the refactoring goal. Ensure that this field is not used elsewhere in the code.
  • Reason this comment was not posted:
    Confidence changes required: 20%
    The removal of the 'DBEngine' field from the ManagerOptions struct is consistent across all instances where the struct is used. This change aligns with the refactoring goal of removing unnecessary fields.
5. pkg/query-service/app/server.go:174
  • Draft comment:
    Avoid using inline styles in React components. Use external stylesheets, CSS classes, or styled components instead. This is also applicable in other parts of the code where inline styles are used.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_8M11gtu6Fo1lD3Vp


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Jan 9, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on e1cb905 in 38 seconds

More details
  • Looked at 241 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. pkg/sqlstore/config.go:36
  • Draft comment:
    The increase in MaxOpenConns from 10 to 100 should be justified. Ensure the system can handle this increase without resource exhaustion.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The change in MaxOpenConns from 10 to 100 in pkg/sqlstore/config.go is significant and should be justified. Increasing the number of open connections can improve performance by allowing more concurrent database operations, but it can also lead to resource exhaustion if not managed properly. It's important to ensure that the system can handle this increase without negative side effects.
2. pkg/sqlstore/provider/sqlite/provider.go:33
  • Draft comment:
    The log message includes ?_foreign_keys=true in the path, which might be misleading as it's not part of the actual connection string. Consider aligning the log message with the actual connection string or explaining the discrepancy.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The connection string for SQLite in pkg/sqlstore/provider/sqlite/provider.go includes ?_foreign_keys=true in the log message but not in the actual connection string. This could lead to confusion as the log message suggests foreign keys are enabled by default, which is not the case unless explicitly set in the connection string or via PRAGMA command.
3. pkg/sqlstore/provider/sqlite/provider.go:5
  • Draft comment:
    Avoid using the component/index.tsx file structure approach, as it makes it difficult to debug and find components using global search tools.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_WX037G8SS8Azkp3M


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Jan 9, 2025

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 2060905 in 36 seconds

More details
  • Looked at 75 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. pkg/sqlstore/provider/sqlite/provider.go:30
  • Draft comment:
    The refactor removed the explicit enabling of foreign key support using PRAGMA foreign_keys = ON;. Ensure that foreign key constraints are enforced as expected, as SQLite does not enable them by default.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. pkg/sqlstore/provider/sqlite/provider.go:30
  • Draft comment:
    Avoid using inline styles in React components. Use external stylesheets, CSS classes, or styled components instead. This comment applies to other instances of inline styles in the code as well.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_iCItnw1uPH1tsZFP


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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.

2 participants