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

feat(dqlite): add service layer for cloud image metadata #18121

Merged
merged 2 commits into from
Sep 23, 2024

Conversation

gfouillet
Copy link
Contributor

@gfouillet gfouillet commented Sep 19, 2024

Add the service layer for cloud image metadata.

It is basically a wrapper to state, with few functionnalities:

  • Validation of metadata (missing required attributes, empty image ID or invalid architectures)
  • Groups metadata by source while fetching (to be as close as possible to actual interface)

Checklist

  • Code style: imports ordered, good names, simple structure, etc
  • Comments saying why design decisions were made
  • Go unit tests, with comments saying what you're testing
    - [ ] Integration tests, with comments saying what you're testing
    - [ ] doc.go added or updated in changed packages

QA steps

Unit test are self-sufficient

Documentation changes

None

Links

Jira card: JUJU-6630

@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch 4 times, most recently from f360fbb to a07610b Compare September 19, 2024 14:12
Copy link
Member

@nvinuesa nvinuesa left a comment

Choose a reason for hiding this comment

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

First pass, looking very good. Just a few small remarks/questions.

core/cloudimagemetadata/types.go Show resolved Hide resolved
// invalid.
func (s Service) SaveMetadata(ctx context.Context, metadata []cloudimagemetadata.Metadata) error {
if len(metadata) == 0 {
return errors.NothingToSave
Copy link
Member

Choose a reason for hiding this comment

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

Why this error? We don't return it on the legacy state, and it does feel a bit counter-intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right, it is not on the legacy. I think somewhere in my mind I think that caller shouldn't even try to save empty metadata... But there would be inconsistent of some generic function in go behave (like errors.Join).

Will return nil.


supportedArchitectures := s.st.SupportedArchitectures(context.Background())
if !supportedArchitectures.Contains(m.Arch) {
return jujuerrors.Errorf("unsupported architecture %s (should be any of %s): %w", m.Arch, supportedArchitectures.Values(), errors.Invalid)
Copy link
Member

Choose a reason for hiding this comment

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

Just to be sure, errors.NotValid(..) returns an error that satisfies errors.Is(err, errors.Invalid) right? If not, why not using errors.NotValidf(...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It returns an error who satisfies github.com/juju/juju/domain/cloudimagemetadata/errors.Invalid.

I don't know from which errors package you get error.NotValidf but I assumes it comes from github.com/juju/juju/errors which we don't use anymore, as far i understand, in favor of domain-scoped errors.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see, it's from your domain errors' package. That's fine then. IMO you should name the error NotValid as well, just for consistency because that's what we have all around our codebase.

@hpidcock hpidcock added the 4.0 label Sep 20, 2024
@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch from a07610b to 889aadf Compare September 20, 2024 08:21
@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch 2 times, most recently from d4e7bfc to da8f8f4 Compare September 20, 2024 12:21
Copy link
Member

@nvinuesa nvinuesa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes!

// fields empty.
Invalid = errors.ConstError("invalid metadata")
NotValid = errors.ConstError("invalid metadata")
Copy link
Member

Choose a reason for hiding this comment

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

🚀

Copy link
Member

@SimonRichardson SimonRichardson left a comment

Choose a reason for hiding this comment

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

Fix this context issue, then this is good to go.

Comment on lines 65 to 67
if imageId == "" {
return errors.EmptyImageID
}
Copy link
Member

Choose a reason for hiding this comment

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

Thank-you.

domain/cloudimagemetadata/service/service.go Outdated Show resolved Hide resolved
@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch from da8f8f4 to 513a5e6 Compare September 20, 2024 14:03
Copy link
Member

@SimonRichardson SimonRichardson left a comment

Choose a reason for hiding this comment

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

Thanks for guiding this through.

@gfouillet
Copy link
Contributor Author

/merge

@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch from 513a5e6 to 2c14502 Compare September 20, 2024 15:15
@@ -0,0 +1,16 @@
// Copyright 2023 Canonical Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

todo: s/2023/2024


// FindMetadata retrieves a list of cloud image metadata based on the provided criteria.
// It returns the matched metadata or a [github.com/juju/juju/domain/cloudimagemetadata/errors.NotFound] error
// If there are no one.
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
// If there are no one.
// if there are not one.

}

// SaveMetadata saves the provided cloud image metadata if non-empty and valid.
// It returns a [errors.NothingToSave] if the input are empty, or a [errors.NotValid] if at least one of the inputs are
Copy link
Member

Choose a reason for hiding this comment

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

question: where is error NothingToSave defined? Looks like the method returns nil in this case, which is preferable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not. Removed it during review, forgot to remove this part of comment. Thanks for asking, I removed it.

return s.st.SaveMetadata(ctx, metadata)
}

// DeleteMetadataWithImageID removes all the metadata associated with the given imageID from the state.
Copy link
Member

Choose a reason for hiding this comment

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

todo: add errors returned to the comments.


var missing []string
if m.Version == "" {
missing = append(missing, "version")
Copy link
Member

Choose a reason for hiding this comment

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

love it - gathering all the errors before returning.

@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch from 2c14502 to 807d1c5 Compare September 23, 2024 07:40
Signed-off-by: Guillaume Fouillet <guillaume.fouillet@canonical.com>
- Before this commit, the code lacked a service layer interface for managing cloud image metadata.
- After this commit, a service interface for cloud image metadata management is added along with
  its unit tests.

This commit introduces a new service layer for managing cloud image metadata, including methods for
saving, deleting, and finding metadata.

Signed-off-by: Guillaume Fouillet <guillaume.fouillet@canonical.com>
@gfouillet gfouillet force-pushed the v4/dqlite/cloudimagemetadata/service branch from 807d1c5 to bc2521b Compare September 23, 2024 11:31
@gfouillet
Copy link
Contributor Author

/merge

@jujubot jujubot merged commit a5c1e1b into juju:main Sep 23, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants