-
Notifications
You must be signed in to change notification settings - Fork 32
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
Track the policy data by source group #2181
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2181 +/- ##
==========================================
- Coverage 71.22% 71.18% -0.05%
==========================================
Files 89 88 -1
Lines 7479 7506 +27
==========================================
+ Hits 5327 5343 +16
- Misses 2152 2163 +11
Flags with carried forward coverage won't be shown. Click here to find out more.
|
01a9434
to
b63738a
Compare
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'm expecting snapshots that need updating (haven't looked at the CI), so UPDATE_SNAPS=1 make ci
should help
internal/image/validate.go
Outdated
@@ -130,7 +131,7 @@ func ValidateImage(ctx context.Context, comp app.SnapshotComponent, snap *app.Sn | |||
return nil, err | |||
} | |||
allResults = append(allResults, results...) | |||
out.Data = append(out.Data, data) | |||
out.Data[fmt.Sprintf("%d", idx)] = append(out.Data[fmt.Sprintf("%d", idx)], data) |
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.
Could be a tad nicer
out.Data[fmt.Sprintf("%d", idx)] = append(out.Data[fmt.Sprintf("%d", idx)], data) | |
key := strconv.FormatInt(idx, 10) | |
out.Data[key] = append(out.Data[key], data) |
738ed22
to
a234a77
Compare
The snapshot variable substitution is somewhat rudimentary, I think we either need to indent by 2 or decrease the indent by 2, and the underscores should probably reflect that here |
cmd/validate/image.go
Outdated
@@ -409,12 +412,17 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command { | |||
e := fmt.Errorf("error validating image %s of component %s: %w", r.component.ContainerImage, r.component.Name, r.err) | |||
allErrors = errors.Join(allErrors, e) | |||
} else { | |||
for key, val := range r.data { |
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 think this is quite right. This is merging all the data from different source groups.
Consider something like this:
// Renamed from manyData
var evaluatorData []evaluator.Data
dataCollected := false
for i := 0; i < numComponents; i++ {
r := <-results
...
if !dataCollected {
evaluatorData = r.data
dataCollected = true
}
}
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.
or rather:
// Renamed from manyData
var evaluatorData []evaluator.Data
for i := 0; i < numComponents; i++ {
r := <-results
...
if evaluatorData == nil {
evaluatorData = r.data
}
}
Anyways, I think you get the idea.
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.
Don't we want that since the data could differ per source group?
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.
r.data
is a list of data.
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 changed it to map[string]evaluator.Data
. My thought was each evaluator maps to a source group, so to just collect data per evaluator.
https://github.com/enterprise-contract/ec-cli/pull/2181/files#diff-7f11215ba891ff8199fa09a412849a5414e416050d163c813f6499009bbe0b96R304
https://github.com/enterprise-contract/ec-cli/pull/2181/files#diff-ed62eb280d370e54af87c7fdb7026890b2efeefd1da359a2b28ecb76904cd86eR136
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.
hmm I think I see understand what you're doing now. Why use a map where the keys are indexes? Wouldn't it be more natural to keep it as a slice?
Also, running this for loop for every component is unnecessary. It's just copying data around needlessly. Please consider introducing a mechanism so that is only done for the first component.
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 makes me think this whole PR could be replaced with
--- a/cmd/validate/image.go
+++ b/cmd/validate/image.go
@@ -410,7 +410,9 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
allErrors = errors.Join(allErrors, e)
} else {
components = append(components, r.component)
- manyData = append(manyData, r.data)
+ if len(manyData) == 0 {
+ manyData = append(manyData, r.data)
+ }
manyPolicyInput = append(manyPolicyInput, r.policyInput)
}
}
1585fe3
to
3a22118
Compare
Only collect the policy data once for each source group. Before this the data was duplicated for each component. https://issues.redhat.com/browse/EC-1027
Closing in favor of this #2184 |
Only collect the policy data once for each source group. Before this the data was duplicated for each component.
https://issues.redhat.com/browse/EC-1027