From 845a36192ff10afb54d69cf1bf58a7d6551a383e Mon Sep 17 00:00:00 2001 From: David AMSALLEM Date: Fri, 23 Feb 2024 14:38:04 +0100 Subject: [PATCH] Clean old discovery metadata aerospike-namespaces' * This metadata is no more added to consul --- configs/aerospike_config.yaml | 5 -- pkg/aerospike/config.go | 1 - pkg/aerospike/discovery.go | 25 ++-------- pkg/aerospike/discovery_test.go | 81 +++++++++------------------------ probes/aerospike/README.md | 11 ----- 5 files changed, 24 insertions(+), 99 deletions(-) diff --git a/configs/aerospike_config.yaml b/configs/aerospike_config.yaml index f2326d5..189aa80 100644 --- a/configs/aerospike_config.yaml +++ b/configs/aerospike_config.yaml @@ -26,12 +26,7 @@ client_config: # Skip ssl verification tls_skip_verify: false ### Probe discovery configuration ### - # The key to discover Aerospike's namespaces through service discovery - # Set it to "" to instead discover namespaces automatically via the info command - # DEPRECATED since 02/19/2024 - namespace_meta_key: "aerospike-namespaces" # The key prefix to discover Aerospike's namespaces through service discovery - # old "namespace_meta_key" has been DEPRECATED because of 512 bytes limitation of the value in consul. namespace_meta_key_prefix: "aerospike-monitoring-" ### Probe configuration ### monitoring_set: monitoring diff --git a/pkg/aerospike/config.go b/pkg/aerospike/config.go index e54b8f4..3e093f0 100644 --- a/pkg/aerospike/config.go +++ b/pkg/aerospike/config.go @@ -63,7 +63,6 @@ var ( PasswordEnv: "AEROSPIKE_PASSWORD", TLSTag: "tls", TLSHostnameMetaKey: "tls-hostname", - NamespaceMetaKey: "", NamespaceMetaKeyPrefix: "aerospike-monitoring-", MonitoringSet: "monitoring", LatencyKeyPrefix: "monitoring_latency_", diff --git a/pkg/aerospike/discovery.go b/pkg/aerospike/discovery.go index 8ba82c4..effa3b7 100644 --- a/pkg/aerospike/discovery.go +++ b/pkg/aerospike/discovery.go @@ -78,45 +78,26 @@ func (conf *AerospikeProbeConfig) generateNamespacedEndpointsFromEntry(logger lo func (conf AerospikeProbeConfig) getNamespacesFromEntry(logger log.Logger, entry discovery.ServiceEntry) map[string]struct{} { namespaces := make(map[string]struct{}) - fallback := false - // Correct way to get namespaces. for metaKey, metaValue := range entry.Meta { if !strings.HasPrefix(metaKey, conf.AerospikeEndpointConfig.NamespaceMetaKeyPrefix) { continue } ready, err := strconv.ParseBool(metaValue) - // if the value of the NamespaceMetaKeyPrefix MetaData is not a boolean then fallback to the old method if err != nil { level.Error(logger).Log("msg", fmt.Sprintf("Fail to parse boolean value from MetaData %s. Fallbacking to deprecated method.", metaKey), "err", err) - fallback = true - break + continue } - // if ready is at false, then iterate to the next MetaData and try to resolve other namespaces if !ready { continue } - ns := metaKey[len(conf.AerospikeEndpointConfig.NamespaceMetaKeyPrefix):] // MetaKey is like : "aerospike-monitoring-closeststore" + // MetaKey is like : "aerospike-monitoring-foo" + ns := metaKey[len(conf.AerospikeEndpointConfig.NamespaceMetaKeyPrefix):] if len(ns) > 0 { namespaces[ns] = struct{}{} } } - // DEPRECATED way to get namespaces in case of fallback required or empty namespaces with the new method - if fallback || len(namespaces) == 0 { - nsString, ok := entry.Meta[conf.AerospikeEndpointConfig.NamespaceMetaKey] - if ok { - // Clear namespaces for any previously found entry from the old method - for k := range namespaces { - delete(namespaces, k) - } - nsFromDiscovery := strings.Split(nsString, ";") - for _, ns := range nsFromDiscovery { - namespaces[ns] = struct{}{} - } - } - } - return namespaces } diff --git a/pkg/aerospike/discovery_test.go b/pkg/aerospike/discovery_test.go index 4c10cd4..a0b0bb8 100644 --- a/pkg/aerospike/discovery_test.go +++ b/pkg/aerospike/discovery_test.go @@ -1,79 +1,44 @@ package aerospike import ( - "errors" "reflect" "testing" - "time" "github.com/criteo/blackbox-prober/pkg/discovery" - "github.com/criteo/blackbox-prober/pkg/topology" "github.com/go-kit/log" ) -type testEndpoint struct { - topology.DummyEndpoint - deadline time.Time - CheckCallCount int - RefreshCallCount int -} - -func (te *testEndpoint) Refresh() error { - te.RefreshCallCount += 1 - if te.RefreshCallCount%2 == 0 { - return errors.New("fake err") - } - return nil -} - func TestGetNamespacesFromEntry(t *testing.T) { - entry_newValid := discovery.ServiceEntry{ + entry_Valid := discovery.ServiceEntry{ Meta: map[string]string{ "aerospike-monitoring-test1": "true", "aerospike-monitoring-test2": "true", "aerospike-monitoring-test3": "false", }, } - expected_newValid := map[string]struct{}{ - "test1": struct{}{}, - "test2": struct{}{}, - } - - entry_oldValid := discovery.ServiceEntry{ - Meta: map[string]string{ - "aerospike-namespaces": "test1;test2;test3", - }, - } - expected_oldValid := map[string]struct{}{ - "test1": struct{}{}, - "test2": struct{}{}, - "test3": struct{}{}, + expected_Valid := map[string]struct{}{ + "test1": {}, + "test2": {}, } - entry_noFallback := discovery.ServiceEntry{ + entry_OneInvalid := discovery.ServiceEntry{ Meta: map[string]string{ - "aerospike-namespaces": "test3", "aerospike-monitoring-test1": "true", - "aerospike-monitoring-test2": "false", - "aerospike-monitoring-test3": "true", + "aerospike-monitoring-test2": "foo", + "aerospike-monitoring-test3": "false", }, } - expected_noFallback := map[string]struct{}{ - "test1": struct{}{}, - "test3": struct{}{}, + expected_OneInvalid := map[string]struct{}{ + "test1": {}, } - entry_fallback := discovery.ServiceEntry{ + entry_Invalid := discovery.ServiceEntry{ Meta: map[string]string{ - "aerospike-namespaces": "test3", - "aerospike-monitoring-test1": "true", + "aerospike-monitoring-test1": "bar", "aerospike-monitoring-test2": "foo", - "aerospike-monitoring-test3": "false", }, } - expected_fallback := map[string]struct{}{ - "test3": struct{}{}, - } + expected_Invalid := map[string]struct{}{} entry_empty := discovery.ServiceEntry{ Meta: map[string]string{}, @@ -87,21 +52,17 @@ func TestGetNamespacesFromEntry(t *testing.T) { NamespaceMetaKeyPrefix: "aerospike-monitoring-", } - namespaces := config.getNamespacesFromEntry(log.NewNopLogger(), entry_newValid) - if !reflect.DeepEqual(namespaces, expected_newValid) { - t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_newValid'.") - } - namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_oldValid) - if !reflect.DeepEqual(namespaces, expected_oldValid) { - t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_oldValid'.") + namespaces := config.getNamespacesFromEntry(log.NewNopLogger(), entry_Valid) + if !reflect.DeepEqual(namespaces, expected_Valid) { + t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_Valid'.") } - namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_noFallback) - if !reflect.DeepEqual(namespaces, expected_noFallback) { - t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_noFallback'.") + namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_OneInvalid) + if !reflect.DeepEqual(namespaces, expected_OneInvalid) { + t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_OneInvalid'.") } - namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_fallback) - if !reflect.DeepEqual(namespaces, expected_fallback) { - t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_fallback'.") + namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_Invalid) + if !reflect.DeepEqual(namespaces, expected_Invalid) { + t.Errorf("getNamespacesFromEntry didn't return expected value for entry 'entry_Invalid'.") } namespaces = config.getNamespacesFromEntry(log.NewNopLogger(), entry_empty) if !reflect.DeepEqual(namespaces, expected_empty) { diff --git a/probes/aerospike/README.md b/probes/aerospike/README.md index 5ea9336..f1b9230 100644 --- a/probes/aerospike/README.md +++ b/probes/aerospike/README.md @@ -14,17 +14,6 @@ For advertising "foo" and "bar" namespace `aerospike-monitoring-foo: true` `aerospike-monitoring-bar: true` -If any of these MetaData entries are not present of does not define a bool value -then it will fallback to the old method of namespace discovery: -`namespace_meta_key` which contains namespaces separated by `;` - -Example: -`namespace_meta_key` per default is set to `aerospike-namespaces`. - -For advertising "foo" and "bar" namespace - -`aerospike-namespaces: foo;bar` - ## Latency checks executed at cluster level In the Aerospike probe, all latency checks are being run on cluster level. Normally