Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions pkg/proxy/autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ func (s *server) reconcileClickHouseAutodiscover(ctx context.Context, entry Clic
return
}

// A failed probe means we could not determine availability, not that the
// datasource is gone. Leave the current state untouched so a transient
// error (timeout, network blip, 5xx) does not tear down a healthy
// datasource. Removal only happens when a probe succeeds and reports the
// database absent.
if err != nil {
logger.WithError(err).Debug("ClickHouse autodiscovery probe failed; leaving current state unchanged")

return
}

if available && !*present {
if !s.addAutodiscoveredClickHouseCluster(target.cluster) {
return
Expand All @@ -126,12 +137,6 @@ func (s *server) reconcileClickHouseAutodiscover(ctx context.Context, entry Clic
return
}

if err != nil {
logger.WithError(err).Debug("ClickHouse autodiscovery probe failed")

return
}

logger.WithField("available", available).Debug("ClickHouse autodiscovery state unchanged")
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,17 @@ func TestAutodiscoverReconcilesClickHouseDatasource(t *testing.T) {
t.Fatalf("/datasources ClickHouseInfo[0].Description = %q, want custom description", datasources.ClickHouseInfo[0].Description)
}

// A transient probe error must not remove a healthy datasource.
pingOK = false
srv.reconcileClickHouseAutodiscover(t.Context(), entry, &present)
if !present || !srv.clickhouseHandler.HasCluster("local-kurtosis") {
t.Fatal("expected datasource to survive a transient probe error")
}
pingOK = true

// A successful probe that reports the database absent removes it.
databaseExists = false
srv.reconcileClickHouseAutodiscover(t.Context(), entry, &present)
if present {
t.Fatal("expected datasource to become absent")
}
Expand All @@ -756,7 +765,7 @@ func TestAutodiscoverReconcilesClickHouseDatasource(t *testing.T) {
t.Fatalf("ClickHouseDatasourceInfo() after removal = %v, want empty", got)
}

pingOK = true
databaseExists = true
srv.reconcileClickHouseAutodiscover(t.Context(), entry, &present)
if !present {
t.Fatal("expected datasource to become present again")
Expand Down
Loading