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

remove controller watcher #1478

Conversation

SimoneDutto
Copy link
Contributor

@SimoneDutto SimoneDutto commented Dec 3, 2024

Description

In this PR we remove the Model Watcher controller from JIMM.
To do so:

  • we've handled the modeldestroy with a cleanup routine

Removed:

  • jujuclient code
  • most of the watcher tests

Fixes JIRA/GitHub issue number

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

Test instructions

Notes for code reviewers

@SimoneDutto SimoneDutto requested a review from a team as a code owner December 3, 2024 15:13
@SimoneDutto SimoneDutto marked this pull request as draft December 3, 2024 15:13
@SimoneDutto SimoneDutto marked this pull request as ready for review December 4, 2024 15:17
Copy link
Contributor Author

@SimoneDutto SimoneDutto Dec 4, 2024

Choose a reason for hiding this comment

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

in the previous pr i've renamed the watcher_test.go file to avoid fixing useless tests failing, but now this commit seems to add new test in this watcher_test.go

It is not, I've just removed all tests regarding ModelWatcher and readded the ModelSummaryWatcher tests.

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.

Nice stuff! Just 2 comments

ctx, cancel := context.WithCancel(ctx)
defer cancel()

err := j.DB().ForEachModel(ctx, func(m *dbmodel.Model) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of for each models, rather list models that are dying.

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, i was battled because i feel like creating a method in the database called GetDyingModels() is not very clever. I'd rather add a List(filter) method in our db methods.
But i remember last time there was some opposition to that, and rather just using "ForEach" to keep it consistent.

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 foreach is fine honestly and dialing the controllers makes a lot of sense to me. Why would we have a db method?

if m.Life == state.Dying.String() {
// if the model is dying and not found by querying the controller we can assume it is dead.
// And safely delete the reference from our db.
api, err := j.dialModel(ctx, &m.Controller, m.ResourceTag())
Copy link
Contributor

Choose a reason for hiding this comment

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

What about following the same pattern as the previous code. Something like:

  1. Start a routine for each controller.
  2. Open API connection to controller.
  3. GetDyingModels(ThisController)
  4. Query controller for model status.

If the routine returns with an error, the caller can reschedule after e.g. 30s. It just saves us for making a new connection for each model. Granted this may be a premature optimisation but it feels cleaner and aligns with how the watcher worked before anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially we could do something like this.
However I though starting a routine for each controller feels like a useless optimization because we run this cleanup every 1 minute, so do we care how long the cleanup is? No user is waiting for this to finish.

Saving the connection for each model is fine, if we move towards listing the dying model.

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.

this looks nice, but i have some questions/suggestions.

cmd/jimmsrv/service/service.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Outdated Show resolved Hide resolved
return nil
}
if err := api.ModelInfo(ctx, &jujuparams.ModelInfo{UUID: m.UUID.String}); err != nil {
// Some versions of juju return unauthorized for models that cannot be found.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please explain which versions return which error?

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 copy/pasted this from the watcher code. I honestly have no idea.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be nice to verify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2d232e1
it's a 3 years old comment from Martin

internal/jimm/model_cleanup.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Show resolved Hide resolved
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.

LGTM with a few nitpicks/suggestions

cmd/jimmsrv/main.go Show resolved Hide resolved
internal/jimm/model.go Outdated Show resolved Hide resolved
internal/jimm/model.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Show resolved Hide resolved
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm, just some minor comments. Please do them :) good work!

internal/jimm/model.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup.go Outdated Show resolved Hide resolved
internal/jimm/model_cleanup_test.go Show resolved Hide resolved
internal/jimm/watcher_test.go Show resolved Hide resolved
@SimoneDutto SimoneDutto merged commit 24bde4c into canonical:slim-jimm-model Dec 10, 2024
4 checks passed
SimoneDutto added a commit that referenced this pull request Dec 10, 2024
* remove controller watcher
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.

4 participants