VictoriaMetrics / VictoriaMetrics

VictoriaMetrics: fast, cost-effective monitoring solution and time series database
https://victoriametrics.com/
Apache License 2.0
12.04k stars 1.19k forks source link

query_range and query API return `errorType` code #6413

Open IsQiao opened 4 months ago

IsQiao commented 4 months ago

Is your feature request related to a problem? Please describe

No response

Describe the solution you'd like

i want to check the error type, but current the error code '422' is too vague, many error types is '422'

Current

error response format when call victorial metrics query_range API:

func sendPrometheusError(w http.ResponseWriter, r *http.Request, err error) {
    logger.WarnfSkipframes(1, "error in %q: %s", httpserver.GetRequestURI(r), err)

    w.Header().Set("Content-Type", "application/json")
    statusCode := http.StatusUnprocessableEntity
    var esc *httpserver.ErrorWithStatusCode
    if errors.As(err, &esc) {
        statusCode = esc.StatusCode
    }
    w.WriteHeader(statusCode)

    var ure *promql.UserReadableError
    if errors.As(err, &ure) {
        err = ure
    }
    prometheus.WriteErrorResponse(w, statusCode, err)
}
{
    "status": "error",
    "errorType": "422",
    "error": "not enough memory for processing {{expr}}, which returns 692272000 data points across 8000 time series with 86534 points in each time series; total available memory for concurrent requests: 7129148723 bytes; requested memory: 11091552000 bytes; possible solutions are: reducing the number of matching time series; increasing `step` query arg (step=30s); switching to node with more RAM; increasing -memory.allowedPercent"
}

Solution

like prometheus response error type

https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go#L411

const (
    // Possible values for ErrorType.
    ErrBadData     ErrorType = "bad_data"
    ErrTimeout     ErrorType = "timeout"
    ErrCanceled    ErrorType = "canceled"
    ErrExec        ErrorType = "execution"
    ErrBadResponse ErrorType = "bad_response"
    ErrServer      ErrorType = "server_error"
    ErrClient      ErrorType = "client_error"
)

Describe alternatives you've considered

No response

Additional information

No response

hagen1778 commented 3 months ago

Hi @IsQiao!

I don't think it will be that useful, because none of the components VictoriaMetrics can be integrated will expect it to return error codes. In result, none of these integrations would benefit from having these error codes added.

IsQiao commented 3 months ago

Hi @hagen1778 , My current scenario is that there is a charting front-end under development that is using VictorialMetrics as the back-end engine, and the charting front-end when configured with some very large time ranges or label ranges some of the scenarios get an error, and these errors want to be asserted by the front-end and then i18n processed to display.

It's okay. I'll think of something else. Thank you.

hagen1778 commented 3 months ago

Let's keep this issue open in case if other users will find it useful.