Add server settings view (#768)
This commit is contained in:
@@ -486,6 +486,12 @@ func GetConnectionInfo(c *gin.Context) {
|
||||
successResponse(c, info)
|
||||
}
|
||||
|
||||
// GetServerSettings renders a list of all server settings
|
||||
func GetServerSettings(c *gin.Context) {
|
||||
res, err := DB(c).ServerSettings()
|
||||
serveResult(c, res, err)
|
||||
}
|
||||
|
||||
// GetActivity renders a list of running queries
|
||||
func GetActivity(c *gin.Context) {
|
||||
res, err := DB(c).Activity()
|
||||
|
||||
@@ -35,6 +35,7 @@ func SetupRoutes(router *gin.Engine) {
|
||||
api.POST("/switchdb", SwitchDb)
|
||||
api.GET("/databases", GetDatabases)
|
||||
api.GET("/connection", GetConnectionInfo)
|
||||
api.GET("/server_settings", GetServerSettings)
|
||||
api.GET("/activity", GetActivity)
|
||||
api.GET("/schemas", GetSchemas)
|
||||
api.GET("/objects", GetObjects)
|
||||
|
||||
@@ -386,6 +386,10 @@ func (client *Client) TablesStats() (*Result, error) {
|
||||
return client.query(statements.TablesStats)
|
||||
}
|
||||
|
||||
func (client *Client) ServerSettings() (*Result, error) {
|
||||
return client.query(statements.Settings)
|
||||
}
|
||||
|
||||
// Returns all active queriers on the server
|
||||
func (client *Client) Activity() (*Result, error) {
|
||||
if client.serverType == cockroachType {
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sosedoff/pgweb/pkg/command"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sosedoff/pgweb/pkg/command"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -717,6 +717,32 @@ func testConnContext(t *testing.T) {
|
||||
assert.Equal(t, "default", result.Mode)
|
||||
}
|
||||
|
||||
func testServerSettings(t *testing.T) {
|
||||
expectedColumns := []string{
|
||||
"name",
|
||||
"setting",
|
||||
"unit",
|
||||
"category",
|
||||
"short_desc",
|
||||
"extra_desc",
|
||||
"context",
|
||||
"vartype",
|
||||
"source",
|
||||
"min_val",
|
||||
"max_val",
|
||||
"enumvals",
|
||||
"boot_val",
|
||||
"reset_val",
|
||||
"sourcefile",
|
||||
"sourceline",
|
||||
"pending_restart",
|
||||
}
|
||||
|
||||
result, err := testClient.ServerSettings()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedColumns, result.Columns)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
if onWindows() {
|
||||
t.Log("Unit testing on Windows platform is not supported.")
|
||||
@@ -756,6 +782,7 @@ func TestAll(t *testing.T) {
|
||||
testDumpExport(t)
|
||||
testTablesStats(t)
|
||||
testConnContext(t)
|
||||
testServerSettings(t)
|
||||
|
||||
teardownClient()
|
||||
teardown(t, true)
|
||||
|
||||
@@ -47,6 +47,9 @@ var (
|
||||
//go:embed sql/function.sql
|
||||
Function string
|
||||
|
||||
//go:embed sql/settings.sql
|
||||
Settings string
|
||||
|
||||
// Activity queries for specific PG versions
|
||||
Activity = map[string]string{
|
||||
"default": "SELECT * FROM pg_stat_activity WHERE datname = current_database()",
|
||||
|
||||
1
pkg/statements/sql/settings.sql
Normal file
1
pkg/statements/sql/settings.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT * FROM pg_settings
|
||||
Reference in New Issue
Block a user