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

Forwarded: not-needed
Last-Update: 2025-02-09

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

diff --git a/config/config_test.go b/config/config_test.go
index d3e860b..ecb8c0a 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"
@@ -385,61 +384,6 @@ var expectedConf = &Config{
 				},
 			},
 		},
-		{
-			JobName: "service-y",
-
-			HonorTimestamps:       true,
-			ScrapeInterval:        model.Duration(15 * time.Second),
-			ScrapeTimeout:         DefaultGlobalConfig.ScrapeTimeout,
-			EnableCompression:     true,
-			BodySizeLimit:         globBodySizeLimit,
-			SampleLimit:           globSampleLimit,
-			TargetLimit:           globTargetLimit,
-			LabelLimit:            globLabelLimit,
-			LabelNameLengthLimit:  globLabelNameLengthLimit,
-			LabelValueLengthLimit: globLabelValueLengthLimit,
-			ScrapeProtocols:       DefaultGlobalConfig.ScrapeProtocols,
-
-			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",
 
@@ -1470,7 +1414,7 @@ func TestElideSecrets(t *testing.T) {
 	yamlConfig := string(config)
 
 	matches := secretRe.FindAllStringIndex(yamlConfig, -1)
-	require.Len(t, matches, 22, "wrong number of secret matches found")
+	require.Len(t, matches, 21, "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 3890f51..a7bcdf2 100644
--- a/config/testdata/conf.good.yml
+++ b/config/testdata/conf.good.yml
@@ -160,31 +160,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 51b59dd..f560e8c 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 bdc1fc8..acde681 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 e3bc793..03e5f09 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/consul/metrics.go b/discovery/consul/metrics.go
index 8266e7c..b57999d 100644
--- a/discovery/consul/metrics.go
+++ b/discovery/consul/metrics.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 41c13fb..631b61f 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 e3f0c7a..ce286a1 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"
 
