diff --git a/go/config/config.go b/go/config/config.go index 3c1ad4c80..170375e2a 100644 --- a/go/config/config.go +++ b/go/config/config.go @@ -255,6 +255,8 @@ 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. DiscoveryIgnoreReplicaHostnameFilters []string // Regexp filters to apply to prevent auto-discovering new replicas. Usage: unreachable servers due to firewalls, applications which trigger binlog dumps + DiscoveryIgnoreMasterHostnameFilters []string // Regexp filters to apply to prevent auto-discovering a master. Usage: pointing your master temporarily to replicate seom data from external host + DiscoveryIgnoreHostnameFilters []string // Regexp filters to apply to prevent discovering instances of any kind ConsulAddress string // Address where Consul HTTP api is found. Example: 127.0.0.1:8500 ConsulAclToken string // ACL token used to write to Consul KV ConsulCrossDataCenterDistribution bool // should orchestrator automatically auto-deduce all consul DCs and write KVs in all DCs diff --git a/go/inst/analysis_test.go b/go/inst/analysis_test.go new file mode 100644 index 000000000..9ad5d7dbf --- /dev/null +++ b/go/inst/analysis_test.go @@ -0,0 +1,49 @@ +/* + Copyright 2014 Outbrain Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package inst + +import ( + "github.com/github/orchestrator/go/config" + "github.com/openark/golib/log" + // test "github.com/openark/golib/tests" + "testing" +) + +func init() { + config.Config.HostnameResolveMethod = "none" + config.MarkConfigurationLoaded() + log.SetLevel(log.ERROR) +} + +func TestGetAnalysisInstanceType(t *testing.T) { + // { + // analysis := &ReplicationAnalysis{} + // test.S(t).ExpectEquals(string(analysis.GetAnalysisInstanceType()), "intermediate-master") + // } + // { + // analysis := &ReplicationAnalysis{IsMaster: true} + // test.S(t).ExpectEquals(string(analysis.GetAnalysisInstanceType()), "master") + // } + // { + // analysis := &ReplicationAnalysis{IsCoMaster: true} + // test.S(t).ExpectEquals(string(analysis.GetAnalysisInstanceType()), "co-master") + // } + // { + // analysis := &ReplicationAnalysis{IsMaster: true, IsCoMaster: true} + // test.S(t).ExpectEquals(string(analysis.GetAnalysisInstanceType()), "co-master") + // } +} diff --git a/go/inst/instance_dao.go b/go/inst/instance_dao.go index afc35451f..c65a1a793 100644 --- a/go/inst/instance_dao.go +++ b/go/inst/instance_dao.go @@ -1827,6 +1827,16 @@ func InjectUnseenMasters() error { operations := 0 for _, masterKey := range unseenMasterKeys { masterKey := masterKey + + if RegexpMatchPatterns(masterKey.StringCode(), config.Config.DiscoveryIgnoreMasterHostnameFilters) { + log.Debugf("InjectUnseenMasters: skipping discovery of %+v because it matches DiscoveryIgnoreMasterHostnameFilters", masterKey) + continue + } + if RegexpMatchPatterns(masterKey.StringCode(), config.Config.DiscoveryIgnoreHostnameFilters) { + log.Debugf("InjectUnseenMasters: skipping discovery of %+v because it matches DiscoveryIgnoreHostnameFilters", masterKey) + continue + } + clusterName := masterKey.StringCode() // minimal details: instance := Instance{Key: masterKey, Version: "Unknown", ClusterName: clusterName} diff --git a/go/logic/orchestrator.go b/go/logic/orchestrator.go index 54578df72..5a01f9698 100644 --- a/go/logic/orchestrator.go +++ b/go/logic/orchestrator.go @@ -190,6 +190,11 @@ func DiscoverInstance(instanceKey inst.InstanceKey) { log.Debugf("discoverInstance: skipping discovery of %+v because it is set to be forgotten", instanceKey) return } + if inst.RegexpMatchPatterns(instanceKey.StringCode(), config.Config.DiscoveryIgnoreHostnameFilters) { + log.Debugf("discoverInstance: skipping discovery of %+v because it matches DiscoveryIgnoreHostnameFilters", instanceKey) + return + } + // create stopwatch entries latency := stopwatch.NewNamedStopwatch() latency.AddMany([]string{ @@ -289,7 +294,9 @@ func DiscoverInstance(instanceKey inst.InstanceKey) { } // Investigate master: if instance.MasterKey.IsValid() { - discoveryQueue.Push(instance.MasterKey) + if !inst.RegexpMatchPatterns(instance.MasterKey.StringCode(), config.Config.DiscoveryIgnoreMasterHostnameFilters) { + discoveryQueue.Push(instance.MasterKey) + } } }