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

Louis/enrichment datamodel #377

Merged
merged 2 commits into from May 6, 2021
Merged

Conversation

ldelossa
Copy link
Contributor

Draft pull request to implement Enrichment data model changes per:
quay/clair#1229

@ldelossa ldelossa marked this pull request as ready for review April 29, 2021 12:40
@ldelossa ldelossa force-pushed the louis/enrichment-datamodel branch 3 times, most recently from 913a22d to 1c2238c Compare April 29, 2021 14:26
hdonnay
hdonnay previously approved these changes Apr 30, 2021
Copy link
Member

@hdonnay hdonnay left a comment

Choose a reason for hiding this comment

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

My one suggestion isn't going to affect correctness, so it's not super important.

Comment on lines +286 to -223
var uo driver.UpdateOperation
err := rows.Scan(
&uo.Ref,
&uo.Updater,
&uo.Fingerprint,
&uo.Date,
)
if err != nil {
rows.Close()
return nil, fmt.Errorf("failed to retrieve update operation for updater %v: %w", updater, err)
}
ops := []driver.UpdateOperation{}

getUpdateOperationsCounter.WithLabelValues("query").Add(1)
getUpdateOperationsDuration.WithLabelValues("query").Observe(time.Since(start).Seconds())

for rows.Next() {
ops = append(ops, driver.UpdateOperation{})
uo := &ops[len(ops)-1]
err := rows.Scan(
&uo.Ref,
&uo.Updater,
&uo.Fingerprint,
&uo.Date,
)
if err != nil {
rows.Close()
return nil, fmt.Errorf("failed to scan update operation for updater %q: %w", u, err)
}
}
rows.Close()
if err := rows.Err(); err != nil {
return nil, err
return nil, fmt.Errorf("failed to scan update operation for updater %q: %w", uo.Updater, err)
}
out[u] = ops
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little worried about excess copying doing it this way, but it's certainly simpler to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where are the concerns?

Copy link
Member

Choose a reason for hiding this comment

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

The previous version allocates a local slice, grows it and populates in-place, then adds it to the map, so the slices in the map never need to be updated once they escape. This version allocates a uo local, populates it, then potentially reallocates the updater's slice copies it into the slice.

Comment on lines -225 to -226
if err := tx.Commit(ctx); err != nil {
return nil, fmt.Errorf("failed to commit transaction: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

I see why we wouldn't bother with the commit, but it's a little weird. Using BeginTx with a read-only option would call out this being read-only in code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm not sure why we went with a transaction here to begin with, I think we can get rid of it and make this a read only method all together, right?

Copy link
Member

Choose a reason for hiding this comment

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

I thought the transaction was needed to make sure the same snapshot of the table is used, since we're issuing multiple queries.

This commit adds the necessary migration to support
the Enrichment feature per out specification:
https://github.com/quay/clair-enrichment-spec/

This commit will be backported to stable branches
to maintain upgrade path compatibility.

Signed-off-by: ldelossa <ldelossa@redhat.com>
@ldelossa ldelossa force-pushed the louis/enrichment-datamodel branch from 06ef7fd to 468a76f Compare May 6, 2021 16:10
this commit introduces the necessary changes to support the
enrichment specification's data model changes.

see: https://github.com/quay/clair-enrichment-spec/

In addition to this, a small bug was fixed in the updater code
where errors were not being logged.
@hdonnay hdonnay force-pushed the louis/enrichment-datamodel branch from 468a76f to 9a3b349 Compare May 6, 2021 17:48
@hdonnay hdonnay merged commit 9a3b349 into quay:main May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants