Skip to content

Commit 267c26e

Browse files
refactor: change returned status code and description in clickhouse error handling (#286)
1 parent aeb92af commit 267c26e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

cmd/e2e-test/carbon-clickhouse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type CarbonClickhouse struct {
2828

2929
func (c *CarbonClickhouse) Start(testDir, clickhouseURL string) (string, error) {
3030
if len(c.Version) == 0 {
31-
c.Version = "0.11.4"
31+
c.Version = "latest"
3232
}
3333
if len(c.DockerImage) == 0 {
3434
c.DockerImage = "ghcr.io/go-graphite/carbon-clickhouse"

helper/clickhouse/clickhouse.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ func extractClickhouseError(e string) (int, string) {
7272
return http.StatusServiceUnavailable, "Storage configuration error"
7373
}
7474
}
75-
return http.StatusInternalServerError, "Storage error"
75+
if strings.HasPrefix(e, "clickhouse response status 404: Code: 60. DB::Exception: Table default.") {
76+
return http.StatusServiceUnavailable, "Storage default tables damaged"
77+
}
78+
return http.StatusServiceUnavailable, "Storage unavailable"
7679
}
7780

7881
func HandleError(w http.ResponseWriter, err error) (status int, queueFail bool) {

helper/clickhouse/clickhouse_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ func Test_extractClickhouseError(t *testing.T) {
3434
wantStatus: http.StatusForbidden,
3535
wantMessage: "Storage read limit for memory",
3636
},
37+
{
38+
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",
39+
wantStatus: http.StatusServiceUnavailable,
40+
wantMessage: "Storage default tables damaged",
41+
},
3742
{
3843
errStr: "Other error",
39-
wantStatus: http.StatusInternalServerError,
40-
wantMessage: "Storage error",
44+
wantStatus: http.StatusServiceUnavailable,
45+
wantMessage: "Storage unavailable",
4146
},
4247
}
4348
for _, tt := range tests {

0 commit comments

Comments
 (0)