-
Notifications
You must be signed in to change notification settings - Fork 43
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
Reconcile entity registration #3562
Conversation
…acklok/minder into reconcile-entity-registration
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
proto/minder/v1/minder.proto
Outdated
Context context = 1; | ||
string entity = 2; | ||
|
||
string provider = 3 [deprecated=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.
let's not add deprecated fields into new messages.
proto/minder/v1/minder.proto
Outdated
@@ -342,6 +342,17 @@ service RepositoryService { | |||
relation: RELATION_REPO_CREATE | |||
}; | |||
} | |||
rpc ReconcileEntityRegistration(ReconcileEntityRegistrationRequest) returns (ReconcileEntityRegistrationResponse) { | |||
option (google.api.http) = { | |||
post: "/api/v1/provider/{provider}/register_all" |
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 must have made a copy-paste in the original ticket. What I put in the additional bindings is what I think we should use as the REST API path, so post: "/api/v1/provider/register_all"
. Which provider are we reconciling should be read from the context.
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 honestly thought this would be more appropriate as well. Thanks.
projectID, | ||
providerName, | ||
) | ||
if err != nil { |
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 know this was in the original code, but could we also zerolog
the error message?
|
||
repos, err := s.fetchRepositoriesForProvider(ctx, projectID, providerName, provider) | ||
if err != nil { | ||
errorProvs = append(errorProvs, providerName) |
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.
since the handler only errors out if all providers fail could we zerolog
the error message? (I guess there would realistically be only one provider though)
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.
Line 75 already ships the error with the log as a structured field, do you mean something more detailed than that?
continue | ||
} | ||
|
||
if s.publishEntityMessage(&l, msg) != nil { |
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.
since we are checking for an error here could we write if err := s.publishEntityMessage(&l, msg); err != nil {
(we're probably not logging the err from this call underneath)
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.
Ah 🤦 , my bad, thanks
@@ -0,0 +1,132 @@ | |||
// Copyright 2023 Stacklok, Inc |
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.
it's 2024 :-P
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.
looking good, a couple of nits here and there, but the main thing is to fix the protobuf to not include the provider (sorry, my fault for writing it wrong in the issue description)
proto/minder/v1/minder.proto
Outdated
@@ -342,6 +342,17 @@ service RepositoryService { | |||
relation: RELATION_REPO_CREATE | |||
}; | |||
} | |||
rpc ReconcileEntityRegistration(ReconcileEntityRegistrationRequest) returns (ReconcileEntityRegistrationResponse) { |
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.
One more thing, because this RPC can register any types, shouldn't it be part of the provider service? (See also its http path..)
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 agree, it's better placed under provider service.
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 thought about this at the beginning as well but then I noticed that the provider service contains RPCs explicitly related to CRUD operations for the provider entity itself. Indeed, the repository service is not a suitable place.
Still, I've moved this to the Provider service as it's the closest logically related one.
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.
First batch of minor comments. Thanks for the great work @teodor-yanev!
// handleEntityAddEvent handles the entity add event. | ||
// Although this method is meant to be generic and handle all types of entities, | ||
// it currently only does so for repositories. | ||
// Todo: Utilise for other entities when such are supported. |
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.
Thank you so much for adding this comment! 🙏
// fetchRepositoriesForProvider fetches repositories for a given provider | ||
// | ||
// Returns a list of repositories that with an up-to-date status of whether they are registered | ||
func (s *Server) fetchRepositoriesForProvider( | ||
ctx context.Context, | ||
projectID uuid.UUID, | ||
providerName string, | ||
provider v1.Provider, | ||
) ([]*pb.UpstreamRepositoryRef, 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.
suggestion: this is now used from multiple handlers and should probably be moved to a separate source file; I'm not too religious about this and I'm not sure where to put it, @jhrozek what do you think about it?
Please bear in mind that I think this can be addressed in a follow up PR.
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 agree it would be nice but let's do it in a separate PR to not delay this one longer than needed.
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.
Yeah, I agree with both of the statements.
proto/minder/v1/minder.proto
Outdated
@@ -342,6 +342,17 @@ service RepositoryService { | |||
relation: RELATION_REPO_CREATE | |||
}; | |||
} | |||
rpc ReconcileEntityRegistration(ReconcileEntityRegistrationRequest) returns (ReconcileEntityRegistrationResponse) { |
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 agree, it's better placed under provider service.
|
||
repos, err := s.fetchRepositoriesForProvider(ctx, projectID, providerName, provider) | ||
if err != nil { | ||
errorProvs = append(errorProvs, providerName) |
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.
Line 75 already ships the error with the log as a structured field, do you mean something more detailed than that?
// Todo: We don't support other entities yet. This should be updated when we do. | ||
entityType := in.GetEntity() | ||
if pb.EntityFromString(entityType) != pb.Entity_ENTITY_REPOSITORIES { | ||
return nil, util.UserVisibleError(codes.Internal, "entity type %s not supported", entityType) |
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.
One small change please, this should not return codes.Internal
, but codes.InvalidArgument
instead. Mainly so that we get the proper HTTP error code through the gateway (now we get a 500)
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.
Yep, the copy/pasta betrayed me, thanks!
Fixed
Summary
Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.
Fixes #3268
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Calling the method via the CLI. (note: please ignore the "nil" as it was part of the print testing)
For simplicity of the testing, I added this as an additional operation as part of the "register" flow. I'm mentioning this in case the screenshot seems confusing at first.
Review Checklist: