-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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: use google/wire for cache #7024
Conversation
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
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.
LGTM
left a couple comments.
@@ -144,6 +145,8 @@ func (f *GlobalFlagGroup) ToOptions() (GlobalOptions, error) { | |||
// Keep TRIVY_NON_SSL for backward compatibility | |||
insecure := f.Insecure.Value() || os.Getenv("TRIVY_NON_SSL") != "" | |||
|
|||
log.Debug("Cache dir", log.String("dir", f.CacheDir.Value())) |
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.
i am not sure that we need to add this here.
We show cache dir for server
mode:
trivy/pkg/commands/server/run.go
Line 27 in 5751870
log.Debug("Cache", log.String("dir", opts.CacheDir)) |
(perhaps it make sense to move this to
Lines 31 to 47 in 5751870
func NewRemoteCache(opts RemoteOptions) *RemoteCache { | |
ctx := client.WithCustomHeaders(context.Background(), opts.CustomHeaders) | |
httpClient := &http.Client{ | |
Transport: &http.Transport{ | |
Proxy: http.ProxyFromEnvironment, | |
TLSClientConfig: &tls.Config{ | |
InsecureSkipVerify: opts.Insecure, | |
}, | |
}, | |
} | |
c := rpcCache.NewCacheProtobufClient(opts.ServerAddr, httpClient) | |
return &RemoteCache{ | |
ctx: ctx, | |
client: c, | |
} | |
} |
Also we show this log for redis cache (cache directory information when using redis
can be confusing for users).
But we need to add this log to
Line 22 in 5751870
func NewFSCache(cacheDir string) (FSCache, 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.
Also we show this log for redis cache (cache directory information when using redis can be confusing for users).
--cache-dir
is effective more than the scan cache. It also affects the vulnerability DB and the Java DB.
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.
We show cache dir for server mode:
Deleted 1ab584e
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.
--cache-dir is effective more than the scan cache. It also affects the vulnerability DB and the Java DB.
hm... you are right.
Let's update redis log then (e.g. Redis scan cache
):
Line 91 in 1ab584e
log.Info("Redis cache", log.String("url", opts.BackendMasked())) |
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.
BTW, I'm not sure scan cache is a good name. I tentatively named it "scan cache" because we needed a different name to distinguish between a general cache, including DB, and a specific cache for storing analysis results (fanal cache), but there are other candidates, such as "layer cache" or "analysis cache". What do you think?
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.
I don't like layer cache
. User may think that we store layers (I mean files from layers), but we only store layer IDs.
analysis cache
looks good.
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.
I don't like layer cache. User may think that we store layers (I mean files from layers), but we only store layer IDs.
Right. That's why I didn't choose it.
While "analysis cache" describes the internal logic well, the "analyzer" concept is not exported to end users. I'm not sure people understand "analysis cache". Anyway, I'll change it to Redis scan cache for now. I'll open another issue to discuss the naming.
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.
Fixed 2868b08
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 "analyzer" concept is not exported to end users. I'm not sure people understand "analysis cache"
We, as maintainers, constantly work with analyzers
and are accustomed to this term, so perhaps scan cache
does not seem to be best choice for us, but perhaps it will be clearer for users
I'll open another issue to discuss the naming.
Anyway, let's listen to the users
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.
@DmitriyLewen Please feel free to leave any comments.
#7034
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Description
This PR simplifies the cache initialization process in the artifact scanning. Previously, we initialized the
cache.Cache
instance withinpkg/commands/artifact/run.go
to support--clear-cache
and--reset
operations. However, these operations have been moved to thetrivy clean
command.With this change, we can now generate the
cache.Cache
instance through google/wire, which is consistent with other instances in the project.Changes
initCache
function frompkg/commands/artifact/run.go
cache.Cache
generationBenefits
Checklist