Resolve host IPs through DNS, add purge, French date format by default
- Reverse DNS (cached PTR lookups): IP hosts are stored with their name in 'host' and the IP in 'host_ip'; older IP-only logs are resolved on display and the host filter shows 'name (IP)'. RDNS / DNS_SERVER env. - Settings > Danger zone: delete all logs (type PURGE to confirm) through VictoriaLogs /delete/run_task; -delete.enable added to docker-compose. ALLOW_PURGE env to disable it. - Remove the custom YYYY-MM-DD - HH:MM:SS:mmm format; default is now the usual French display DD/MM/YYYY HH:MM:SS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
85701a9119
commit
7a706eeb82
11 files changed
+455
-21
No files matched your search
@@ -171,6 +171,60 @@ func (s *Store) Query(ctx context.Context, query string) ([]map[string]any, erro
|
||||
return rows, sc.Err()
|
||||
}
|
||||
|
||||
// Purge starts a VictoriaLogs task that deletes every stored log, and resets
|
||||
// the counters. VictoriaLogs must run with -delete.enable.
|
||||
func (s *Store) Purge(ctx context.Context) (string, error) {
|
||||
body, err := s.deleteCall(ctx, "/delete/run_task?filter="+url.QueryEscape("*"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var res struct {
|
||||
TaskID string `json:"task_id"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &res); err != nil {
|
||||
return "", fmt.Errorf("unexpected VictoriaLogs answer: %s", strings.TrimSpace(string(body)))
|
||||
}
|
||||
s.received.Store(0)
|
||||
s.ingested.Store(0)
|
||||
s.dropped.Store(0)
|
||||
s.lastErr.Store("")
|
||||
return res.TaskID, nil
|
||||
}
|
||||
|
||||
// PurgeRunning returns the number of deletion tasks still running in VictoriaLogs.
|
||||
func (s *Store) PurgeRunning(ctx context.Context) (int, error) {
|
||||
body, err := s.deleteCall(ctx, "/delete/active_tasks")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var tasks []json.RawMessage
|
||||
if err := json.Unmarshal(body, &tasks); err != nil {
|
||||
return 0, fmt.Errorf("unexpected VictoriaLogs answer: %s", strings.TrimSpace(string(body)))
|
||||
}
|
||||
return len(tasks), nil
|
||||
}
|
||||
|
||||
func (s *Store) deleteCall(ctx context.Context, path string) ([]byte, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.base+path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
msg := strings.TrimSpace(string(body))
|
||||
if resp.StatusCode == http.StatusNotFound || strings.Contains(msg, "delete.enable") {
|
||||
return nil, &codedError{code: "purge_unavailable", msg: "VictoriaLogs refuses deletions: start it with -delete.enable (see docker-compose.yml)", detail: msg}
|
||||
}
|
||||
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, msg)
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func (s *Store) Stats() map[string]any {
|
||||
return map[string]any{
|
||||
"received": s.received.Load(),
|
||||
|
||||
Reference in new issue
Block a user