Skip to content

Commit

Permalink
Clickhouse fix (#698)
Browse files Browse the repository at this point in the history
* include select with newline in clickhouse queries

Signed-off-by: jnichols <mail@jnichols.info>

* remove unused body = make(...) call

Signed-off-by: jnichols <mail@jnichols.info>

* ensure negative cache is disabled when testing empty config for opc

Signed-off-by: jnichols <mail@jnichols.info>

---------

Signed-off-by: jnichols <mail@jnichols.info>
  • Loading branch information
jnichols-git authored Feb 17, 2024
1 parent f31766c commit 7522d5c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/backends/clickhouse/handler_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (c *Client) QueryHandler(w http.ResponseWriter, r *http.Request) {
}
var body []byte
if sqlQuery != "" {
body = make([]byte, 0, len(sqlQuery)+len(b))
body = append([]byte(sqlQuery), b...)
q.Del(upQuery)
r.URL.RawQuery = q.Encode()
Expand All @@ -52,7 +51,9 @@ func (c *Client) QueryHandler(w http.ResponseWriter, r *http.Request) {
r = request.SetBody(r, body)
}
sqlQuery = strings.ToLower(sqlQuery)
if (!strings.HasPrefix(sqlQuery, "select ")) && (!(strings.Index(sqlQuery, " select ") > 0)) {
if !(strings.HasPrefix(sqlQuery, "select ") ||
strings.HasPrefix(sqlQuery, "select\n") ||
strings.Contains(sqlQuery, " select ")) {
c.ProxyHandler(w, r)
return
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/proxy/engines/objectproxycache_chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ func TestObjectProxyCacheRequestNegativeCacheChunks(t *testing.T) {
r = r.WithContext(tc.WithResources(r.Context(), request.NewResources(cfg, pc, rsc.CacheConfig,
rsc.CacheClient, rsc.BackendClient, nil, rsc.Logger)))

// Remove negative cache for first request
delete(cfg.NegativeCache, 404)

_, e := testFetchOPC(r, http.StatusNotFound, "test", map[string]string{"status": "kmiss"})
for _, err = range e {
t.Error(err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/proxy/engines/objectproxycache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,9 @@ func TestObjectProxyCacheRequestNegativeCache(t *testing.T) {
r = r.WithContext(tc.WithResources(r.Context(), request.NewResources(cfg, pc, rsc.CacheConfig,
rsc.CacheClient, rsc.BackendClient, nil, rsc.Logger)))

// Remove negative cache for first request
delete(cfg.NegativeCache, 404)

_, e := testFetchOPC(r, http.StatusNotFound, "test", map[string]string{"status": "kmiss"})
for _, err = range e {
t.Error(err)
Expand Down

0 comments on commit 7522d5c

Please sign in to comment.