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

gRPC API & internals redesign #432

Merged
merged 6 commits into from
Aug 17, 2017
Merged

Conversation

KeyboardNerd
Copy link
Contributor

@KeyboardNerd KeyboardNerd commented Jul 12, 2017

This is a large Pull Request that will contain a number of chunks. For easier code review, the Clair V3 PR will contains these commits separately.

  1. API changes
  2. datastore interface changes
  3. mock datastore, extensions update, worker, updater, notifier changes with tests
  4. datastore pgsql implementation with tests
  5. potential vendor clean up

@@ -26,57 +27,63 @@ message Vulnerability {
string link = 4;
string severity = 5;
string metadata = 6;
// fixed_by only exists when querying features
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we treat comments like Go ones? Full sentences 80 char lines.

}

message Feature {
message ClairStatus {
// all listers and detectors implemented in this clair version
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this what Clair is built with or configured with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all built-in listers/detectors. The listers and detectors are not configurable now, should I add that to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, we can do that later, just as long as nothing here prevents us from doing so.

string name = 2;
}

message PagedVulnerableAncestries {
string this_token = 1;
string next_token = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename these 'current_page' and 'next_page'

api/v2/rpc.go Outdated
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason you don't defer the rollback here and instead explicitly call it for each branch below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think Rollback() should ever be called after Commit() on success.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rollback() from database/sql actually is safe to do this and is considered an idiomatic pattern to do so. I think it makes sense both ways, though.

@KeyboardNerd KeyboardNerd force-pushed the ancestry_ branch 5 times, most recently from 2a479a9 to 47e2e2a Compare July 20, 2017 21:21
@KeyboardNerd KeyboardNerd force-pushed the ancestry_ branch 3 times, most recently from 3e3b9c8 to 4c0b6ac Compare July 26, 2017 23:31
@KeyboardNerd
Copy link
Contributor Author

KeyboardNerd commented Aug 3, 2017

I'm using my analyze_local_images fork's py tools to test the APIs, which seems to work properly. I'll do more concurrency tests and the web hook tests.

Besides the implementation of new schema and analyzing functions, I also added the knob to control feature listers and namespace detectors to scan the layers and updaters to fetch vuln src.

Copy link
Contributor

@jzelinskie jzelinskie left a comment

Choose a reason for hiding this comment

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

oh boy, here we go


// For output purposes. Only make sense when the feature version is in the context of an image.
AddedBy Layer
// AffectedFeature is used determine whether a namespaced feature is affected.
Copy link
Contributor

Choose a reason for hiding this comment

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

AffectedFeature is used to determine whether a namespaced feature is affected by a Vulnerability.

return nil, err
}

// encrypt page numbers
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't a particularly useful comment

}

// encrypt page numbers
nextToken, err := dbVuln.Next.Encrypt(paginationKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when there is no next page? Is there a special constant for that or does this function need to handle nil?

},
}, nil
}
pbOldVuln, err := PagedVulnerableAncestriesFromDatabaseModel(dbOldVuln, paginationKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if there is no old vulnerability? Doesn't this need to handle nil?

api/v2/rpc.go Outdated
}

if !ok {
return nil, status.Error(codes.NotFound, "requested ancestry \""+ancestry.Name+" \" is not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

raw string literals will make this easier to read

return nil, status.Error(`requested ancestry "` + ancestry.Name + `" is not found`)

if err != nil {
return nil, err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

why not defer rollback?

worker.go Outdated
}

log.WithFields(log.Fields{logLayerName: name, "path": cleanURL(path), "engine version": Version, "parent layer": parentName, "format": imageFormat}).Debug("processing layer")
// TODO: to fix, when there are duplicated layers
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm

Copy link
Contributor Author

@KeyboardNerd KeyboardNerd Aug 9, 2017

Choose a reason for hiding this comment

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

actually it's not true! the layers are deduplicated before the function call

worker.go Outdated
if err != nil {
return
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

defer rollback?

worker.go Outdated
// version format -> feature ID -> feature
features := map[string]map[string]database.NamespacedFeature{}
for _, layer := range ancestryLayers {
// at start of the loop, namespaces and features always contain the previous
Copy link
Contributor

Choose a reason for hiding this comment

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

capital at the start of sentences, end with periods, lol grammar

worker_test.go Outdated
_ "github.com/coreos/clair/ext/featurefmt/dpkg"
_ "github.com/coreos/clair/ext/featurefmt/rpm"
"github.com/coreos/clair/ext/featurens"
Copy link
Contributor

Choose a reason for hiding this comment

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

pull these up to where they used to be

Main Clair logic is changed in worker, updater, notifier for better adapting
ancestry schema. Extensions are updated with the new model and feature lister
 and namespace detector drivers are able to specify the specific listers and
detectors used to process layer's content. InRange and GetFixedIn interfaces
are added to Version format for adapting ranged affected features and next
available fixed in in the future. Tests for worker, updater and extensions
are fixed.
@jzelinskie jzelinskie changed the title Clair V3 gRPC API & internals redesign Aug 14, 2017
@jzelinskie
Copy link
Contributor

jzelinskie commented Aug 16, 2017

I think we should rename the API package to just "api" or "v3" (because Clair v3) in order to avoid confusion.

After that I think this is safe to merge!

@jzelinskie jzelinskie merged commit 6663bce into quay:master Aug 17, 2017
KeyboardNerd pushed a commit to KeyboardNerd/clair that referenced this pull request Feb 2, 2018
@jzelinskie jzelinskie mentioned this pull request Sep 26, 2018
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.

2 participants