From 78eeca6f0d394dfc14dbb30d6c2fe3227fedcf19 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 5 Jul 2022 23:56:31 +0300 Subject: [PATCH] lib/vmselectapi: rename deleteMetrics to more correct deleteSeries --- app/vmselect/netstorage/netstorage.go | 14 +++++++------- app/vmstorage/servers/vmselect.go | 4 ++-- lib/storage/storage.go | 6 +++--- lib/storage/storage_test.go | 16 ++++++++-------- lib/vmselectapi/api.go | 4 ++-- lib/vmselectapi/server.go | 14 +++++++------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index cd93bc5c9e..4a5b6bfdd9 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -657,7 +657,7 @@ func DeleteSeries(qt *querytracer.Tracer, at *auth.Token, sq *storage.SearchQuer } snr := startStorageNodesRequest(qt, true, func(qt *querytracer.Tracer, idx int, sn *storageNode) interface{} { sn.deleteSeriesRequests.Inc() - deletedCount, err := sn.deleteMetrics(qt, requestData, deadline) + deletedCount, err := sn.deleteSeries(qt, requestData, deadline) if err != nil { sn.deleteSeriesErrors.Inc() } @@ -1497,17 +1497,17 @@ func (sn *storageNode) registerMetricNames(qt *querytracer.Tracer, mrs []storage return sn.execOnConnWithPossibleRetry(qt, "registerMetricNames_v3", f, deadline) } -func (sn *storageNode) deleteMetrics(qt *querytracer.Tracer, requestData []byte, deadline searchutils.Deadline) (int, error) { +func (sn *storageNode) deleteSeries(qt *querytracer.Tracer, requestData []byte, deadline searchutils.Deadline) (int, error) { var deletedCount int f := func(bc *handshake.BufferedConn) error { - n, err := sn.deleteMetricsOnConn(bc, requestData) + n, err := sn.deleteSeriesOnConn(bc, requestData) if err != nil { return err } deletedCount = n return nil } - if err := sn.execOnConnWithPossibleRetry(qt, "deleteMetrics_v5", f, deadline); err != nil { + if err := sn.execOnConnWithPossibleRetry(qt, "deleteSeries_v5", f, deadline); err != nil { return 0, err } return deletedCount, nil @@ -1784,13 +1784,13 @@ func (sn *storageNode) registerMetricNamesOnConn(bc *handshake.BufferedConn, mrs return nil } -func (sn *storageNode) deleteMetricsOnConn(bc *handshake.BufferedConn, requestData []byte) (int, error) { +func (sn *storageNode) deleteSeriesOnConn(bc *handshake.BufferedConn, requestData []byte) (int, error) { // Send the request to sn if err := writeBytes(bc, requestData); err != nil { - return 0, fmt.Errorf("cannot send deleteMetrics request to conn: %w", err) + return 0, fmt.Errorf("cannot send deleteSeries request to conn: %w", err) } if err := bc.Flush(); err != nil { - return 0, fmt.Errorf("cannot flush deleteMetrics request to conn: %w", err) + return 0, fmt.Errorf("cannot flush deleteSeries request to conn: %w", err) } // Read response error. diff --git a/app/vmstorage/servers/vmselect.go b/app/vmstorage/servers/vmselect.go index d300880932..c8a64f81e7 100644 --- a/app/vmstorage/servers/vmselect.go +++ b/app/vmstorage/servers/vmselect.go @@ -86,8 +86,8 @@ func (api *vmstorageAPI) TSDBStatus(qt *querytracer.Tracer, accountID, projectID return api.s.GetTSDBStatus(qt, accountID, projectID, tfss, date, focusLabel, topN, maxMetrics, deadline) } -func (api *vmstorageAPI) DeleteMetrics(qt *querytracer.Tracer, tfss []*storage.TagFilters, maxMetrics int, deadline uint64) (int, error) { - return api.s.DeleteMetrics(qt, tfss) +func (api *vmstorageAPI) DeleteSeries(qt *querytracer.Tracer, tfss []*storage.TagFilters, maxMetrics int, deadline uint64) (int, error) { + return api.s.DeleteSeries(qt, tfss) } func (api *vmstorageAPI) RegisterMetricNames(qt *querytracer.Tracer, mrs []storage.MetricRow) error { diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 8a1b492389..7dbc4b6326 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1346,10 +1346,10 @@ func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, tsids []TSID, dead // ErrDeadlineExceeded is returned when the request times out. var ErrDeadlineExceeded = fmt.Errorf("deadline exceeded") -// DeleteMetrics deletes all the metrics matching the given tfss. +// DeleteSeries deletes all the series matching the given tfss. // // Returns the number of metrics deleted. -func (s *Storage) DeleteMetrics(qt *querytracer.Tracer, tfss []*TagFilters) (int, error) { +func (s *Storage) DeleteSeries(qt *querytracer.Tracer, tfss []*TagFilters) (int, error) { deletedCount, err := s.idb().DeleteTSIDs(qt, tfss) if err != nil { return deletedCount, fmt.Errorf("cannot delete tsids: %w", err) @@ -1889,7 +1889,7 @@ func (s *Storage) add(rows []rawRow, dstMrs []*MetricRow, mrs []MetricRow, preci // Fast path - the TSID for the given MetricNameRaw has been found in cache and isn't deleted. // There is no need in checking whether r.TSID.MetricID is deleted, since tsidCache doesn't // contain MetricName->TSID entries for deleted time series. - // See Storage.DeleteMetrics code for details. + // See Storage.DeleteSeries code for details. prevTSID = r.TSID prevMetricNameRaw = mr.MetricNameRaw diff --git a/lib/storage/storage_test.go b/lib/storage/storage_test.go index f49505bafd..6ef66309e7 100644 --- a/lib/storage/storage_test.go +++ b/lib/storage/storage_test.go @@ -531,8 +531,8 @@ func testStorageRandTimestamps(s *Storage) error { return nil } -func TestStorageDeleteMetrics(t *testing.T) { - path := "TestStorageDeleteMetrics" +func TestStorageDeleteSeries(t *testing.T) { + path := "TestStorageDeleteSeries" s, err := OpenStorage(path, 0, 0, 0) if err != nil { t.Fatalf("cannot open storage: %s", err) @@ -549,7 +549,7 @@ func TestStorageDeleteMetrics(t *testing.T) { t.Run("serial", func(t *testing.T) { for i := 0; i < 3; i++ { - if err = testStorageDeleteMetrics(s, 0); err != nil { + if err = testStorageDeleteSeries(s, 0); err != nil { t.Fatalf("unexpected error on iteration %d: %s", i, err) } @@ -569,7 +569,7 @@ func TestStorageDeleteMetrics(t *testing.T) { go func(workerNum int) { var err error for j := 0; j < 2; j++ { - err = testStorageDeleteMetrics(s, workerNum) + err = testStorageDeleteSeries(s, workerNum) if err != nil { break } @@ -604,7 +604,7 @@ func TestStorageDeleteMetrics(t *testing.T) { } } -func testStorageDeleteMetrics(s *Storage, workerNum int) error { +func testStorageDeleteSeries(s *Storage, workerNum int) error { const rowsPerMetric = 100 const metricsCount = 30 @@ -694,7 +694,7 @@ func testStorageDeleteMetrics(s *Storage, workerNum int) error { if n := metricBlocksCount(tfs); n == 0 { return fmt.Errorf("expecting non-zero number of metric blocks for tfs=%s", tfs) } - deletedCount, err := s.DeleteMetrics(nil, []*TagFilters{tfs}) + deletedCount, err := s.DeleteSeries(nil, []*TagFilters{tfs}) if err != nil { return fmt.Errorf("cannot delete metrics: %w", err) } @@ -702,11 +702,11 @@ func testStorageDeleteMetrics(s *Storage, workerNum int) error { return fmt.Errorf("expecting non-zero number of deleted metrics on iteration %d", i) } if n := metricBlocksCount(tfs); n != 0 { - return fmt.Errorf("expecting zero metric blocks after DeleteMetrics call for tfs=%s; got %d blocks", tfs, n) + return fmt.Errorf("expecting zero metric blocks after DeleteSeries call for tfs=%s; got %d blocks", tfs, n) } // Try deleting empty tfss - deletedCount, err = s.DeleteMetrics(nil, nil) + deletedCount, err = s.DeleteSeries(nil, nil) if err != nil { return fmt.Errorf("cannot delete empty tfss: %w", err) } diff --git a/lib/vmselectapi/api.go b/lib/vmselectapi/api.go index 1d2b8d0818..9b78980118 100644 --- a/lib/vmselectapi/api.go +++ b/lib/vmselectapi/api.go @@ -30,8 +30,8 @@ type API interface { // TSDBStatus returns tsdb status for the given sq. TSDBStatus(qt *querytracer.Tracer, accountID, projectID uint32, tfss []*storage.TagFilters, date uint64, focusLabel string, topN, maxMetrics int, deadline uint64) (*storage.TSDBStatus, error) - // DeleteMetrics deletes metrics matching the given tfss. - DeleteMetrics(qt *querytracer.Tracer, tfss []*storage.TagFilters, maxMetrics int, deadline uint64) (int, error) + // DeleteSeries deletes series matching the given tfss. + DeleteSeries(qt *querytracer.Tracer, tfss []*storage.TagFilters, maxMetrics int, deadline uint64) (int, error) // RegisterMetricNames registers the given mrs in the storage. RegisterMetricNames(qt *querytracer.Tracer, mrs []storage.MetricRow) error diff --git a/lib/vmselectapi/server.go b/lib/vmselectapi/server.go index 58aa58878d..6d2f3a10be 100644 --- a/lib/vmselectapi/server.go +++ b/lib/vmselectapi/server.go @@ -51,7 +51,7 @@ type Server struct { indexSearchDuration *metrics.Histogram registerMetricNamesRequests *metrics.Counter - deleteMetricsRequests *metrics.Counter + deleteSeriesRequests *metrics.Counter labelNamesRequests *metrics.Counter labelValuesRequests *metrics.Counter tagValueSuffixesRequests *metrics.Counter @@ -98,7 +98,7 @@ func NewServer(addr string, api API, limits Limits, disableResponseCompression b indexSearchDuration: metrics.NewHistogram(fmt.Sprintf(`vm_index_search_duration_seconds{addr=%q}`, addr)), registerMetricNamesRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="registerMetricNames",addr=%q}`, addr)), - deleteMetricsRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="deleteMetrics",addr=%q}`, addr)), + deleteSeriesRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="deleteSeries",addr=%q}`, addr)), labelNamesRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="labelNames",addr=%q}`, addr)), labelValuesRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="labelValues",addr=%q}`, addr)), tagValueSuffixesRequests: metrics.NewCounter(fmt.Sprintf(`vm_vmselect_rpc_requests_total{action="tagValueSuffixes",addr=%q}`, addr)), @@ -488,8 +488,8 @@ func (s *Server) processRPC(ctx *vmselectRequestCtx, rpcName string) error { return s.processSeriesCount(ctx) case "tsdbStatus_v5": return s.processTSDBStatus(ctx) - case "deleteMetrics_v5": - return s.processDeleteMetrics(ctx) + case "deleteSeries_v5": + return s.processDeleteSeries(ctx) case "registerMetricNames_v3": return s.processRegisterMetricNames(ctx) default: @@ -537,8 +537,8 @@ func (s *Server) processRegisterMetricNames(ctx *vmselectRequestCtx) error { return nil } -func (s *Server) processDeleteMetrics(ctx *vmselectRequestCtx) error { - s.deleteMetricsRequests.Inc() +func (s *Server) processDeleteSeries(ctx *vmselectRequestCtx) error { + s.deleteSeriesRequests.Inc() // Read request if err := ctx.readSearchQuery(); err != nil { @@ -555,7 +555,7 @@ func (s *Server) processDeleteMetrics(ctx *vmselectRequestCtx) error { if err != nil { return ctx.writeErrorMessage(err) } - deletedCount, err := s.api.DeleteMetrics(ctx.qt, tfss, maxMetrics, ctx.deadline) + deletedCount, err := s.api.DeleteSeries(ctx.qt, tfss, maxMetrics, ctx.deadline) if err != nil { return ctx.writeErrorMessage(err) }