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

Reconcile entity registration #3562

Merged
merged 20 commits into from
Jun 14, 2024
Merged

Conversation

teodor-yanev
Copy link
Contributor

@teodor-yanev teodor-yanev commented Jun 8, 2024

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:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

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.

image

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@teodor-yanev teodor-yanev requested a review from a team as a code owner June 8, 2024 00:38
@teodor-yanev teodor-yanev self-assigned this Jun 8, 2024
@teodor-yanev teodor-yanev marked this pull request as draft June 8, 2024 00:38
@teodor-yanev teodor-yanev marked this pull request as ready for review June 12, 2024 07:38
@teodor-yanev teodor-yanev changed the title wip: reconcile entity registration Reconcile entity registration Jun 12, 2024
@coveralls
Copy link

Coverage Status

coverage: 53.19% (+0.07%) from 53.12%
when pulling 6047294 on reconcile-entity-registration
into bb173c2 on main.

@coveralls
Copy link

Coverage Status

coverage: 53.19% (+0.07%) from 53.12%
when pulling 58bd3b5 on reconcile-entity-registration
into bb173c2 on main.

Context context = 1;
string entity = 2;

string provider = 3 [deprecated=true];
Copy link
Contributor

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.

@@ -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"
Copy link
Contributor

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.

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 honestly thought this would be more appropriate as well. Thanks.

projectID,
providerName,
)
if err != nil {
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

it's 2024 :-P

Copy link
Contributor

@jhrozek jhrozek left a 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)

@coveralls
Copy link

Coverage Status

coverage: 53.311% (+0.09%) from 53.226%
when pulling 703a1e7 on reconcile-entity-registration
into cb2e850 on main.

@coveralls
Copy link

Coverage Status

coverage: 53.321% (+0.1%) from 53.226%
when pulling 703a1e7 on reconcile-entity-registration
into cb2e850 on main.

@@ -342,6 +342,17 @@ service RepositoryService {
relation: RELATION_REPO_CREATE
};
}
rpc ReconcileEntityRegistration(ReconcileEntityRegistrationRequest) returns (ReconcileEntityRegistrationResponse) {
Copy link
Contributor

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..)

Copy link
Contributor

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.

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 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.

Copy link
Contributor

@blkt blkt left a 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!

internal/controlplane/handlers_entities.go Outdated Show resolved Hide resolved
Comment on lines +30 to +33
// 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.
Copy link
Contributor

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! 🙏

Comment on lines +352 to +360
// 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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

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 agree with both of the statements.

proto/minder/v1/minder.proto Outdated Show resolved Hide resolved
@@ -342,6 +342,17 @@ service RepositoryService {
relation: RELATION_REPO_CREATE
};
}
rpc ReconcileEntityRegistration(ReconcileEntityRegistrationRequest) returns (ReconcileEntityRegistrationResponse) {
Copy link
Contributor

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)
Copy link
Contributor

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?

@coveralls
Copy link

Coverage Status

coverage: 53.453% (+0.2%) from 53.226%
when pulling 74bb67b on reconcile-entity-registration
into cb2e850 on main.

@coveralls
Copy link

Coverage Status

coverage: 53.468% (+0.2%) from 53.226%
when pulling 64a7505 on reconcile-entity-registration
into cb2e850 on main.

// 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)
Copy link
Contributor

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)

Copy link
Contributor Author

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

@coveralls
Copy link

Coverage Status

coverage: 53.464% (+0.2%) from 53.226%
when pulling 271269f on reconcile-entity-registration
into cb2e850 on main.

@teodor-yanev teodor-yanev merged commit 266f0f4 into main Jun 14, 2024
22 checks passed
@teodor-yanev teodor-yanev deleted the reconcile-entity-registration branch June 14, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants