Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package vmsup
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// DeleteSeries removes every series matching any of matchers from the named store with VictoriaMetrics'
|
|
// delete_series. Whole series only: the API takes no time range. It talks to the store's localhost URL.
|
|
func DeleteSeries(ctx context.Context, hc *http.Client, t Target, store string, matchers []string) error {
|
|
if !t.Healthy(store) {
|
|
return fmt.Errorf("%w: %s", ErrStoreDown, store)
|
|
}
|
|
form := url.Values{"match[]": matchers}
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, t.URL(store)+"/api/v1/admin/tsdb/delete_series",
|
|
strings.NewReader(form.Encode()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
resp, err := hc.Do(req)
|
|
if err != nil {
|
|
return fmt.Errorf("delete series in %s: %w", store, err)
|
|
}
|
|
defer func() { _ = resp.Body.Close() }()
|
|
msg, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
|
if resp.StatusCode/100 != 2 {
|
|
return fmt.Errorf("delete series in %s: %s: %s", store, resp.Status, strings.TrimSpace(string(msg)))
|
|
}
|
|
return nil
|
|
}
|