Skip to content

Commit

Permalink
[BUGFIX] curl请求采集接口时,http.resp.status_code 非200直接报错返回,避免权限错误引起的解析错误的误导
Browse files Browse the repository at this point in the history
  • Loading branch information
ning1875 committed Feb 24, 2021
1 parent c722fe6 commit 5fb4fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.0.5 / 2021-02-24
* [BUGFIX] curl请求采集接口时,http.resp.status_code 非200直接报错返回,避免权限错误引起的解析错误的误导

## v2.0.4 / 2021-01-28
* [FEATURE] 新增ksm指标计算节点cpu/mem 请求/限制率等指标
* [BUGFIX] ksm启动不再sleep等待,因为push的瓶颈在transfer已经解决了
Expand Down
5 changes: 5 additions & 0 deletions collect/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package collect
import (
"context"
"crypto/md5"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -593,6 +594,10 @@ func CurlTlsMetricsApi(logger log.Logger, funcName string, cg *config.CommonApiS
level.Error(logger).Log("msg", "client request error", "funcName", funcName, "err", err)
return nil, err
}
if resp.StatusCode != http.StatusOK {
level.Error(logger).Log("msg", "target_scrape_status_code_not_200_maybe_unauthorized", "funcName", funcName, "StatusCode", resp.StatusCode, "Status", resp.Status)
return nil, errors.New(fmt.Sprintf("server returned HTTP status %s", resp.Status))
}
defer func() {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
Expand Down

0 comments on commit 5fb4fd5

Please sign in to comment.