From eb0e8ac404ee1bcceeebeae7d3ac82ca75190e54 Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Thu, 31 Oct 2024 17:01:39 -0400 Subject: [PATCH 1/2] Fix flaky test because of prometheus metrics: blackhole metrics --- integration/tctl_terraform_env_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/integration/tctl_terraform_env_test.go b/integration/tctl_terraform_env_test.go index b949d9b96033e..62cbcf4b4c54d 100644 --- a/integration/tctl_terraform_env_test.go +++ b/integration/tctl_terraform_env_test.go @@ -23,6 +23,7 @@ import ( "bytes" "context" "encoding/base64" + "github.com/prometheus/client_golang/prometheus" "log/slog" "os" "path/filepath" @@ -52,6 +53,7 @@ import ( // service and generates valid credentials Terraform can use to connect to Teleport. func TestTCTLTerraformCommand_ProxyJoin(t *testing.T) { testDir := t.TempDir() + prometheus.DefaultRegisterer = metricRegistryBlackHole{} // Test setup: creating a teleport instance running auth and proxy clusterName := "root.example.com" @@ -127,6 +129,7 @@ func TestTCTLTerraformCommand_ProxyJoin(t *testing.T) { func TestTCTLTerraformCommand_AuthJoin(t *testing.T) { t.Parallel() testDir := t.TempDir() + prometheus.DefaultRegisterer = metricRegistryBlackHole{} // Test setup: creating a teleport instance running auth and proxy clusterName := "root.example.com" @@ -348,3 +351,20 @@ func connectWithCredentialsFromVars(t *testing.T, vars map[string]string, clt *a _, err = botClt.Ping(ctx) require.NoError(t, err) } + +// metricRegistryBlackHole is a fake prometheus.Registerer that accepts every metric and do nothing. +// This is a workaround for different teleport component using the global registry but registering incompatible metrics. +// Those issues can surface during integration tests starting Teleport auth, proxy, and tbot. +// The long-term fix is to have every component use its own registry instead of the global one. +type metricRegistryBlackHole struct { +} + +func (m metricRegistryBlackHole) Register(_ prometheus.Collector) error { + return nil +} + +func (m metricRegistryBlackHole) MustRegister(_ ...prometheus.Collector) {} + +func (m metricRegistryBlackHole) Unregister(_ prometheus.Collector) bool { + return true +} From f487795dd9738681d580be52dedac89f85f4239b Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Thu, 31 Oct 2024 17:02:19 -0400 Subject: [PATCH 2/2] lint --- integration/tctl_terraform_env_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/tctl_terraform_env_test.go b/integration/tctl_terraform_env_test.go index 62cbcf4b4c54d..d7a9ac1c2dad0 100644 --- a/integration/tctl_terraform_env_test.go +++ b/integration/tctl_terraform_env_test.go @@ -23,7 +23,6 @@ import ( "bytes" "context" "encoding/base64" - "github.com/prometheus/client_golang/prometheus" "log/slog" "os" "path/filepath" @@ -33,6 +32,7 @@ import ( "github.com/alecthomas/kingpin/v2" "github.com/google/uuid" + "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require"