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

slim clouds #1512

Closed
wants to merge 1 commit into from
Closed

Conversation

SimoneDutto
Copy link
Contributor

@SimoneDutto SimoneDutto commented Jan 8, 2025

Description

In this pr we slim clouds, removing non-essential fields.

@SimoneDutto SimoneDutto requested a review from a team as a code owner January 8, 2025 13:51
@SimoneDutto SimoneDutto requested a review from kian99 January 8, 2025 13:52
@SimoneDutto SimoneDutto force-pushed the JUJU-7135/slim-clouds branch 6 times, most recently from 8cc9a90 to 65b53fa Compare January 9, 2025 10:50
@SimoneDutto SimoneDutto force-pushed the JUJU-7135/slim-clouds branch from 65b53fa to 6f18463 Compare January 9, 2025 12:47
Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

The approach looks good to me.. a few comments..

return jCl, nil
}

func (j *JIMM) GetClouds(ctx context.Context, user *openfga.User) (map[string]jujuparams.Cloud, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

godoc, please

}, nil
}

func (j *JIMM) ListCloudsInfo(ctx context.Context, user *openfga.User, all bool) ([]jujuparams.ListCloudInfoResult, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

godoc, please

@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
Copy link
Collaborator

Choose a reason for hiding this comment

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

new line

@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
Copy link
Collaborator

Choose a reason for hiding this comment

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

new line

@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
Copy link
Collaborator

Choose a reason for hiding this comment

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

new line, please

return cl, errors.E(op, err)
return jujuparams.CloudInfo{}, errors.E(op, err)
}
// TODO (SimoneDutto): refactor this to use `user.IsCloudAdmin()`
Copy link
Collaborator

Choose a reason for hiding this comment

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

where do we require admin access to the cloud?

Copy link
Contributor

@kian99 kian99 left a comment

Choose a reason for hiding this comment

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

I like how it's slimmed things but I'm a bit hesitant on performance, even though it's not a huge deal. I'm wondering if we want/need to slim down clouds. The gains seem marginal but curious to hear what you think after doing this.

@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
package db_test
Copy link
Contributor

Choose a reason for hiding this comment

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

newline

@@ -26,29 +26,8 @@ type Cloud struct {
// cloud is hosted.
HostCloudRegion string
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 keep this?

@@ -0,0 +1,3 @@
-- remove non essential fields from cloud.
ALTER TABLE clouds DROP COLUMN auth_types, DROP COLUMN endpoint, DROP COLUMN identity_endpoint,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a space after the comment

@@ -20,35 +20,173 @@ import (
ofganames "github.com/canonical/jimm/v3/internal/openfga/names"
)

// GetUserCloudAccess returns users access level for the specified cloud.
func (j *JIMM) GetUserCloudAccess(ctx context.Context, user *openfga.User, cloud names.CloudTag) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is already a method in the permission manager that does this. Can you use that instead?

if err := j.Database.GetCloud(ctx, &cl); err != nil {
return jujuparams.Cloud{}, errors.E(op, err)
}
// TODO (SimoneDutto): refactor this to use `user.IsCloudAdmin()`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do that now?

// contain the authentcated user.
func (j *JIMM) GetCloud(ctx context.Context, user *openfga.User, tag names.CloudTag) (jujuparams.Cloud, error) {
const op = errors.Op("jimm.CloudInfo")
zapctx.Info(ctx, string(op))
Copy link
Contributor

Choose a reason for hiding this comment

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

Was thinking about this sometime last year and whether we want it. If we do want it then it might be better suited to go inside the jujuapi.FindMethod() class of functions so that we don't clutter up these functions.

if err != nil {
return jCl, errors.E(op, err)
}
jCl.IsControllerCloud = false // jimm doesn't know where is deployed, so none of the clouds should have this field set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
jCl.IsControllerCloud = false // jimm doesn't know where is deployed, so none of the clouds should have this field set.
jCl.IsControllerCloud = false // jimm doesn't know where it's deployed, so none of the clouds should have this field set.

Comment on lines +90 to +96
for _, cl := range clouds {
cloud, err := j.getCloudFromController(ctx, cl)
if err != nil {
return nil, errors.E(op, err)
}
results[cl.ResourceTag().String()] = cloud
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a concern that this will be annoyingly slow. Not so slow that it's bad but since getting a cloud requires a sequential call to a controller... I've experienced running juju <command> to take several seconds sometimes so I hope we don't have that issue here.
Some caching in the future will of course help and then be similar in a way to what the database was doing.

controllers = append(controllers, c.Controller)
}
}
err := j.firstSuccessfulController(ctx, controllers, func(api API) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we will always be calling the first controller in the list most frequently. We could randomise the list to do some round-robin if we want.

@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
Copy link
Contributor

Choose a reason for hiding this comment

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

newline

@kian99
Copy link
Contributor

kian99 commented Jan 10, 2025

Points we discussed on this:

  • Cloud fields are static and we don't get much gain here versus models where we were able to get rid of the watcher.
  • This might be annoyingly slow if latency to controllers is high and we need to list all clouds.
  • Returning the cloud info from the first controller that matches might not be accurate if different controllers are aware of different regions.
  • Making this more performant would introduce a cache and mirror what we're currently doing with the database.

@SimoneDutto
Copy link
Contributor Author

Points we discussed on this:

  • Cloud fields are static and we don't get much gain here versus models where we were able to get rid of the watcher.
  • This might be annoyingly slow if latency to controllers is high and we need to list all clouds.
  • Returning the cloud info from the first controller that matches might not be accurate if different controllers are aware of different regions.
  • Making this more performant would introduce a cache and mirror what we're currently doing with the database.

After the discussion the decision is to close this pr. Moving forward we've decided not to remove from our db static fields.

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.

3 participants