Skip to content

Commit

Permalink
Merge branch 'v3' into fix-model-default-order
Browse files Browse the repository at this point in the history
  • Loading branch information
alesstimec authored Dec 16, 2024
2 parents 6760ea5 + 486ff61 commit fbee42c
Show file tree
Hide file tree
Showing 55 changed files with 1,444 additions and 2,446 deletions.
10 changes: 2 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
## Description

The what and why - include a summary of the change, describe what it does, and include relevant motivation and context.

Fixes _JIRA/GitHub issue number_
<!-- *(mandatory)* Detail your pull request, with the what, why and how. -->

## Engineering checklist
*Check only items that apply*
<!-- *Check only items that apply* -->

- [ ] Documentation updated
- [ ] Covered by unit tests
- [ ] Covered by integration tests

## Test instructions
<!-- *(optional)* Describe any non-standard test instructions and configuration settings. Delete this section if not applicable. -->

## Notes for code reviewers
<!-- *(optional)* Mention any relevant information for code reviewers. Delete this section if not applicable. -->
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ qa-lxd
/cloudinit.temp.yaml

local/traefik/certs/ca.srl

db_schemas
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"go.lintFlags": [
"--fast"
],
"go.lintOnSave": "workspace",
"go.testEnvVars": {
"JIMM_TEST_LOG_SQL": "false",
"TEST_LOGGING_CONFIG": "ERROR" // this is the logging level for juju connsuite logs
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ lint:
check: version/commit.txt version/version.txt lint
go test -timeout 30m $(PROJECT)/... -cover

# generates database schemas locally to inspect them.
generate-schemas:
@./local/jimm/generate_db_schemas.sh

clean:
go clean $(PROJECT)/...
-$(RM) version/commit.txt version/version.txt
Expand Down
8 changes: 0 additions & 8 deletions cmd/jimmctl/cmd/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"sort"
"strings"
"time"

petname "github.com/dustinkirkland/golang-petname"
"github.com/google/uuid"
Expand Down Expand Up @@ -542,13 +541,6 @@ func (s *relationSuite) TestCheckRelationViaSuperuser(c *gc.C) {
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Life: "alive",
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now().UTC().Truncate(time.Millisecond),
Valid: true,
},
},
}

err = db.AddModel(ctx, &model)
Expand Down
37 changes: 21 additions & 16 deletions cmd/jimmsrv/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,6 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.mux.ServeHTTP(w, req)
}

// WatchControllers connects to all controllers and starts an AllWatcher
// monitoring all changes to models. WatchControllers finishes when the
// given context is canceled, or there is a fatal error watching models.
func (s *Service) WatchControllers(ctx context.Context) error {
w := jimm.Watcher{
Database: s.jimm.Database,
Dialer: s.jimm.Dialer,
}
return w.Watch(ctx, 10*time.Minute)
}

// WatchModelSummaries connects to all controllers and starts a
// ModelSummaryWatcher for all models. WatchModelSummaries finishes when
// the given context is canceled, or there is a fatal error watching model
Expand Down Expand Up @@ -275,6 +264,22 @@ func (s *Service) OpenFGACleanup(ctx context.Context, trigger <-chan time.Time)
}
}

// CleanupDyingModels triggers every `trigger` time and calls the jimm methods to cleanup dying models.
func (s *Service) CleanupDyingModels(ctx context.Context, trigger <-chan time.Time) error {
for {
select {
case <-trigger:
err := s.jimm.CleanupDyingModels(ctx)
if err != nil {
zapctx.Error(ctx, "dying models cleanup", zap.Error(err))
continue
}
case <-ctx.Done():
return nil
}
}
}

// Cleanup cleans up resources that need to be released on shutdown.
func (s *Service) Cleanup() {
// Iterating over clean up function in reverse-order to avoid early clean ups.
Expand Down Expand Up @@ -498,11 +503,6 @@ func NewService(ctx context.Context, p Params) (*Service, error) {
func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
// on the leader unit we start additional routines
if s.isLeader {
// the leader unit connects to all controllers' AllWatcher
svc.Go(func() error {
return s.WatchControllers(ctx)
})

// audit log cleanup routine
if s.auditLogCleanupPeriod != 0 {
svc.Go(func() error {
Expand All @@ -524,6 +524,11 @@ func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
svc.Go(func() error {
return s.OpenFGACleanup(ctx, time.NewTicker(6*time.Hour).C)
})

// CleanupDyingModels cleanup - cleans up all dying models
svc.Go(func() error {
return s.CleanupDyingModels(ctx, time.NewTicker(time.Minute).C)
})
}

// all units periodically update their controller/model metrics
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.24.0
golang.org/x/oauth2 v0.22.0
golang.org/x/sync v0.9.0
golang.org/x/sync v0.10.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/errgo.v1 v1.0.1
gopkg.in/httprequest.v1 v1.2.1
Expand Down Expand Up @@ -314,12 +314,12 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/api v0.154.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1267,6 +1269,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1339,6 +1343,8 @@ golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -1352,6 +1358,8 @@ golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1369,6 +1377,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
19 changes: 0 additions & 19 deletions internal/db/applicationoffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"database/sql"
"sort"
"testing"
"time"

qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -82,16 +81,7 @@ func initTestEnvironment(c *qt.C, db *db.Database) testEnvironment {
Controller: env.controller,
CloudRegion: env.cloud.Regions[0],
CloudCredential: env.cred,
Type: "iaas",
IsController: false,
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
}
c.Assert(db.DB.Create(&env.model).Error, qt.IsNil)

Expand All @@ -105,16 +95,7 @@ func initTestEnvironment(c *qt.C, db *db.Database) testEnvironment {
Controller: env.controller,
CloudRegion: env.cloud.Regions[0],
CloudCredential: env.cred,
Type: "iaas",
IsController: false,
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
}
c.Assert(db.DB.Create(&env.model1).Error, qt.IsNil)

Expand Down
3 changes: 3 additions & 0 deletions internal/db/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (d *Database) ForEachModel(ctx context.Context, f func(m *dbmodel.Model) er

// GetModelsByUUID retrieves a list of models where the model UUIDs are in
// the provided modelUUIDs slice.
//
// If the UUID cannot be resolved to a model, it is skipped from the result and
// no error is returned.
func (d *Database) GetModelsByUUID(ctx context.Context, modelUUIDs []string) (_ []dbmodel.Model, err error) {
const op = errors.Op("db.GetModelsByUUID")

Expand Down
Loading

0 comments on commit fbee42c

Please sign in to comment.