-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Feat: Log enhancement for command generate and update #2461
Feat: Log enhancement for command generate and update #2461
Conversation
Thank you! |
@@ -23,11 +24,11 @@ func NewCargo(client CargoClient) *CargoVersionGetter { | |||
} | |||
} | |||
|
|||
func (c *CargoVersionGetter) Get(ctx context.Context, pkg *registry.PackageInfo, filters []*Filter) (string, error) { | |||
func (c *CargoVersionGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, filters []*Filter) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused, so we don't need to add this at the moment.
func (c *CargoVersionGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, filters []*Filter) (string, error) { | |
func (c *CargoVersionGetter) Get(ctx context.Context, pkg *registry.PackageInfo, filters []*Filter) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are five classes/structs that implement the interface VersionGetter
:
GeneralVersionGetter
CargoVersionGetter
GitHubReleaseVersionGetter
GitHubTagVersionGetter
MockVersionGetter
Since I’ve modified the VersionGetter
. Removing the _ *logrus.Entry,
will result in a compile error in GeneralVersionGetter.get
.
After considering the feature of log enhancement, I think there are two options:
- Keep it simple. Do not modify the interface
VersionGetter
, log the ERROR in FuzzyGetter.Get
only. - Modify the interface
VersionGetter
and log the GH API Rate Limit info as DEBUG level. TheCargoVersionGetter
has to be modified.
What do you think about it? If you have a better approach, please tell me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I’ve modified the VersionGetter. Removing the _ *logrus.Entry, will result in a compile error in GeneralVersionGetter.get.
Oh, I see. Thank you for your explanation.
Keep it simple. Do not modify the interface VersionGetter, log the ERROR in FuzzyGetter.Get only.
I disagree with this option. We usually pass *logrus.Entry as an argument to take over the context (log's structured data).
Modify the interface VersionGetter and log the GH API Rate Limit info as DEBUG level. The CargoVersionGetter has to be modified.
The log about GitHub API rate limit should be outputted only when GitHub API rate limit error occurs.
https://pkg.go.dev/github.com/google/go-github/github#hdr-Rate_Limiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log about GitHub API rate limit should be outputted only when GitHub API rate limit error occurs.
https://pkg.go.dev/github.com/google/go-github/github#hdr-Rate_Limiting
Ah, sorry. Let me correct.
Debug log is fine.
This log also should not be outputted always. |
pkg/versiongetter/general.go
Outdated
} | ||
|
||
// fuzzy-finder's output will overwrite the log, add fields to original logE | ||
func addRteLimitInfo(logE *logrus.Entry, resp *github.Response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
func addRteLimitInfo(logE *logrus.Entry, resp *github.Response) { | |
func addRateLimitInfo(logE *logrus.Entry, resp *github.Response) { |
pkg/versiongetter/general.go
Outdated
func addRteLimitInfo(logE *logrus.Entry, resp *github.Response) { | ||
*logE = *logE.WithFields(logrus.Fields{ | ||
"gh_rate_limit": resp.Rate.Limit, | ||
"gh_rate_remaining": resp.Rate.Remaining, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func addRteLimitInfo(logE *logrus.Entry, resp *github.Response) { | |
*logE = *logE.WithFields(logrus.Fields{ | |
"gh_rate_limit": resp.Rate.Limit, | |
"gh_rate_remaining": resp.Rate.Remaining, | |
}) | |
} | |
func addRateLimitInfo(logE *logrus.Entry, resp *github.Response) *logrus.Entry { | |
return logE.WithFields(logrus.Fields{ | |
"gh_rate_limit": resp.Rate.Limit, | |
"gh_rate_remaining": resp.Rate.Remaining, | |
}) | |
} |
I think this is more natural.
logE = addRateLimitInfo(logE, resp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logE = addRateLimitInfo(logE, resp)
This statement generate a derived logE and assign its pointer to a local variable.
This will not change its orginal value.
see this example in playground
*logE = *addRateLimitInfo(logE, resp)
What do you think of editing it like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to change the original value.
You just create a new *logrus.Entry and use it.
I think this is the design of logrus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I want to change its original value is the fuzzy-finder's output will overwirte the log output.
See this code
List
is invoked before openning fuzzy-finder, if log something in List
, it will be overwritten by fuzzy-finder.
List -> print log -> open fuzzy-finder -> print content (overwrite the log)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation. I understood the issue, but I don't want to change *logrus.Entry
.
This is tricky.
I don't think the information about API rate limit is so important that we need to output it with the tricky way unless API rate limit error occurs.
Description
One more question
May I ask why this tricky approach is not recommended? Are there any disadvantages to it? Test casesgenerate# DEFAULT LEVEL
# Releases
$ aqua g cli/cli
- name: cli/[email protected]
$ aqua g -s cli/cli
- name: cli/[email protected]
$ aqua g -s -l -1 cli/cli
- name: cli/[email protected]
# Rate Limit
$ aqua g cli/cli
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: GET https://api.github.com/repos/cli/cli/releases/latest: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 2m28s]" program=aqua repo=cli/cli
- name: cli/cli
version: '[SET PACKAGE VERSION]'
# Network error
$ aqua g cli/cli
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: Get \"https://api.github.com/repos/cli/cli/releases/latest\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=cli/cli
- name: cli/cli
version: '[SET PACKAGE VERSION]'
$ aqua g -s cli/cli
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: GET https://api.github.com/repos/cli/cli/releases?per_page=100: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 1m09s]" gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=cli/cli
- name: cli/cli
version: '[SET PACKAGE VERSION]'
# Tags
$ aqua g golang/go
- name: golang/[email protected]
$ aqua g -s golang/go
- name: golang/[email protected]
$ aqua g -s -l -1 golang/go
- name: golang/[email protected]
# Rate Limit
$ aqua g golang/go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: GET https://api.github.com/repos/golang/go/tags?per_page=100: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 40s]" gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=golang/go
WARN[0000] same package already exists aqua_version= env=linux/amd64 package_name=golang/go package_registry=standard program=aqua
- name: golang/go
version: '[SET PACKAGE VERSION]'
# Network error
$ aqua g golang/go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: Get \"https://api.github.com/repos/golang/go/tags?per_page=30\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=golang/go
WARN[0000] same package already exists aqua_version= env=linux/amd64 package_name=golang/go package_registry=standard program=aqua
- name: golang/go
version: '[SET PACKAGE VERSION]'
# DEBUG LEVEL
export AQUA_LOG_LEVEL=DEBUG
# Releases
$ aqua g cli/cli
DEBU[0000] GitHub API Rate Limit info aqua_version= env=windows/amd64 gh_rate_limit=60 gh_rate_remaining=40 program=aqua repo=cli/cli
DEBU[0000] Retrieve pkg version(s) in 863.4326ms aqua_version= env=windows/amd64 program=aqua repo=cli/cli
- name: cli/[email protected]
$ aqua g -s cli/cli
DEBU[0004] Retrieve pkg version(s) in 3.7289863s aqua_version= env=windows/amd64 program=aqua repo=cli/cli
- name: cli/[email protected]
$ aqua g -s -l -1 cli/cli
DEBU[0005] Retrieve pkg version(s) in 4.0286107s aqua_version= env=windows/amd64 program=aqua repo=cli/cli
- name: cli/[email protected]
# Rate Limit
$ aqua g cli/cli
DEBU[0000] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=cli/cli
DEBU[0000] Retrieve pkg version(s) in 469.521004ms aqua_version= env=linux/amd64 program=aqua repo=cli/cli
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: GET https://api.github.com/repos/cli/cli/releases/latest: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 23m57s]" program=aqua repo=cli/cli
- name: cli/cli
version: '[SET PACKAGE VERSION]'
# Tags
$ aqua g golang/go
DEBU[0001] GitHub API Rate Limit info aqua_version= env=windows/amd64 gh_rate_limit=60 gh_rate_remaining=33 program=aqua repo=golang/go
DEBU[0001] Retrieve pkg version(s) in 1.8703541s aqua_version= env=windows/amd64 program=aqua repo=golang/go
- name: golang/[email protected]
$ aqua g -s golang/go
DEBU[0002] Retrieve pkg version(s) in 1.1045973s aqua_version= env=windows/amd64 program=aqua repo=golang/go
- name: golang/[email protected]
$ aqua g -s -l -1 golang/go
DEBU[0002] Retrieve pkg version(s) in 1.6950486s aqua_version= env=windows/amd64 program=aqua repo=golang/go
- name: golang/[email protected]
# Rate limit
$ aqua g golang/go
DEBU[0000] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=golang/go
DEBU[0000] Retrieve pkg version(s) in 562.864474ms aqua_version= env=linux/amd64 program=aqua repo=golang/go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: GET https://api.github.com/repos/golang/go/tags?per_page=30: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 22m32s]" program=aqua repo=golang/go
WARN[0000] same package already exists aqua_version= env=linux/amd64 package_name=golang/go package_registry=standard program=aqua
- name: golang/go
version: '[SET PACKAGE VERSION]' update# DEFAULT LEVEL
# Releases
$ aqua up pryrite
$ aqua up -s pryrite
$ aqua up -s -l -1 pryrite
# Network error
$ aqua up pryrite
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: Get \"https://api.github.com/repos/1xyz/pryrite/releases/latest\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=1xyz/pryrite
# Rate Limit
$ aqua up pryrite
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: GET https://api.github.com/repos/1xyz/pryrite/releases/latest: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 13m45s]" program=aqua repo=1xyz/pryrite
# Tags
$ aqua up go
$ aqua up -s go
$ aqua up -s -l -1 go
# Network error
$ aqua up go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: Get \"https://api.github.com/repos/golang/go/tags?per_page=30\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=golang/go
# Rate Limit
$ aqua up go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: GET https://api.github.com/repos/golang/go/tags?per_page=30: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 15m16s]" program=aqua repo=golang/go
# DEBUG LEVEL
export AQUA_LOG_LEVEL=DEBUG
# Releases
$ aqua up pryrite
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=13 program=aqua repo=1xyz/pryrite
DEBU[0000] Retrieve pkg version(s) in 861.525691ms aqua_version= env=linux/amd64 program=aqua repo=1xyz/pryrite
DEBU[0000] already latest aqua_version= env=linux/amd64 program=aqua
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
$ aqua up -s pryrite
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0002] Retrieve pkg version(s) in 945.278908ms aqua_version= env=linux/amd64 program=aqua repo=1xyz/pryrite
DEBU[0002] already latest aqua_version= env=linux/amd64 program=aqua
DEBU[0002] version isn't found aqua_version= env=linux/amd64 program=aqua
$ aqua up -s -l -1 pryrite
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0001] Retrieve pkg version(s) in 780.912784ms aqua_version= env=linux/amd64 program=aqua repo=1xyz/pryrite
DEBU[0001] already latest aqua_version= env=linux/amd64 program=aqua
DEBU[0001] version isn't found aqua_version= env=linux/amd64 program=aqua
# Rate Limit
$ aqua up pryrite
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=1xyz/pryrite
DEBU[0000] Retrieve pkg version(s) in 503.917687ms aqua_version= env=linux/amd64 program=aqua repo=1xyz/pryrite
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: GET https://api.github.com/repos/1xyz/pryrite/releases/latest: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 16m19s]" program=aqua repo=1xyz/pryrite
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
# Network error
$ aqua up pryrite
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] Retrieve pkg version(s) in 799.3µs aqua_version= env=linux/amd64 program=aqua repo=1xyz/pryrite
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="get the latest GitHub Release: Get \"https://api.github.com/repos/1xyz/pryrite/releases/latest\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=1xyz/pryrite
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
# Tags
$ aqua up go
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] no version_constraint aqua_version= env=linux/amd64 package_name=golang/go program=aqua registry_name=standard
DEBU[0002] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=7 program=aqua repo=golang/go
DEBU[0002] Retrieve pkg version(s) in 2.657070993s aqua_version= env=linux/amd64 program=aqua repo=golang/go
DEBU[0002] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0002] already latest aqua_version= env=linux/amd64 program=aqua
$ aqua up -s go
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] no version_constraint aqua_version= env=linux/amd64 package_name=golang/go program=aqua registry_name=standard
DEBU[0002] Retrieve pkg version(s) in 1.109959998s aqua_version= env=linux/amd64 program=aqua repo=golang/go
DEBU[0002] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0002] already latest aqua_version= env=linux/amd64 program=aqua
$ aqua up -s -l -1 go
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] no version_constraint aqua_version= env=linux/amd64 package_name=golang/go program=aqua registry_name=standard
DEBU[0002] Retrieve pkg version(s) in 1.828739s aqua_version= env=linux/amd64 program=aqua repo=golang/go
DEBU[0002] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0002] already latest aqua_version= env=linux/amd64 program=aqua
# Rate Limit
$ aqua up go
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] no version_constraint aqua_version= env=linux/amd64 package_name=golang/go program=aqua registry_name=standard
DEBU[0000] GitHub API Rate Limit info aqua_version= env=linux/amd64 gh_rate_limit=60 gh_rate_remaining=0 program=aqua repo=golang/go
DEBU[0000] Retrieve pkg version(s) in 466.859563ms aqua_version= env=linux/amd64 program=aqua repo=golang/go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: GET https://api.github.com/repos/golang/go/tags?per_page=30: 403 API rate limit exceeded for xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 18m53s]" program=aqua repo=golang/go
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
# Network error
$ aqua up go
DEBU[0000] match the version_constraint aqua_version= env=linux/amd64 package_name=1xyz/pryrite package_semver=0.10.20 package_version=0.10.20 program=aqua registry_name=standard version_constraint=true
DEBU[0000] no version_constraint aqua_version= env=linux/amd64 package_name=golang/go program=aqua registry_name=standard
DEBU[0000] Retrieve pkg version(s) in 455.2µs aqua_version= env=linux/amd64 program=aqua repo=golang/go
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="list tags: Get \"https://api.github.com/repos/golang/go/tags?per_page=30\": proxyconnect tcp: dial tcp xxx:8888: connect: connection refused" program=aqua repo=golang/go
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua
DEBU[0000] version isn't found aqua_version= env=linux/amd64 program=aqua |
Rate info in error log: $ aqua g -s cli/cli
WARN[0000] Version retrieving error aqua_version= env=linux/amd64 error="...403 API rate limit exceeded for xxx. ..." gh_rate_limit=60 gh_rate_remaining=0
program=aqua repo=cli/cli
- name: cli/cli
version: '[SET PACKAGE VERSION]' |
aqua passes *logrus.Entry in many places but we don't expect the side effect that *logrus.Entry is changed in functions. e.g. g.getter.List(ctx, logE, pkg, filters, limit) // information about api rate limiting are set to logE
// ...
version, err := g.getter.Get(ctx, logE, pkg, filters)
if err != nil {
logE.WithError(err).Warn(getVerErrWarn) // information set by `g.getter.List` are outputted
} Anyway, thank you for your contribution! |
Thank you too, I learned a lot from you and |
Oh! Nice meme 🤣 |
Solve issue mentioned in #2460
Description
Test cases
generate
update