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

Take the property service into use in webhook and repository service #4299

Merged
merged 8 commits into from
Aug 29, 2024

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Aug 28, 2024

Summary

The PR moves us in the direction of using the generic entity tables for
repositories. On receiving a webhook, the repository entity along with the
properties are refreshed if needed (with caching provided by the property
service) and returns the entity and its properties. If this is a good
approach, we can also use it for repo reconciliation and profile
reconciliation. When sending the event, still the Repository protobuf message
is sent, but we could as well modify the entityInfoWrapper code to just accept
a message with the entity and properties in a more generic way.

The refresh is handled by a new method of the github repository service - we
could even use a more generic way and not code up a per-property, but we use
the repo-specific layer to migrate the "legacy" table entries to properties as
they are refreshed.

Because we store some attributes along with the repos that are not fetched
from upstream (webhook-related), we treat them as operational attributes and
carry them over during updates. What the operational attributes are is handled
by the provider without minder-core knowing or caring what they are.

Fixes: #4179

Change Type

  • 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

unit test + manual testing

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.

database/query/entities.sql Outdated Show resolved Hide resolved
minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1"
)

type EntityInstance struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a convenience struct to avoid returning and carrying around both db.EntityInstance and properties when handling an entity with properties. We might want to use the newly introduced protobuf message instead.

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 that we should not use the database structures but should instead have either a middle-struct (as you did here) or even the protobuf. I leave that to your discretion.

@@ -56,6 +56,8 @@ type Provider interface {
// The name is used to identify the entity within minder and is how
// it will be stored in the database.
GetEntityName(entType minderv1.Entity, props *properties.Properties) (string, error)
// OperationalProperties returns the operational properties for an entity
OperationalProperties(entType minderv1.Entity) []string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: Can we come up with a way to expose the operational properties without adding a new method to the generic Provider interface? It feels like the interface is getting too big already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to expose or filter them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to filter them because at the same time we need to be able to remove properties that were deleted upstream but we need to retain the operational attributes like hook ID.
Anyway, we discussed that offline and agreed to move the attributes handling to the provider completely so that minder-core is oblivious to their existence.

@jhrozek
Copy link
Contributor Author

jhrozek commented Aug 29, 2024

@JAORMX I think the only thing missing now is to fix up all the repeated webhook tests..

@jhrozek jhrozek marked this pull request as ready for review August 29, 2024 10:39
If we had called these methods in a transaction, we would have
effectivelly created another parallel transaction which might cause
entities to not be referenced correctly.
These will be useful later.
This is just a shortcut to avoid passing the properties and project ID
and entity etc around
This makes it easier to handle multiple entities inside the github
provider as all that is needed is to implement the PropertyFetcher
interface. It also makes moves the logic around formatting the name and
what properties are operational into the provider to code that is
per-entity.
minder saves attributes like hook ID which do not come from the upstream
entity. We need to avoid deleting them on updates.
Changes fetchRepo to refresh the repository being processed and return
an EntityInstance model structure instead of a database repo

Related: mindersec#4173
@coveralls
Copy link

Coverage Status

coverage: 53.658% (-0.3%) from 53.947%
when pulling ae503b4 on jhrozek:prop_svc
into e0376fe on stacklok:main.

@jhrozek jhrozek merged commit b1b1484 into mindersec:main Aug 29, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persist repository properties in database
3 participants