From 4ecc370acb541447739e4c2c72e2d7179a650bd9 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Wed, 28 Aug 2024 11:14:28 +0200 Subject: [PATCH] lib/storage: properly add previous indexDB metrics (#6890) Previously, some extIndexDB metrics were not registered. It resulted into missing metrics, if metric value was added to the extIndexDB. It's a usual case for search requests at both indexes. Current commit updates all metrics from extIndexDB according to the current IndexDB. It must fix such cases Related issue: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6868 ### Describe Your Changes Please provide a brief description of the changes you made. Be as specific as possible to help others understand the purpose and impact of your modifications. ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --- docs/changelog/CHANGELOG.md | 1 + lib/storage/index_db.go | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/docs/changelog/CHANGELOG.md b/docs/changelog/CHANGELOG.md index 10f989cbd7..e3ac239bac 100644 --- a/docs/changelog/CHANGELOG.md +++ b/docs/changelog/CHANGELOG.md @@ -46,6 +46,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert/), [vmctl](https://docs.victoriametrics.com/vmctl/) and snapshot API: verify correctness of URLs provided via cmd-line flags before executing HTTP requests. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6740) issue for details. * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert): reduce memory usage when parsing responses with big number of metrics in response. The memory usage was increased in [v1.102.0-rc1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.102.0-rc1) after attempt to reduce CPU usage for heavy loaded vmalerts. * BUGFIX: all VictoriaMetrics components: forcefully set owner/group for release tars to 1000:1000. This helps to avoid unpacking [issues](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6788) on systems with limitations around UID:GID configuration. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6846). +* BUGFIX: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): properly register index metrics for previous index part. See this [issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6868) for details. * BUGFIX: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): Removes the fallback to global index search when the search using per-day index fails due to too many time series found (the global index will fail anyway with the same error and so the fallback is not needed and only slows down the search). See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6836) for details. * BUGFIX: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): fix metric names registering in the per-day index for new dates for existing time series when making calls to `/tags/tagSeries` and `/tags/tagMultiSeries` handlers of [Grpahite API](https://docs.victoriametrics.com/#graphite-api-usage). See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6872/) for details. diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 1381ddbc02..3a37ebb541 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -203,6 +203,16 @@ func (db *indexDB) scheduleToDrop() { // UpdateMetrics updates m with metrics from the db. func (db *indexDB) UpdateMetrics(m *IndexDBMetrics) { + // global index metrics + m.DeletedMetricsCount += uint64(db.s.getDeletedMetricIDs().Len()) + + m.IndexBlocksWithMetricIDsProcessed = indexBlocksWithMetricIDsProcessed.Load() + m.IndexBlocksWithMetricIDsIncorrectOrder = indexBlocksWithMetricIDsIncorrectOrder.Load() + + m.MinTimestampForCompositeIndex = uint64(db.s.minTimestampForCompositeIndex) + m.CompositeFilterSuccessConversions = compositeFilterSuccessConversions.Load() + m.CompositeFilterMissingConversions = compositeFilterMissingConversions.Load() + var cs fastcache.Stats cs.Reset() @@ -213,8 +223,6 @@ func (db *indexDB) UpdateMetrics(m *IndexDBMetrics) { m.TagFiltersToMetricIDsCacheRequests += cs.GetCalls m.TagFiltersToMetricIDsCacheMisses += cs.Misses - m.DeletedMetricsCount += uint64(db.s.getDeletedMetricIDs().Len()) - m.IndexDBRefCount += uint64(db.refCount.Load()) m.MissingTSIDsForMetricID += db.missingTSIDsForMetricID.Load() @@ -224,16 +232,26 @@ func (db *indexDB) UpdateMetrics(m *IndexDBMetrics) { m.MissingMetricNamesForMetricID += db.missingMetricNamesForMetricID.Load() - m.IndexBlocksWithMetricIDsProcessed = indexBlocksWithMetricIDsProcessed.Load() - m.IndexBlocksWithMetricIDsIncorrectOrder = indexBlocksWithMetricIDsIncorrectOrder.Load() - - m.MinTimestampForCompositeIndex = uint64(db.s.minTimestampForCompositeIndex) - m.CompositeFilterSuccessConversions = compositeFilterSuccessConversions.Load() - m.CompositeFilterMissingConversions = compositeFilterMissingConversions.Load() - db.tb.UpdateMetrics(&m.TableMetrics) db.doExtDB(func(extDB *indexDB) { extDB.tb.UpdateMetrics(&m.TableMetrics) + + cs.Reset() + extDB.tagFiltersToMetricIDsCache.UpdateStats(&cs) + m.TagFiltersToMetricIDsCacheSize += cs.EntriesCount + m.TagFiltersToMetricIDsCacheSizeBytes += cs.BytesSize + m.TagFiltersToMetricIDsCacheSizeMaxBytes += cs.MaxBytesSize + m.TagFiltersToMetricIDsCacheRequests += cs.GetCalls + m.TagFiltersToMetricIDsCacheMisses += cs.Misses + + m.IndexDBRefCount += uint64(extDB.refCount.Load()) + m.MissingTSIDsForMetricID += extDB.missingTSIDsForMetricID.Load() + + m.DateRangeSearchCalls += extDB.dateRangeSearchCalls.Load() + m.DateRangeSearchHits += extDB.dateRangeSearchHits.Load() + m.GlobalSearchCalls += extDB.globalSearchCalls.Load() + + m.MissingMetricNamesForMetricID += extDB.missingMetricNamesForMetricID.Load() m.IndexDBRefCount += uint64(extDB.refCount.Load()) }) } @@ -3321,6 +3339,7 @@ func (s uint64Sorter) Len() int { return len(s) } func (s uint64Sorter) Less(i, j int) bool { return s[i] < s[j] } + func (s uint64Sorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }