From: Martina Ferrari <tina@debian.org>
Date: Mon, 17 Oct 2022 20:07:52 +0000
Subject: Disable Consul service discovery

Forwarded: not-needed
Last-Updated: Mon, 17 Oct 2022 20:07:52 +0000

Disable Consul SD, as its Debian package has lots of problems.
---
 config/config_test.go              | 56 +-------------------------------------
 config/testdata/conf.good.yml      | 25 -----------------
 config/testdata/roundtrip.good.yml | 14 ----------
 discovery/consul/consul.go         |  3 ++
 discovery/consul/consul_test.go    |  3 ++
 discovery/install/install.go       |  1 -
 plugins/plugins.go                 |  3 --
 7 files changed, 7 insertions(+), 98 deletions(-)

diff --git a/config/config_test.go b/config/config_test.go
index b63ebc3..21142b1 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -33,7 +33,6 @@ import (
 	"github.com/prometheus/prometheus/discovery"
 	"github.com/prometheus/prometheus/discovery/aws"
 	"github.com/prometheus/prometheus/discovery/azure"
-	"github.com/prometheus/prometheus/discovery/consul"
 	"github.com/prometheus/prometheus/discovery/digitalocean"
 	"github.com/prometheus/prometheus/discovery/dns"
 	"github.com/prometheus/prometheus/discovery/eureka"
@@ -373,59 +372,6 @@ var expectedConf = &Config{
 				},
 			},
 		},
-		{
-			JobName: "service-y",
-
-			HonorTimestamps:       true,
-			ScrapeInterval:        model.Duration(15 * time.Second),
-			ScrapeTimeout:         DefaultGlobalConfig.ScrapeTimeout,
-			BodySizeLimit:         globBodySizeLimit,
-			SampleLimit:           globSampleLimit,
-			TargetLimit:           globTargetLimit,
-			LabelLimit:            globLabelLimit,
-			LabelNameLengthLimit:  globLabelNameLengthLimit,
-			LabelValueLengthLimit: globLabelValueLengthLimit,
-
-			MetricsPath:      DefaultScrapeConfig.MetricsPath,
-			Scheme:           DefaultScrapeConfig.Scheme,
-			HTTPClientConfig: config.DefaultHTTPClientConfig,
-
-			ServiceDiscoveryConfigs: discovery.Configs{
-				&consul.SDConfig{
-					Server:          "localhost:1234",
-					PathPrefix:      "/consul",
-					Token:           "mysecret",
-					Services:        []string{"nginx", "cache", "mysql"},
-					ServiceTags:     []string{"canary", "v1"},
-					NodeMeta:        map[string]string{"rack": "123"},
-					TagSeparator:    consul.DefaultSDConfig.TagSeparator,
-					Scheme:          "https",
-					RefreshInterval: consul.DefaultSDConfig.RefreshInterval,
-					AllowStale:      true,
-					HTTPClientConfig: config.HTTPClientConfig{
-						TLSConfig: config.TLSConfig{
-							CertFile:           filepath.FromSlash("testdata/valid_cert_file"),
-							KeyFile:            filepath.FromSlash("testdata/valid_key_file"),
-							CAFile:             filepath.FromSlash("testdata/valid_ca_file"),
-							InsecureSkipVerify: false,
-						},
-						FollowRedirects: true,
-						EnableHTTP2:     true,
-					},
-				},
-			},
-
-			RelabelConfigs: []*relabel.Config{
-				{
-					SourceLabels: model.LabelNames{"__meta_sd_consul_tags"},
-					Regex:        relabel.MustNewRegexp("label:([^=]+)=([^,]+)"),
-					Separator:    ",",
-					TargetLabel:  "${1}",
-					Replacement:  "${2}",
-					Action:       relabel.Replace,
-				},
-			},
-		},
 		{
 			JobName: "service-z",
 
@@ -1328,7 +1274,7 @@ func TestElideSecrets(t *testing.T) {
 	yamlConfig := string(config)
 
 	matches := secretRe.FindAllStringIndex(yamlConfig, -1)
-	require.Equal(t, 21, len(matches), "wrong number of secret matches found")
+	require.Equal(t, 20, len(matches), "wrong number of secret matches found")
 	require.NotContains(t, yamlConfig, "mysecret",
 		"yaml marshal reveals authentication credentials.")
 }
diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml
index 518bcca..bb9aec2 100644
--- a/config/testdata/conf.good.yml
+++ b/config/testdata/conf.good.yml
@@ -157,31 +157,6 @@ scrape_configs:
         regex: expensive_metric.*
         action: drop
 
-  - job_name: service-y
-
-    consul_sd_configs:
-      - server: "localhost:1234"
-        token: mysecret
-        path_prefix: /consul
-        services: ["nginx", "cache", "mysql"]
-        tags: ["canary", "v1"]
-        node_meta:
-          rack: "123"
-        allow_stale: true
-        scheme: https
-        tls_config:
-          ca_file: valid_ca_file
-          cert_file: valid_cert_file
-          key_file: valid_key_file
-          insecure_skip_verify: false
-
-    relabel_configs:
-      - source_labels: [__meta_sd_consul_tags]
-        separator: ","
-        regex: label:([^=]+)=([^,]+)
-        target_label: ${1}
-        replacement: ${2}
-
   - job_name: service-z
 
     tls_config:
diff --git a/config/testdata/roundtrip.good.yml b/config/testdata/roundtrip.good.yml
index 4840174..eeab987 100644
--- a/config/testdata/roundtrip.good.yml
+++ b/config/testdata/roundtrip.good.yml
@@ -37,20 +37,6 @@ scrape_configs:
         client_secret: <secret>
         port: 9100
 
-    consul_sd_configs:
-      - server: localhost:1234
-        token: <secret>
-        services: [nginx, cache, mysql]
-        tags: [canary, v1]
-        node_meta:
-          rack: "123"
-        allow_stale: true
-        scheme: https
-        tls_config:
-          ca_file: valid_ca_file
-          cert_file: valid_cert_file
-          key_file: valid_key_file
-
     digitalocean_sd_configs:
       - authorization:
           credentials: <secret>
diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go
index 99ea396..73ef14a 100644
--- a/discovery/consul/consul.go
+++ b/discovery/consul/consul.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package consul
 
 import (
diff --git a/discovery/consul/consul_test.go b/discovery/consul/consul_test.go
index c929601..ac9de95 100644
--- a/discovery/consul/consul_test.go
+++ b/discovery/consul/consul_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package consul
 
 import (
diff --git a/discovery/install/install.go b/discovery/install/install.go
index 9e0986c..6b875bb 100644
--- a/discovery/install/install.go
+++ b/discovery/install/install.go
@@ -18,7 +18,6 @@ package install
 import (
 	_ "github.com/prometheus/prometheus/discovery/aws"          // register aws
 	_ "github.com/prometheus/prometheus/discovery/azure"        // register azure
-	_ "github.com/prometheus/prometheus/discovery/consul"       // register consul
 	_ "github.com/prometheus/prometheus/discovery/digitalocean" // register digitalocean
 	_ "github.com/prometheus/prometheus/discovery/dns"          // register dns
 	_ "github.com/prometheus/prometheus/discovery/eureka"       // register eureka
diff --git a/plugins/plugins.go b/plugins/plugins.go
index 246fd30..91f3e9d 100644
--- a/plugins/plugins.go
+++ b/plugins/plugins.go
@@ -22,9 +22,6 @@ import (
 	// Register azure plugin.
 	_ "github.com/prometheus/prometheus/discovery/azure"
 
-	// Register consul plugin.
-	_ "github.com/prometheus/prometheus/discovery/consul"
-
 	// Register digitalocean plugin.
 	_ "github.com/prometheus/prometheus/discovery/digitalocean"
 
