提交 0771e5a3 编写于 作者: S Shlomi Noach 提交者: GitHub

Merge pull request #102 from sjmudd/DiscoveryIgnoreReplicaHostnameFilters

Add new option: DiscoveryIgnoreReplicaHostnameFilters
......@@ -201,6 +201,7 @@ type Configuration struct {
GraphitePollSeconds int // Graphite writes interval. 0 disables.
URLPrefix string // URL prefix to run orchestrator on non-root web path, e.g. /orchestrator to put it behind nginx.
MaxOutdatedKeysToShow int // Maximum number of keys to show in ContinousDiscovery. If the number of polled hosts grows too far then showing the complete list is not ideal.
DiscoveryIgnoreReplicaHostnameFilters []string // Regexp filters to apply to prevent auto-discovering new replicas. Usage: unreachable servers due to firewalls, applications which trigger binlog dumps
}
// ToJSONString will marshal this configuration as JSON
......@@ -364,6 +365,7 @@ func newConfiguration() *Configuration {
GraphitePollSeconds: 60,
URLPrefix: "",
MaxOutdatedKeysToShow: 64,
DiscoveryIgnoreReplicaHostnameFilters: []string{},
}
}
......
......@@ -466,6 +466,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
// otherwise report the error to the caller
return fmt.Errorf("ReadTopologyInstance(%+v) 'show slave hosts' returned row with <host,port>: <%v,%v>", instanceKey, host, port)
}
// Note: NewInstanceKeyFromStrings calls ResolveHostname() implicitly
replicaKey, err := NewInstanceKeyFromStrings(host, port)
if err == nil && replicaKey.IsValid() {
......@@ -480,7 +481,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
}
if !foundByShowSlaveHosts && !isMaxScale {
// Either not configured to read SHOW SLAVE HOSTS or nothing was there.
// Discover by processlist
// Discover by information_schema.processlist
latency.Start("instance")
err := sqlutils.QueryRowsMap(db, `
select
......@@ -488,8 +489,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
from
information_schema.processlist
where
command='Binlog Dump'
or command='Binlog Dump GTID'
command IN ('Binlog Dump', 'Binlog Dump GTID')
`,
func(m sqlutils.RowMap) error {
cname, resolveErr := ResolveHostname(m.GetString("slave_hostname"))
......@@ -1121,10 +1121,8 @@ func ReadProblemInstances(clusterName string) ([](*Instance), error) {
if instance.IsDowntimed {
skip = true
}
for _, filter := range config.Config.ProblemIgnoreHostnameFilters {
if matched, _ := regexp.MatchString(filter, instance.Key.Hostname); matched {
skip = true
}
if RegexpMatchPatterns(instance.Key.Hostname, config.Config.ProblemIgnoreHostnameFilters) {
skip = true
}
if !skip {
reportedInstances = append(reportedInstances, instance)
......@@ -1257,22 +1255,16 @@ func ReadClusterCandidateInstances(clusterName string) ([](*Instance), error) {
func filterOSCInstances(instances [](*Instance)) [](*Instance) {
result := [](*Instance){}
for _, instance := range instances {
skipThisHost := false
for _, filter := range config.Config.OSCIgnoreHostnameFilters {
if matched, _ := regexp.MatchString(filter, instance.Key.Hostname); matched {
skipThisHost = true
}
if RegexpMatchPatterns(instance.Key.Hostname, config.Config.OSCIgnoreHostnameFilters) {
continue
}
if instance.IsBinlogServer() {
skipThisHost = true
continue
}
if !instance.IsLastCheckValid {
skipThisHost = true
}
if !skipThisHost {
result = append(result, instance)
continue
}
result = append(result, instance)
}
return result
}
......
......@@ -158,3 +158,13 @@ func IsSmallerBinlogFormat(binlogFormat string, otherBinlogFormat string) bool {
}
return false
}
// RegexpMatchPatterns returns true if s matches any of the provided regexpPatterns
func RegexpMatchPatterns(s string, regexpPatterns []string) bool {
for _, filter := range regexpPatterns {
if matched, err := regexp.MatchString(filter, s); err == nil && matched {
return true
}
}
return false
}
package inst
import (
"testing"
)
type testPatterns struct {
s string
patterns []string
expected bool
}
func TestRegexpMatchPatterns(t *testing.T) {
patterns := []testPatterns{
{"hostname", []string{}, false},
{"hostname", []string{"blah"}, false},
{"hostname", []string{"blah", "blah"}, false},
{"hostname", []string{"host", "blah"}, true},
{"hostname", []string{"blah", "host"}, true},
{"hostname", []string{"ho.tname"}, true},
{"hostname", []string{"ho.tname2"}, false},
{"hostname", []string{"ho.*me"}, true},
}
for _, p := range patterns {
if match := RegexpMatchPatterns(p.s, p.patterns); match != p.expected {
t.Errorf("RegexpMatchPatterns failed with: %q, %+v, got: %+v, expected: %+v", p.s, p.patterns, match, p.expected)
}
}
}
......@@ -224,7 +224,13 @@ func discoverInstance(instanceKey inst.InstanceKey) {
// Investigate replicas:
for _, replicaKey := range instance.SlaveHosts.GetInstanceKeys() {
replicaKey := replicaKey
replicaKey := replicaKey // not needed? no concurrency here?
// Avoid noticing some hosts we would otherwise discover
if inst.RegexpMatchPatterns(replicaKey.Hostname, config.Config.DiscoveryIgnoreReplicaHostnameFilters) {
continue
}
if replicaKey.IsValid() {
discoveryQueue.Push(replicaKey)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册