Skip to content

Commit

Permalink
refactor: implement measure
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Jan 3, 2024
1 parent 8dbfc99 commit 90ab49a
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/measure/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func Readyz() runtime.Handle {
return func(c *gin.Context) {
d, ok := health.MustValidate(c, []string{"k8sctrl", "casdoor"})
d, ok := health.MustValidate(c, []string{"database"})
if !ok {
c.String(http.StatusServiceUnavailable, d)
return
Expand Down
3 changes: 3 additions & 0 deletions pkg/database/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ type BoltDriver interface {

// IsReadOnly returns whether the database is opened in read-only mode.
IsReadOnly() bool

// Path returns the path to the file backing the database.
Path() string
}
20 changes: 20 additions & 0 deletions pkg/database/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package database

import (
"context"
"errors"
"os"
)

func IsConnected(ctx context.Context, db BoltDriver) error {
_, err := os.Stat(db.Path())
if err != nil {
return err
}

if db.IsReadOnly() {
return errors.New("invalid database storage file: read-only")
}

return nil
}
Loading

0 comments on commit 90ab49a

Please sign in to comment.