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

Reduce dependencies #734

Merged
merged 4 commits into from
Jan 30, 2023
Merged

Reduce dependencies #734

merged 4 commits into from
Jan 30, 2023

Conversation

ka3de
Copy link
Collaborator

@ka3de ka3de commented Jan 27, 2023

This PR tries to get rid of some dependencies currently required by the main module that are marginally used. More specifically:

  • Removes the usage of github.com/fatih/color
  • Removes the requirement for golang.org/x/exp from main module (still required as transitive)
    This produces the direct inclusion of github.com/google/go-cmp but that is only used inside tests pkg
  • Replaces the usage of github.com/hashicorp/go-multierror with a custom implementation that fulfills our current use case

Closes #729.

@ka3de
Copy link
Collaborator Author

ka3de commented Jan 27, 2023

A comment on d76ff69 and multierror dependency replacement.

I came up with a custom implementation that fulfills our current usage of the library in order to try to comply with the previous API and log format. E:g.: Example of previous output by Hashicorps multierror library, which has been mimicked by our custom version:

2 errors occurred:
        * object is too large and will be parsed partially
        * parsing object property "objPropName": objTestErr

I think this is the safest bet before the release, but nevertheless in the future we should review this implementation and try to replace it with something simpler. For example go v1.20 adds support for wrapping multiple errors.

@ka3de ka3de marked this pull request as ready for review January 27, 2023 10:52
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Most of it looks good. I've left some suggestions that I think are worth considering, and let me know in the comments if my suggestions don't work 🙂

EDIT: Could you also double check the CI pipeline issues and resolve those? There are some tests that fail often in the CI pipeline (we have raised issues for those so you should be able to find them, and then rerun the failed tests runs).

common/remote_object.go Outdated Show resolved Hide resolved
common/remote_object.go Outdated Show resolved Hide resolved
common/remote_object.go Show resolved Hide resolved
common/remote_object.go Outdated Show resolved Hide resolved
ka3de added a commit that referenced this pull request Jan 27, 2023
go.mod Outdated Show resolved Hide resolved
@ka3de ka3de force-pushed the optimization/729-reduce-dependencies branch from b4f3aad to d76ff69 Compare January 27, 2023 15:07
log/logger.go Outdated Show resolved Hide resolved
ka3de added a commit that referenced this pull request Jan 30, 2023
If the given inner logger for our log implementation is nil,
provide a new logrus logger by default. This avoids a possible panic
when checking for the log level in the Logf method as well as allows us
to remove the particular logging action using Printf when wrapped logger
was nil.

Resolves: #734 (comment)
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Didn't look into this thoroughly yet, here is what I saw after skimming it.

It's great that we're getting rid of that excess calories 👏

common/remote_object_test.go Outdated Show resolved Hide resolved
common/remote_object_test.go Outdated Show resolved Hide resolved
common/remote_object_test.go Outdated Show resolved Hide resolved
@ankur22 ankur22 self-requested a review January 30, 2023 10:36
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for taking on the feedback 🙂

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM with some suggestions.

common/remote_object.go Show resolved Hide resolved
common/remote_object.go Outdated Show resolved Hide resolved
ka3de added 2 commits January 30, 2023 11:56
If the given inner logger for our log implementation is nil,
provide a new logrus logger by default. This avoids a possible panic
when checking for the log level in the Logf method as well as allows us
to remove the particular logging action using Printf when wrapped logger
was nil.

Resolves: #734 (comment)
This dependency is now included as "indirect", but it's only required
from the tests package, therefore should not be included in the
generated binary.
@ka3de ka3de force-pushed the optimization/729-reduce-dependencies branch from 805bf89 to 8dcfbb6 Compare January 30, 2023 10:57
@inancgumus inancgumus self-requested a review January 30, 2023 11:32
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

🚀

ka3de added a commit that referenced this pull request Jan 30, 2023
ka3de and others added 2 commits January 30, 2023 13:10
This commit replaces the Hashicorp multierror dependency usage with a
custom implementation which fulfills our use case. The implementation
tries to comply with the error format used by the replaced library for
grouping multiple errors.

Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Considering the merge with k6, this will allow the final generated
binary to include a single version of the mentioned dependency.
@ka3de ka3de force-pushed the optimization/729-reduce-dependencies branch from f6d1e5f to 6ec0732 Compare January 30, 2023 12:10
@ka3de ka3de merged commit 4c6d3f8 into main Jan 30, 2023
@ka3de ka3de deleted the optimization/729-reduce-dependencies branch January 30, 2023 13:02
inancgumus pushed a commit that referenced this pull request Jan 31, 2023
ankur22 pushed a commit that referenced this pull request Jan 31, 2023
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.

Reduce dependency usage
3 participants