Skip to content

Commit

Permalink
refactor: change returned status code and description in clickhouse e…
Browse files Browse the repository at this point in the history
…rror handling (#286)
  • Loading branch information
AleksandrMatsko authored Aug 12, 2024
1 parent aeb92af commit 267c26e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/e2e-test/carbon-clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion helper/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions helper/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 267c26e

Please sign in to comment.