Skip to content

Commit

Permalink
Fix flaky test because of prometheus metrics: blackhole metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoShaka committed Oct 31, 2024
1 parent c1f368e commit eb0e8ac
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions integration/tctl_terraform_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"context"
"encoding/base64"
"github.com/prometheus/client_golang/prometheus"
"log/slog"
"os"
"path/filepath"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit eb0e8ac

Please sign in to comment.