Thanos Sidecar release-0.26 源码阅读和分析
https://github.com/thanos-io/thanos/blob/release-0.26
一、整体架构
Thanos Sidecar 作为 Prometheus 的伴生容器运行,主要负责:
- Prometheus 健康检查
- 提供 HTTP API 查询接口
- 提供 gRPC 查询服务
- 数据块上传到对象存储
- 最近数据(head chunks)的查询
二、源码分析
2.1、Prometheus 探活实现部分
https://github.com/thanos-io/thanos/blob/release-0.26/pkg/promclient/promclient.go
// 68行-73行 // Client represents a Prometheus API client. type Client struct { HTTPClient userAgent string logger log.Logger } …… // 654行-693行 // 健康检查实现 func (c *Client) get2xxResultWithGRPCErrors(ctx context.Context, spanName string, u *url.URL, data interface{}) error { span, ctx := tracing.StartSpan(ctx, spanName) defer span.Finish() body, code, err := c.req2xx(ctx, u, http.MethodGet) if err != nil { if code, exists := statusToCode[code]; exists && code != 0 { return status.Error(code, err.Error()) } return status.Error(codes.Internal, err.Error()) } if code == http.StatusNoContent { return nil } var m struct { Data interface{} `json:"data"` Status string `json:"status"` Error string `json:"error"` } if err = json.Unmarshal(body, &m); err != nil { return status.Error(codes.Internal, err.Error()) } if m.Status != SUCCESS { code, exists := statusToCode[code] if !exists { return status.Error(codes.Internal, m.Error) } return status.Error(code, m.Error) } if err = json.Unmarshal(body, &data); err != nil { return status.Error(codes.Internal, err.Error()) } return nil }
标签:status,code,return,err,精讲,源码,Error,Thanos From: https://www.cnblogs.com/zuoyang/p/18685455