Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v16] Fix flaky integration tests caused by prometheus metrics conficts #51206

Open
wants to merge 1 commit into
base: branch/v16
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration/tctl_terraform_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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"

Expand All @@ -51,6 +52,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"
Expand Down Expand Up @@ -126,6 +128,7 @@ func TestTCTLTerraformCommand_ProxyJoin(t *testing.T) {
func TestTCTLTerraformCommand_AuthJoin(t *testing.T) {
t.Parallel()
testDir := t.TempDir()
prometheus.DefaultRegisterer = metricRegistryBlackHole{}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe to do in a parallel test?

// Test setup: creating a teleport instance running auth and proxy
clusterName := "root.example.com"
Expand Down Expand Up @@ -347,3 +350,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
}
Loading