Skip to content

Commit e1f38a3

Browse files
Merge pull request #21 from kamil-holubicki/DISTMYSQL-228
DISTMYSQL-228: Orchestrator GUI messages should optionally contain the name of the orchestratorapp generating the message
2 parents eb84360 + bc7a6b8 commit e1f38a3

File tree

21 files changed

+588
-2
lines changed

21 files changed

+588
-2
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/openark/orchestrator
33
go 1.16
44

55
require (
6+
github.com/Showmax/go-fqdn v1.0.0 // indirect
67
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6
78
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
89
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432
@@ -47,7 +48,7 @@ require (
4748

4849
replace (
4950
github.com/hashicorp/raft => github.com/openark/raft v0.0.0-20170918052300-fba9f909f7fe
51+
github.com/openark/golib => ./go/golib
5052
golang.org/x/text v0.3.0 => golang.org/x/text v0.3.8
5153
golang.org/x/text v0.3.7 => golang.org/x/text v0.3.8
52-
github.com/openark/golib => ./go/golib
5354
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
2+
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
13
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
24
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 h1:G1bPvciwNyF7IUmKXNt9Ak3m6u9DE1rF+RmtIkBpVdA=
35
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=

go/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ type Configuration struct {
278278
EnforceExactSemiSyncReplicas bool // If true, semi-sync replicas will be enabled/disabled to match the wait count in the desired priority order; this applies to LockedSemiSyncMaster and MasterWithTooManySemiSyncReplicas
279279
RecoverLockedSemiSyncMaster bool // If true, orchestrator will recover from a LockedSemiSync state by enabling semi-sync on replicas to match the wait count; this behavior can be overridden by EnforceExactSemiSyncReplicas
280280
ReasonableLockedSemiSyncMasterSeconds uint // Time to evaluate the LockedSemiSyncHypothesis before triggering the LockedSemiSync analysis; falls back to ReasonableReplicationLagSeconds if not set
281+
PrependMessagesWithOrcIdentity string // use FQDN/hostname/custom to prefix error message returned to the client. Empty string (default)/none skips prefixing.
282+
CustomOrcIdentity string // use if PrependMessagesWithOrcIdentity is 'custom'
281283
}
282284

283285
// ToJSONString will marshal this configuration as JSON
@@ -452,6 +454,8 @@ func newConfiguration() *Configuration {
452454
EnforceExactSemiSyncReplicas: false,
453455
RecoverLockedSemiSyncMaster: false,
454456
ReasonableLockedSemiSyncMasterSeconds: 0,
457+
PrependMessagesWithOrcIdentity: "",
458+
CustomOrcIdentity: "",
455459
}
456460
}
457461

go/http/api.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"net"
2323
"net/http"
24+
"os"
2425
"strconv"
2526
"strings"
2627
"time"
@@ -32,6 +33,7 @@ import (
3233
"github.com/openark/golib/log"
3334
"github.com/openark/golib/util"
3435

36+
fqdn "github.com/Showmax/go-fqdn"
3537
"github.com/openark/orchestrator/go/agent"
3638
"github.com/openark/orchestrator/go/collection"
3739
"github.com/openark/orchestrator/go/config"
@@ -114,10 +116,52 @@ type APIResponse struct {
114116
Details interface{}
115117
}
116118

119+
var messagePrefix string
120+
117121
func Respond(r render.Render, apiResponse *APIResponse) {
122+
apiResponse.Message = fmt.Sprintf("%+v%+v", messagePrefix, apiResponse.Message)
118123
r.JSON(apiResponse.Code.HttpStatus(), apiResponse)
119124
}
120125

126+
func setupMessagePrefix() {
127+
act := config.Config.PrependMessagesWithOrcIdentity
128+
if act == "" || act == "none" {
129+
return
130+
}
131+
if act != "FQDN" && act != "hostname" && act != "custom" {
132+
log.Warning("PrependMessagesWithOrcIdentity option has unsupported value '%+v'")
133+
return
134+
}
135+
136+
var hostname string
137+
var err error
138+
fallbackActive := false
139+
140+
if act == "FQDN" {
141+
if hostname, err = fqdn.FqdnHostname(); err != nil {
142+
log.Warning("Failed to get Orchestrator's FQDN. Falling back to hostname.")
143+
hostname = ""
144+
fallbackActive = true
145+
}
146+
}
147+
if fallbackActive || act == "hostname" {
148+
fallbackActive = false
149+
if hostname, err = os.Hostname(); err != nil {
150+
log.Warning("Failed to get Orchestrator's FQDN. Falling back to custom prefix (if provided).")
151+
hostname = ""
152+
fallbackActive = true
153+
}
154+
}
155+
if (fallbackActive || act == "custom") && config.Config.CustomOrcIdentity != "" {
156+
hostname = config.Config.CustomOrcIdentity
157+
}
158+
if hostname != "" {
159+
messagePrefix = fmt.Sprintf("Orchestrator %+v says: ", hostname)
160+
} else {
161+
log.Warning("Prepending messages with Orchestrator identity was requested, but identity cannot be determined. Skipping prefix.")
162+
}
163+
}
164+
121165
type HttpAPI struct {
122166
URLPrefix string
123167
}
@@ -3963,4 +4007,6 @@ func (this *HttpAPI) RegisterRequests(m *martini.ClassicMartini) {
39634007
} else {
39644008
m.Get(config.Config.StatusEndpoint, this.StatusCheck)
39654009
}
4010+
4011+
setupMessagePrefix()
39664012
}

vendor/github.com/Showmax/go-fqdn/.golangci.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Showmax/go-fqdn/LICENSE

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Showmax/go-fqdn/README.md

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Showmax/go-fqdn/errors.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)