vmalert: Redact passwords from error messages (#1713)

This commit is contained in:
Alexander Rickardsson 2021-10-18 09:20:26 +02:00 committed by Aliaksandr Valialkin
parent ed994873fd
commit 63571e1334
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
4 changed files with 7 additions and 7 deletions

View File

@ -132,12 +132,12 @@ func (s *VMStorage) QueryRange(ctx context.Context, query string, start, end tim
func (s *VMStorage) do(ctx context.Context, req *http.Request) (*http.Response, error) { func (s *VMStorage) do(ctx context.Context, req *http.Request) (*http.Response, error) {
resp, err := s.c.Do(req.WithContext(ctx)) resp, err := s.c.Do(req.WithContext(ctx))
if err != nil { if err != nil {
return nil, fmt.Errorf("error getting response from %s: %w", req.URL, err) return nil, fmt.Errorf("error getting response from %s: %w", req.URL.Redacted(), err)
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
return nil, fmt.Errorf("unexpected response code %d for %s. Response body %s", resp.StatusCode, req.URL, body) return nil, fmt.Errorf("unexpected response code %d for %s. Response body %s", resp.StatusCode, req.URL.Redacted(), body)
} }
return resp, nil return resp, nil
} }

View File

@ -38,7 +38,7 @@ func (r graphiteResponse) metrics() []Metric {
func parseGraphiteResponse(req *http.Request, resp *http.Response) ([]Metric, error) { func parseGraphiteResponse(req *http.Request, resp *http.Response) ([]Metric, error) {
r := &graphiteResponse{} r := &graphiteResponse{}
if err := json.NewDecoder(resp.Body).Decode(r); err != nil { if err := json.NewDecoder(resp.Body).Decode(r); err != nil {
return nil, fmt.Errorf("error parsing graphite metrics for %s: %w", req.URL, err) return nil, fmt.Errorf("error parsing graphite metrics for %s: %w", req.URL.Redacted(), err)
} }
return r.metrics(), nil return r.metrics(), nil
} }

View File

@ -82,10 +82,10 @@ const (
func parsePrometheusResponse(req *http.Request, resp *http.Response) ([]Metric, error) { func parsePrometheusResponse(req *http.Request, resp *http.Response) ([]Metric, error) {
r := &promResponse{} r := &promResponse{}
if err := json.NewDecoder(resp.Body).Decode(r); err != nil { if err := json.NewDecoder(resp.Body).Decode(r); err != nil {
return nil, fmt.Errorf("error parsing prometheus metrics for %s: %w", req.URL, err) return nil, fmt.Errorf("error parsing prometheus metrics for %s: %w", req.URL.Redacted(), err)
} }
if r.Status == statusError { if r.Status == statusError {
return nil, fmt.Errorf("response error, query: %s, errorType: %s, error: %s", req.URL, r.ErrorType, r.Error) return nil, fmt.Errorf("response error, query: %s, errorType: %s, error: %s", req.URL.Redacted(), r.ErrorType, r.Error)
} }
if r.Status != statusSuccess { if r.Status != statusSuccess {
return nil, fmt.Errorf("unknown status: %s, Expected success or error ", r.Status) return nil, fmt.Errorf("unknown status: %s, Expected success or error ", r.Status)

View File

@ -246,13 +246,13 @@ func (c *Client) send(ctx context.Context, data []byte) error {
resp, err := c.c.Do(req.WithContext(ctx)) resp, err := c.c.Do(req.WithContext(ctx))
if err != nil { if err != nil {
return fmt.Errorf("error while sending request to %s: %w; Data len %d(%d)", return fmt.Errorf("error while sending request to %s: %w; Data len %d(%d)",
req.URL, err, len(data), r.Size()) req.URL.Redacted(), err, len(data), r.Size())
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("unexpected response code %d for %s. Response body %q", return fmt.Errorf("unexpected response code %d for %s. Response body %q",
resp.StatusCode, req.URL, body) resp.StatusCode, req.URL.Redacted(), body)
} }
return nil return nil
} }