Skip to content

Commit

Permalink
Remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome committed Jan 18, 2024
1 parent 72d3c05 commit 3751033
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 21 deletions.
4 changes: 1 addition & 3 deletions cmd/carbonapi/http/expand_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ func expandHandler(w http.ResponseWriter, r *http.Request) {
queryLengthSum += uint64(len(q))
}
if queryLengthSum > config.Config.MaxQueryLength {
http.Error(w, "query length limit exceeded", http.StatusBadRequest)
accessLogDetails.HTTPCode = http.StatusBadRequest
accessLogDetails.Reason = "query length limit exceeded"
setError(w, &accessLogDetails, "query length limit exceeded", http.StatusBadRequest, uid.String())
logAsError = true
return
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/carbonapi/http/find_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ func findHandler(w http.ResponseWriter, r *http.Request) {
queryLengthSum += uint64(len(q))
}
if queryLengthSum > config.Config.MaxQueryLength {
http.Error(w, "query length limit exceeded", http.StatusBadRequest)
accessLogDetails.HTTPCode = http.StatusBadRequest
accessLogDetails.Reason = "query length limit exceeded"
setError(w, &accessLogDetails, "query length limit exceeded", http.StatusBadRequest, uid.String())
logAsError = true
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/carbonapi/http/render_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func renderHandler(w http.ResponseWriter, r *http.Request) {
targetLengthSum += uint64(len(target))
}
if targetLengthSum > config.Config.MaxQueryLength {
setError(w, accessLogDetails, "total target length exceeded", http.StatusBadRequest, uid.String())
setError(w, accessLogDetails, "total target length limit exceeded", http.StatusBadRequest, uid.String())
logAsError = true
return
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/carbonapi/http/tags_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func tagHandler(w http.ResponseWriter, r *http.Request) {
rawQuery := q.Encode()

if uint64(len(rawQuery)) > config.Config.MaxQueryLength {
http.Error(w, "query length limit exceeded", http.StatusBadRequest)
accessLogDetails.HTTPCode = http.StatusBadRequest
accessLogDetails.Reason = "query length limit exceeded"
setError(w, accessLogDetails, "query length limit exceeded", http.StatusBadRequest, uuid.String())
logAsError = true
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,45 @@ test:
- name: "carbonapi"
binary: "./carbonapi"
args:
- "-test"
- "-config"
- "./cmd/mockbackend/testcases/pr743/carbonapi.yaml"
queries:
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/render?target=a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.b&format=json"
expectedResponse:
httpCode: 400
contentType: "text/plain; charset=utf-8"
emptyBody: true
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/metrics/find?query=a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.*"
expectedResponse:
httpCode: 400
contentType: "text/plain; charset=utf-8"
emptyBody: true
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/metrics/expand?query=a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.b"
expectedResponse:
httpCode: 400
contentType: "text/plain; charset=utf-8"
emptyBody: true
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/tags/autoComplete/tags?query=a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.b"
expectedResponse:
httpCode: 400
contentType: "text/plain; charset=utf-8"
emptyBody: true
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/tags/autoComplete/values?query=a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.b"
expectedResponse:
httpCode: 400
contentType: "text/plain; charset=utf-8"
emptyBody: true
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/render/?target=a.b.c&target=a.b.d&format=json"
expectedResponse:
Expand All @@ -62,28 +55,24 @@ test:
- target: "a.b.d"
datapoints: [[31,1],[10,2],[4,3],[7,4],[3,5]]
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/metrics/find?query=a.b.*&format=json"
expectedResponse:
httpCode: 200
contentType: "application/json"
# - endpoint: "http://127.0.0.1:8081"
# delay: 1
# type: "GET"
# URL: "/metrics/expand?query=a.*&format=json"
# expectedResponse:
# httpCode: 200
# contentType: "application/json"
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/tags/autoComplete/tags?query=a.b.c"
expectedResponse:
httpCode: 200
contentType: "application/json"
- endpoint: "http://127.0.0.1:8081"
delay: 1
type: "GET"
URL: "/tags/autoComplete/values?query=a.b.c"
expectedResponse:
Expand Down

0 comments on commit 3751033

Please sign in to comment.