Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for DiscoveryIgnoreMasterHostnameFilters #1018

Merged
merged 8 commits into from
Nov 20, 2019
2 changes: 2 additions & 0 deletions go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions go/inst/analysis_test.go
Original file line number Diff line number Diff line change
@@ -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")
// }
}
10 changes: 10 additions & 0 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
9 changes: 8 additions & 1 deletion go/logic/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
}
}

Expand Down