Skip to content

Commit

Permalink
Add server settings view (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosedoff authored Dec 15, 2024
1 parent e6df3d1 commit f5f78eb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 29 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -756,6 +782,7 @@ func TestAll(t *testing.T) {
testDumpExport(t)
testTablesStats(t)
testConnContext(t)
testServerSettings(t)

teardownClient()
teardown(t, true)
Expand Down
3 changes: 3 additions & 0 deletions pkg/statements/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()",
Expand Down
1 change: 1 addition & 0 deletions pkg/statements/sql/settings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM pg_settings
2 changes: 2 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ <h3 class="text-center">SSH Connection</h3>
<li><a href="#" data-action="show_db_stats">Show Database Stats</a></li>
<li><a href="#" data-action="download_db_stats">Download Database Stats</a></li>
<li class="divider"></li>
<li><a href="#" data-action="server_settings">Show Server Settings</a></li>
<li class="divider"></li>
<li><a href="#" data-action="export">Export SQL dump</a></li>
</ul>
</div>
Expand Down
15 changes: 15 additions & 0 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function apiCall(method, path, params, cb) {

function getInfo(cb) { apiCall("get", "/info", {}, cb); }
function getConnection(cb) { apiCall("get", "/connection", {}, cb); }
function getServerSettings(cb) { apiCall("get", "/server_settings", {}, cb); }
function getSchemas(cb) { apiCall("get", "/schemas", {}, cb); }
function getObjects(cb) { apiCall("get", "/objects", {}, cb); }
function getTables(cb) { apiCall("get", "/tables", {}, cb); }
Expand Down Expand Up @@ -678,6 +679,17 @@ function downloadDatabaseStats() {
openInNewWindow("api/tables_stats", { format: "csv", export: "true" });
}

function showServerSettings() {
getServerSettings(function(data) {
buildTable(data);

setCurrentTab("table_content");
$("#input").hide();
$("#body").prop("class", "full");
$("#results").addClass("no-crop");
});
}

function showTableStructure() {
var name = getCurrentObject().name;

Expand Down Expand Up @@ -1280,6 +1292,9 @@ function bindCurrentDatabaseMenu() {
case "download_db_stats":
downloadDatabaseStats();
break;
case "server_settings":
showServerSettings();
break;
case "export":
openInNewWindow("api/export");
break;
Expand Down

0 comments on commit f5f78eb

Please sign in to comment.