Skip to content

Commit

Permalink
Use correct error write function (grafana#11487)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
This fixes the last known regression for `protobuf` encoding.

**Checklist**
- [ ] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [x] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] If the change is worth mentioning in the release notes, add
`add-to-release-notes` label
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/setup/upgrade/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](grafana@d10549e)
- [ ] If the change is deprecating or removing a configuration option,
update the `deprecated-config.yaml` and `deleted-config.yaml` files
respectively in the `tools/deprecated-config-checker` directory.
[Example
PR](grafana@0d4416a)
  • Loading branch information
jeschkies authored and rhnasc committed Apr 12, 2024
1 parent 5b4e561 commit e569be9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 46 deletions.
7 changes: 6 additions & 1 deletion integration/loki_micro_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ func TestMicroServicesIngestQuery(t *testing.T) {
assert.ElementsMatch(t, []map[string]string{{"job": "fake"}}, resp)
})

t.Run("stats error", func(t *testing.T) {
t.Run("series error", func(t *testing.T) {
_, err := cliQueryFrontend.Series(context.Background(), `{job="fake"}|= "search"`)
require.ErrorContains(t, err, "status code 400: only label matchers are supported")
})

t.Run("stats error", func(t *testing.T) {
_, err := cliQueryFrontend.Stats(context.Background(), `{job="fake"}|= "search"`)
require.ErrorContains(t, err, "status code 400: only label matchers are supported")
})

t.Run("per-request-limits", func(t *testing.T) {
queryLimitsPolicy := client.InjectHeadersOption(map[string][]string{querylimits.HTTPHeaderQueryLimitsKey: {`{"maxQueryLength": "1m"}`}})
cliQueryFrontendLimited := client.New(tenantID, "", tQueryFrontend.HTTPURL(), queryLimitsPolicy)
Expand Down
17 changes: 2 additions & 15 deletions pkg/lokifrontend/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
querier_stats "github.com/grafana/loki/pkg/querier/stats"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/server"
)

const (
Expand Down Expand Up @@ -133,7 +134,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
queryResponseTime := time.Since(startTime)

if err != nil {
writeError(w, err)
server.WriteError(err, w)
return
}

Expand Down Expand Up @@ -229,20 +230,6 @@ func formatQueryString(queryString url.Values) (fields []interface{}) {
return fields
}

func writeError(w http.ResponseWriter, err error) {
switch err {
case context.Canceled:
err = errCanceled
case context.DeadlineExceeded:
err = errDeadlineExceeded
default:
if util.IsRequestBodyTooLarge(err) {
err = errRequestEntityTooLarge
}
}
httpgrpc.WriteError(w, err)
}

func writeServiceTimingHeader(queryResponseTime time.Duration, headers http.Header, stats *querier_stats.Stats) {
if stats != nil {
parts := make([]string, 0)
Expand Down
30 changes: 0 additions & 30 deletions pkg/lokifrontend/frontend/transport/handler_test.go

This file was deleted.

0 comments on commit e569be9

Please sign in to comment.