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

Commit

Permalink
Added support for sqlite in db backend reporting in /web/status.
Browse files Browse the repository at this point in the history
  • Loading branch information
maurosr committed Jun 26, 2017
1 parent 488d834 commit 93a5cf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
3 changes: 1 addition & 2 deletions go/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,7 @@ var generateSQLPatches = []string{
`,
`
ALTER TABLE node_health
ADD COLUMN mysql_backend_hostname varchar(128) CHARACTER SET ascii,
ADD COLUMN mysql_backend_port smallint UNSIGNED
ADD COLUMN db_backend varchar(255) CHARACTER SET ascii NOT NULL DEFAULT ""
`,
}

Expand Down
45 changes: 24 additions & 21 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 @@ -28,13 +29,12 @@ import (
const registrationPollSeconds = 10

type NodeHealth struct {
Hostname string
Token string
AppVersion string
FirstSeenActive string
LastSeenActive string
MySQLBackendHostname string
MySQLBackendPort int
Hostname string
Token string
AppVersion string
FirstSeenActive string
LastSeenActive string
DBBackend string
}

type HealthStatus struct {
Expand Down Expand Up @@ -93,17 +93,22 @@ func RegisterNode(extraInfo string, command string, firstTime bool) (healthy boo
}
}
{
db_backend := ""
if config.Config.IsSQLite() {
db_backend = config.Config.SQLite3DataFile
} else {
db_backend = config.Config.MySQLOrchestratorHost + ":" +
fmt.Sprintf("%d", 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,
mysql_backend_hostname, mysql_backend_port)
(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,
config.Config.MySQLOrchestratorHost,
config.Config.MySQLOrchestratorPort,
db_backend,
)
if err != nil {
return false, log.Errore(err)
Expand Down Expand Up @@ -208,8 +213,7 @@ func ReadAvailableNodes(onlyHttpNodes bool) (nodes [](*NodeHealth), err error) {
}
query := `
select
hostname, token, app_version, first_seen_active, last_seen_active, mysql_backend_hostname,
mysql_backend_port
hostname, token, app_version, first_seen_active, last_seen_active, db_backend
from
node_health
where
Expand All @@ -221,13 +225,12 @@ func ReadAvailableNodes(onlyHttpNodes bool) (nodes [](*NodeHealth), err error) {

err = db.QueryOrchestrator(query, sqlutils.Args(registrationPollSeconds*2, extraInfo), func(m sqlutils.RowMap) error {
nodeHealth := &NodeHealth{
Hostname: m.GetString("hostname"),
Token: m.GetString("token"),
AppVersion: m.GetString("app_version"),
FirstSeenActive: m.GetString("first_seen_active"),
LastSeenActive: m.GetString("last_seen_active"),
MySQLBackendHostname: m.GetString("mysql_backend_hostname"),
MySQLBackendPort: m.GetInt("mysql_backend_port"),
Hostname: m.GetString("hostname"),
Token: m.GetString("token"),
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
4 changes: 2 additions & 2 deletions resources/public/js/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $(document).ready(function () {
'<tr><td></td>' +
'<td><b>Hostname</b></td>' +
'<td><b>Running Since</b></td>' +
'<td><b>MySQL Backend</b></td>' +
'<td><b>DB Backend</b></td>' +
'<td><b>App Version</b></td></tr>'
);
health.Details.AvailableNodes.forEach(function(node) {
Expand All @@ -52,7 +52,7 @@ $(document).ready(function () {
message += '</code>';

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

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

0 comments on commit 93a5cf4

Please sign in to comment.