Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Added MySQL backend to /web/status. #216

Merged
merged 3 commits into from
Jun 26, 2017
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
4 changes: 4 additions & 0 deletions go/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,10 @@ var generateSQLPatches = []string{
`
CREATE UNIQUE INDEX host_port_active_recoverable_uidx_topology_failure_detection ON topology_failure_detection (hostname, port, in_active_period, end_active_period_unixtime, is_actionable)
`,
`
ALTER TABLE node_health
ADD COLUMN db_backend varchar(255) CHARACTER SET ascii NOT NULL DEFAULT ""
`,
}

// Track if a TLS has already been configured for topology
Expand Down
17 changes: 14 additions & 3 deletions go/process/health_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package process
import (
"time"

"fmt"
"github.com/github/orchestrator/go/config"
"github.com/github/orchestrator/go/db"
"github.com/openark/golib/log"
Expand All @@ -33,6 +34,7 @@ type NodeHealth struct {
AppVersion string
FirstSeenActive string
LastSeenActive string
DBBackend string
}

type HealthStatus struct {
Expand Down Expand Up @@ -91,14 +93,22 @@ func RegisterNode(extraInfo string, command string, firstTime bool) (healthy boo
}
}
{
dbBackend := ""
if config.Config.IsSQLite() {
dbBackend = config.Config.SQLite3DataFile
} else {
dbBackend = fmt.Sprintf("%s:%d", config.Config.MySQLOrchestratorHost,
config.Config.MySQLOrchestratorPort)
}
sqlResult, err := db.ExecOrchestrator(`
insert ignore into node_health
(hostname, token, first_seen_active, last_seen_active, extra_info, command, app_version)
(hostname, token, first_seen_active, last_seen_active, extra_info, command, app_version, db_backend)
values
(?, ?, now(), now(), ?, ?, ?)
(?, ?, now(), now(), ?, ?, ?, ?)
`,
ThisHostname, ProcessToken.Hash, extraInfo, command,
config.RuntimeCLIFlags.ConfiguredVersion,
dbBackend,
)
if err != nil {
return false, log.Errore(err)
Expand Down Expand Up @@ -203,7 +213,7 @@ func ReadAvailableNodes(onlyHttpNodes bool) (nodes [](*NodeHealth), err error) {
}
query := `
select
hostname, token, app_version, first_seen_active, last_seen_active
hostname, token, app_version, first_seen_active, last_seen_active, db_backend
from
node_health
where
Expand All @@ -220,6 +230,7 @@ func ReadAvailableNodes(onlyHttpNodes bool) (nodes [](*NodeHealth), err error) {
AppVersion: m.GetString("app_version"),
FirstSeenActive: m.GetString("first_seen_active"),
LastSeenActive: m.GetString("last_seen_active"),
DBBackend: m.GetString("db_backend"),
}
nodes = append(nodes, nodeHealth)
return nil
Expand Down
13 changes: 8 additions & 5 deletions resources/public/js/status.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

function addStatusTableData(name, column1, column2, column3) {
function addStatusTableData(name, column1, column2, column3, column4) {
$("#orchestratorStatusTable").append(
'<tr><td>' + name + '</td>' +
'<td>' + column1 + '</td>' +
'<td><code class="text-info">' + column2 + '</code></td>' +
'<td><code class="text-info">' + column3 + '</code></td></tr>'
'<td><code class="text-info">' + column2 + '</code></td>' +
'<td><code class="text-info">' + column3 + '</code></td>' +
'<td><code class="text-info">' + column4 + '</code></td></tr>'
);
}
function addStatusActionButton(name, uri) {
Expand All @@ -27,6 +28,7 @@ $(document).ready(function () {
'<tr><td></td>' +
'<td><b>Hostname</b></td>' +
'<td><b>Running Since</b></td>' +
'<td><b>DB Backend</b></td>' +
'<td><b>App Version</b></td></tr>'
);
health.Details.AvailableNodes.forEach(function(node) {
Expand All @@ -50,16 +52,17 @@ $(document).ready(function () {
message += '</code>';

var running_since ='<span class="text-info">'+node.FirstSeenActive+'</span>';
var address = node.DBBackend;

addStatusTableData("Available node", message, running_since, app_version);
addStatusTableData("Available node", message, running_since, address, app_version);
})

var userId = getUserId();
if (userId == "") {
userId = "[unknown]"
}
var userStatus = (isAuthorizedForAction() ? "admin" : "read only");
addStatusTableData("You", userId + ", " + userStatus, "", "");
addStatusTableData("You", userId + ", " + userStatus, "", "", "");

if (isAuthorizedForAction()) {
addStatusActionButton("Reload configuration", "reload-configuration");
Expand Down