forked from mirror/client_golang
Merge pull request #944 from yeya24/add-wal-replay-status
API: support wal replay status api
This commit is contained in:
commit
e6e54e8082
|
@ -139,6 +139,7 @@ const (
|
|||
epBuildinfo = apiPrefix + "/status/buildinfo"
|
||||
epRuntimeinfo = apiPrefix + "/status/runtimeinfo"
|
||||
epTSDB = apiPrefix + "/status/tsdb"
|
||||
epWalReplay = apiPrefix + "/status/walreplay"
|
||||
)
|
||||
|
||||
// AlertState models the state of an alert.
|
||||
|
@ -261,6 +262,8 @@ type API interface {
|
|||
Metadata(ctx context.Context, metric string, limit string) (map[string][]Metadata, error)
|
||||
// TSDB returns the cardinality statistics.
|
||||
TSDB(ctx context.Context) (TSDBResult, error)
|
||||
// WalReplay returns the current replay status of the wal.
|
||||
WalReplay(ctx context.Context) (WalReplayStatus, error)
|
||||
}
|
||||
|
||||
// AlertsResult contains the result from querying the alerts endpoint.
|
||||
|
@ -437,6 +440,13 @@ type TSDBResult struct {
|
|||
SeriesCountByLabelValuePair []Stat `json:"seriesCountByLabelValuePair"`
|
||||
}
|
||||
|
||||
// WalReplayStatus represents the wal replay status.
|
||||
type WalReplayStatus struct {
|
||||
Min int `json:"min"`
|
||||
Max int `json:"max"`
|
||||
Current int `json:"current"`
|
||||
}
|
||||
|
||||
// Stat models information about statistic value.
|
||||
type Stat struct {
|
||||
Name string `json:"name"`
|
||||
|
@ -984,6 +994,23 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
|
|||
return res, json.Unmarshal(body, &res)
|
||||
}
|
||||
|
||||
func (h *httpAPI) WalReplay(ctx context.Context) (WalReplayStatus, error) {
|
||||
u := h.client.URL(epWalReplay, nil)
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
if err != nil {
|
||||
return WalReplayStatus{}, err
|
||||
}
|
||||
|
||||
_, body, _, err := h.client.Do(ctx, req)
|
||||
if err != nil {
|
||||
return WalReplayStatus{}, err
|
||||
}
|
||||
|
||||
var res WalReplayStatus
|
||||
return res, json.Unmarshal(body, &res)
|
||||
}
|
||||
|
||||
func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime time.Time, endTime time.Time) ([]ExemplarQueryResult, error) {
|
||||
u := h.client.URL(epQueryExemplars, nil)
|
||||
q := u.Query()
|
||||
|
|
|
@ -230,6 +230,13 @@ func TestAPIs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
doWalReply := func() func() (interface{}, Warnings, error) {
|
||||
return func() (interface{}, Warnings, error) {
|
||||
v, err := promAPI.WalReplay(context.Background())
|
||||
return v, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
doQueryExemplars := func(query string, startTime time.Time, endTime time.Time) func() (interface{}, Warnings, error) {
|
||||
return func() (interface{}, Warnings, error) {
|
||||
v, err := promAPI.QueryExemplars(context.Background(), query, startTime, endTime)
|
||||
|
@ -1198,6 +1205,30 @@ func TestAPIs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
{
|
||||
do: doWalReply(),
|
||||
reqMethod: "GET",
|
||||
reqPath: "/api/v1/status/walreplay",
|
||||
inErr: fmt.Errorf("some error"),
|
||||
err: fmt.Errorf("some error"),
|
||||
},
|
||||
|
||||
{
|
||||
do: doWalReply(),
|
||||
reqMethod: "GET",
|
||||
reqPath: "/api/v1/status/walreplay",
|
||||
inRes: map[string]interface{}{
|
||||
"min": 2,
|
||||
"max": 5,
|
||||
"current": 40,
|
||||
},
|
||||
res: WalReplayStatus{
|
||||
Min: 2,
|
||||
Max: 5,
|
||||
Current: 40,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
|
||||
reqMethod: "GET",
|
||||
|
|
Loading…
Reference in New Issue