From 64d157538593d2fb2728799a0355d960fc209ff9 Mon Sep 17 00:00:00 2001 From: AleksandrMatsko Date: Tue, 6 Aug 2024 11:20:22 +0700 Subject: [PATCH] refactor: change returned status code and description in clickhouse error handling --- cmd/e2e-test/carbon-clickhouse.go | 2 +- helper/clickhouse/clickhouse.go | 5 ++++- helper/clickhouse/clickhouse_test.go | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/e2e-test/carbon-clickhouse.go b/cmd/e2e-test/carbon-clickhouse.go index 01d684a68..fcd45db3a 100644 --- a/cmd/e2e-test/carbon-clickhouse.go +++ b/cmd/e2e-test/carbon-clickhouse.go @@ -28,7 +28,7 @@ type CarbonClickhouse struct { func (c *CarbonClickhouse) Start(testDir, clickhouseURL string) (string, error) { if len(c.Version) == 0 { - c.Version = "0.11.4" + c.Version = "latest" } if len(c.DockerImage) == 0 { c.DockerImage = "ghcr.io/go-graphite/carbon-clickhouse" diff --git a/helper/clickhouse/clickhouse.go b/helper/clickhouse/clickhouse.go index 036e546d3..326c01290 100644 --- a/helper/clickhouse/clickhouse.go +++ b/helper/clickhouse/clickhouse.go @@ -72,7 +72,10 @@ func extractClickhouseError(e string) (int, string) { return http.StatusServiceUnavailable, "Storage configuration error" } } - return http.StatusInternalServerError, "Storage error" + if strings.HasPrefix(e, "clickhouse response status 404: Code: 60. DB::Exception: Table default.") { + return http.StatusServiceUnavailable, "Storage default tables damaged" + } + return http.StatusServiceUnavailable, "Storage unavailable" } func HandleError(w http.ResponseWriter, err error) (status int, queueFail bool) { diff --git a/helper/clickhouse/clickhouse_test.go b/helper/clickhouse/clickhouse_test.go index 6772fce73..4a3304a83 100644 --- a/helper/clickhouse/clickhouse_test.go +++ b/helper/clickhouse/clickhouse_test.go @@ -34,10 +34,15 @@ func Test_extractClickhouseError(t *testing.T) { wantStatus: http.StatusForbidden, wantMessage: "Storage read limit for memory", }, + { + errStr: "clickhouse response status 404: Code: 60. DB::Exception: Table default.graphite_index does not exist. (UNKNOWN_TABLE) (version 23.12.6.19 (official build))\n", + wantStatus: http.StatusServiceUnavailable, + wantMessage: "Storage default tables damaged", + }, { errStr: "Other error", - wantStatus: http.StatusInternalServerError, - wantMessage: "Storage error", + wantStatus: http.StatusServiceUnavailable, + wantMessage: "Storage unavailable", }, } for _, tt := range tests {