Skip to content

Commit

Permalink
Remove namespace auto-discover feature
Browse files Browse the repository at this point in the history
This feature is not used and is causing problems when the list of namespace to display is empty
  • Loading branch information
geobeau committed Jun 22, 2022
1 parent 3899067 commit 2fa6d05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
7 changes: 2 additions & 5 deletions pkg/aerospike/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (conf *AerospikeProbeConfig) generateAerospikeEndpointFromEntry(logger log.
}

namespaces := make(map[string]struct{})
autoDiscoverNamespaces := true

if conf.AerospikeEndpointConfig.NamespaceMetaKey != "" {
nsString, ok := entry.Meta[conf.AerospikeEndpointConfig.NamespaceMetaKey]
Expand All @@ -57,14 +56,12 @@ func (conf *AerospikeProbeConfig) generateAerospikeEndpointFromEntry(logger log.
for _, ns := range nsFromDiscovery {
namespaces[ns] = struct{}{}
}
autoDiscoverNamespaces = false
}
}

return &AerospikeEndpoint{Name: entry.Address,
ClusterName: clusterName,
Namespaces: namespaces,
AutoDiscoverNamespaces: autoDiscoverNamespaces,
ClusterName: clusterName,
Namespaces: namespaces,
Config: AerospikeClientConfig{
// auth
authEnabled: authEnabled,
Expand Down
55 changes: 14 additions & 41 deletions pkg/aerospike/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,27 @@ var clusterStats = promauto.NewGaugeVec(prometheus.GaugeOpts{
}, []string{"cluster", "probe_endpoint", "name"})

type AerospikeEndpoint struct {
Name string
ClusterLevel bool
ClusterName string
Client *as.Client
Config AerospikeClientConfig
Logger log.Logger
AutoDiscoverNamespaces bool
Namespaces map[string]struct{}
Name string
ClusterLevel bool
ClusterName string
Client *as.Client
Config AerospikeClientConfig
Logger log.Logger
Namespaces map[string]struct{}
}

func (e *AerospikeEndpoint) GetHash() string {
hash := fmt.Sprintf("%s/%s", e.ClusterName, e.Name)
// If Namespaces are pushed through service discovery
// the hash should change according to the Namespaces
if !e.AutoDiscoverNamespaces {
// Make sure the list is always in the same order
namespaces := make([]string, 0, len(e.Namespaces))
for str := range e.Namespaces {
namespaces = append(namespaces, str)
}
sort.Strings(namespaces)
return fmt.Sprintf("%s/ns:%s", hash, namespaces)

// Make sure the list is always in the same order
namespaces := make([]string, 0, len(e.Namespaces))
for str := range e.Namespaces {
namespaces = append(namespaces, str)
}
return hash
sort.Strings(namespaces)
return fmt.Sprintf("%s/ns:%s", hash, namespaces)
}

func (e *AerospikeEndpoint) GetName() string {
Expand Down Expand Up @@ -129,30 +126,6 @@ func (e *AerospikeEndpoint) Connect() error {

func (e *AerospikeEndpoint) Refresh() error {
e.refreshMetrics()
if !e.AutoDiscoverNamespaces {
return nil
}
nodes := e.Client.GetNodes()

infop := as.NewInfoPolicy()

e.Namespaces = make(map[string]struct{})
for _, n := range nodes {

data, err := n.RequestInfo(infop, fmt.Sprintln("sets"))
if err != nil {
return err
}
for _, val := range data {
matches := setExtractionRegex.FindAllStringSubmatch(val, -1)
for _, match := range matches {
if len(match) > 1 {
e.Namespaces[match[1]] = struct{}{}
}
}
}
}
level.Debug(e.Logger).Log("msg", fmt.Sprintf("Refresh finished: current Namespaces: %s", e.Namespaces))
return nil
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/aerospike/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ func TestHashWorks(t *testing.T) {
"00": {},
}

e := AerospikeEndpoint{Name: name, ClusterName: "foo", AutoDiscoverNamespaces: true}
if e.GetHash() != "foo/foobar" {
t.Errorf("Hash failed: expected: %s, got: %s", name, e.GetHash())
}
e = AerospikeEndpoint{Name: name, ClusterName: "foo", AutoDiscoverNamespaces: false}
e := AerospikeEndpoint{Name: name, ClusterName: "foo"}
if e.GetHash() != "foo/foobar/ns:[]" {
t.Errorf("Hash failed: expected: %s, got: %s", "foobar/ns:[]", e.GetHash())
}
e = AerospikeEndpoint{Name: name, ClusterName: "foo", AutoDiscoverNamespaces: false, Namespaces: ns}
e = AerospikeEndpoint{Name: name, ClusterName: "foo", Namespaces: ns}
if e.GetHash() != "foo/foobar/ns:[00 bar fo ob]" {
t.Errorf("Hash failed: expected: %s, got: %s (order is important)", "foobar/ns:[00 bar fo ob]", e.GetHash())
}
Expand Down

0 comments on commit 2fa6d05

Please sign in to comment.