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

Add backend interface for dbStats #3267

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/backends/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Database interface {
CreateCollection(context.Context, *CreateCollectionParams) error
DropCollection(context.Context, *DropCollectionParams) error
RenameCollection(context.Context, *RenameCollectionParams) error

Stats(context.Context, *StatsParams) (*StatsResult, error)
}

// databaseContract implements Database interface.
Expand Down Expand Up @@ -184,6 +186,33 @@ func (dbc *databaseContract) RenameCollection(ctx context.Context, params *Renam
return err
}

// StatsParams represents the parameters of Database.Stats method.
type StatsParams struct{}

// StatsResult represents the results of Database.Stats method.
//
// TODO https://github.com/FerretDB/FerretDB/issues/2447
type StatsResult struct {
CountCollections int64
CountObjects int64
CountIndexes int64
SizeTotal int64
SizeIndexes int64
SizeCollections int64
}

// Stats returns statistics about the database.
//
// Database may not exist; that's not an error.
func (dbc *databaseContract) Stats(ctx context.Context, params *StatsParams) (*StatsResult, error) {
defer observability.FuncCall(ctx)()

res, err := dbc.db.Stats(ctx, params)
checkError(err)

return res, err
}

// check interfaces
var (
_ Database = (*databaseContract)(nil)
Expand Down
5 changes: 5 additions & 0 deletions internal/backends/postgresql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (db *database) RenameCollection(ctx context.Context, params *backends.Renam
panic("not implemented")
}

// Stats implements backends.Database interface.
func (db *database) Stats(ctx context.Context, params *backends.StatsParams) (*backends.StatsResult, error) {
panic("not implemented")
}

// check interfaces
var (
_ backends.Database = (*database)(nil)
Expand Down
5 changes: 5 additions & 0 deletions internal/backends/sqlite/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (db *database) RenameCollection(ctx context.Context, params *backends.Renam
panic("not implemented")
}

// Stats implements backends.Database interface.
func (db *database) Stats(ctx context.Context, params *backends.StatsParams) (*backends.StatsResult, error) {
panic("not implemented")
}

// check interfaces
var (
_ backends.Database = (*database)(nil)
Expand Down