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

v2 api with gRPC and gRPC gateway #408

Merged
merged 2 commits into from
Jun 30, 2017
Merged

Conversation

KeyboardNerd
Copy link
Contributor

It's a big commit, probably the logging should be improved. ( currently it's a hack on response writer )

api/api.go Outdated
listenAndServeWithStopper(srv, st, cfg.CertFile, cfg.KeyFile)

log.Info("main API stopped")
}

// RunHealth API
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

api/api.go Outdated
v2.Run(cfg.GrpcPort, tlsConfig, cfg.PaginationKey, cfg.CertFile, cfg.KeyFile, store)
}

// Run V1 API
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

api/v1/routes.go Outdated
@@ -24,7 +24,7 @@ import (

"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
log "github.com/Sirupsen/logrus"
Copy link
Contributor

Choose a reason for hiding this comment

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

In some files this is the first import and in this one it's the last. Did you run GoImports on this? They should be ordered alphabetically.

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

message Vulnerability{
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 file in an idiomatic format? The non-space-separated { seems strange.
There's got to be a protobuf linter that has opinions on this stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope; based on the style, I shouldn't use the camel case for fields: https://developers.google.com/protocol-buffers/docs/style

Copy link
Contributor

Choose a reason for hiding this comment

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

Change this so that you always have the space in between the message name and the curly bracket message Name { instead of message Name{


message VulnerabilityWithLayers{
Vulnerability Vulnerability = 1;
repeated OrderedLayerName OrderedLayersIntroducingVulnerability = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can just called this LayersIntroducingVulnerabilty, it was given this verbose name because the original LayersIntroducingVulnerability was unordered and we didn't want to break backwards-compat in the v1 API.

api/v2/rpc.go Outdated
if r.GetLimit() <= 0 {
return nil, status.Error(codes.InvalidArgument, "Failed to provide page limit")
}
// get page token
Copy link
Contributor

Choose a reason for hiding this comment

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

remove these comments

api/v2/rpc.go Outdated
} else if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &google_protobuf1.Empty{}, nil
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 idiomatic? I'm going to ask someone.

api/v2/server.go Outdated
statusStr := strconv.Itoa(lrw.StatusCode)
if lrw.StatusCode == 0 {
statusStr = "???"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably stop doing this and and just assume all Prometheus requests responded with 200, but that can be handled in a separate PR.

api/v2/util.go Outdated
}

// TODO: Remove this Legacy compability code once the database is revised
// We assume every layer is the root of an ancestry for api being compatible with the current implementation of the database
Copy link
Contributor

Choose a reason for hiding this comment

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

comment rules

api/v2/util.go Outdated
layer database.Layer
err error
)
// iteratively query the layer until we find the one layer requested
Copy link
Contributor

Choose a reason for hiding this comment

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

comment rules

"errors"
"time"

fernet "github.com/fernet/fernet-go"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you actually need this? I'm pretty sure without it, it still imports as fernet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgot to check, it's automatically imported like that

// See the License for the specific language governing permissions and
// limitations under the License.

package token
Copy link
Contributor

Choose a reason for hiding this comment

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

// Package token implements ...


message LayersIntroducingVulnerabilty{
Vulnerability vulnerability = 1;
repeated OrderedLayerName ordered_layers_introducing_vulnerability = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

layers_introducing_vulnerability or maybe even just layers is sufficient because of the message's name and OrderedLayerName tells you that it's ordered

message Layer{
string name = 1;
repeated string namespace_names = 2;
string parent_name = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this in v2?

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

message Vulnerability{
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this so that you always have the space in between the message name and the curly bracket message Name { instead of message Name{

Notification notification = 1;
}

service ClairAPIService{
Copy link
Contributor

Choose a reason for hiding this comment

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

I talked to the etcd team and I think it's a nice pattern to separate Services by resource, so we can have two Services that we register to the same grpc server.

service AncestryService {
   rpc GetAncestry(GetAncestryRequest) returns (GetAncestryResponse) { ... };
   rpc PostAncestry(PostAncestryRequest) returns (PostAncestryResponse) { ... };
}

service NotificationService {
  rpc GetNotification(GetNotificationRequest) returns (GetNotificationResponse) { ... };
  rpc DeleteNotification(DeleteNotificationRequest) returns (DeleteNotificationResponse) { ... };
}

Newly designed API defines Ancestry as a set of layers
and shrinked the api to only the most used apis:
post ancestry, get layer, get notification, delete notification

Fixes quay#98
@jzelinskie jzelinskie merged commit 6c9a131 into quay:master Jun 30, 2017
KeyboardNerd pushed a commit to KeyboardNerd/clair that referenced this pull request Feb 2, 2018
v2 api with gRPC and gRPC gateway
@KeyboardNerd KeyboardNerd deleted the grpc branch March 11, 2018 18:50
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