From 840fac9ba2f7aae64751d26072449ce47e2b2cf6 Mon Sep 17 00:00:00 2001 From: Bastrykov Evgeniy Date: Thu, 23 Oct 2025 11:11:31 +0400 Subject: [PATCH 1/7] Improve binary permissions --- werf.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/werf.yaml b/werf.yaml index efdf0fc3f..f00230089 100644 --- a/werf.yaml +++ b/werf.yaml @@ -128,9 +128,9 @@ shell: - chown -R 64535:64535 /src/ - chown -R 64535:64535 /etc/ - chown -R 64535:64535 /consoles/ - - chmod 0700 /src/prometheus - - chmod 0700 /src/promtool - - chmod 0700 /src/prompptool + - chmod 0755 /src/prometheus + - chmod 0755 /src/promtool + - chmod 0755 /src/prompptool - | touch /bin/prompp ln -s /bin/prompp /bin/prometheus From 460a3b169a9eca2b0a253f94a5bf10e662f44bfa Mon Sep 17 00:00:00 2001 From: Gleb Shigin Date: Mon, 20 Oct 2025 19:17:19 +0300 Subject: [PATCH 2/7] fix lss copy to keep label_set_id order --- pp/bare_bones/memory.h | 1 + pp/series_index/queryable_encoding_bimap.h | 12 +++--------- pp/series_index/sorting_index.h | 4 ++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pp/bare_bones/memory.h b/pp/bare_bones/memory.h index ca8642acc..2002d2235 100644 --- a/pp/bare_bones/memory.h +++ b/pp/bare_bones/memory.h @@ -2,6 +2,7 @@ #include #include +#include #include "preprocess.h" #include "type_traits.h" diff --git a/pp/series_index/queryable_encoding_bimap.h b/pp/series_index/queryable_encoding_bimap.h index 06c06a273..68ab8a425 100644 --- a/pp/series_index/queryable_encoding_bimap.h +++ b/pp/series_index/queryable_encoding_bimap.h @@ -186,25 +186,20 @@ class QueryableEncodingBimapCopier { } void copy_added_series() { - BareBones::Vector ids; - ids.reserve(source_.size()); - std::ranges::copy(ls_id_range_.begin(), ls_id_range_.end(), std::back_inserter(ids)); - - sorting_index_.sort(ids); - Cache cache; cache.reserve(source_.data().label_name_sets_table.size(), source_.data().label_name_sets_table.data().symbols_table.size(), source_.data().symbols_tables); destination_.reserve(source_); - for (const auto ls_id : ids) { + for (const auto ls_id : ls_id_range_) { destination_.items_.emplace_back(destination_.data_, source_[ls_id], cache); } } void copy_ls_id_set() { + auto cmp = sorting_index_.get_comparator(); for (uint32_t ls_id_new = 0; ls_id_new < destination_.size(); ++ls_id_new) { - destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [&](auto, auto) { return true; }, ls_id_new); + destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [&](auto a, auto b) { return cmp(ls_id_range_[a], ls_id_range_[b]); }, ls_id_new); } } @@ -255,5 +250,4 @@ class QueryableEncodingBimapCopier { QueryableEncodingBimap& destination_; const SeriesIds& ls_id_range_; }; - } // namespace series_index diff --git a/pp/series_index/sorting_index.h b/pp/series_index/sorting_index.h index 6ecb17cdd..6906e22ce 100644 --- a/pp/series_index/sorting_index.h +++ b/pp/series_index/sorting_index.h @@ -29,6 +29,10 @@ struct SortingIndex { sort(container.begin(), container.end()); } + PROMPP_ALWAYS_INLINE auto get_comparator() const noexcept { + return [this](uint32_t a, uint32_t b) PROMPP_LAMBDA_INLINE { return index[a] < index[b]; }; + } + Vector index; }; From 47c9e2133be09f654b0591384a72454fd9af6501 Mon Sep 17 00:00:00 2001 From: Gleb Shigin Date: Mon, 20 Oct 2025 19:49:42 +0300 Subject: [PATCH 3/7] time optimization --- pp/series_index/queryable_encoding_bimap.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pp/series_index/queryable_encoding_bimap.h b/pp/series_index/queryable_encoding_bimap.h index 68ab8a425..9af52ea8c 100644 --- a/pp/series_index/queryable_encoding_bimap.h +++ b/pp/series_index/queryable_encoding_bimap.h @@ -198,8 +198,18 @@ class QueryableEncodingBimapCopier { void copy_ls_id_set() { auto cmp = sorting_index_.get_comparator(); - for (uint32_t ls_id_new = 0; ls_id_new < destination_.size(); ++ls_id_new) { - destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [&](auto a, auto b) { return cmp(ls_id_range_[a], ls_id_range_[b]); }, ls_id_new); + + BareBones::Vector ids_new(destination_.size()); + std::ranges::iota(ids_new, 0u); + + BareBones::Vector ids_old; + ids_old.reserve(destination_.size()); + std::ranges::copy(ls_id_range_.begin(), ls_id_range_.end(), std::back_inserter(ids_old)); + + std::ranges::sort(ids_new, [&](auto a, auto b) { return cmp(ids_old[a], ids_old[b]); }); + + for (uint32_t ls_id_new : ids_new) { + destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [](auto, auto) { return true; }, ls_id_new); } } From c02555c1c417909ce32b77ae40a99d5f66d833c6 Mon Sep 17 00:00:00 2001 From: Gleb Shigin Date: Mon, 20 Oct 2025 20:08:33 +0300 Subject: [PATCH 4/7] ref --- pp/series_index/queryable_encoding_bimap.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pp/series_index/queryable_encoding_bimap.h b/pp/series_index/queryable_encoding_bimap.h index 9af52ea8c..fc81dfe9e 100644 --- a/pp/series_index/queryable_encoding_bimap.h +++ b/pp/series_index/queryable_encoding_bimap.h @@ -202,9 +202,8 @@ class QueryableEncodingBimapCopier { BareBones::Vector ids_new(destination_.size()); std::ranges::iota(ids_new, 0u); - BareBones::Vector ids_old; - ids_old.reserve(destination_.size()); - std::ranges::copy(ls_id_range_.begin(), ls_id_range_.end(), std::back_inserter(ids_old)); + BareBones::Vector ids_old(destination_.size()); + std::ranges::copy(ls_id_range_.begin(), ls_id_range_.end(), ids_old.begin()); std::ranges::sort(ids_new, [&](auto a, auto b) { return cmp(ids_old[a], ids_old[b]); }); From d61d44c454f3ecec7e8d19abe0561f7a56282046 Mon Sep 17 00:00:00 2001 From: Alexandr Yudin Date: Tue, 21 Oct 2025 10:07:26 +0000 Subject: [PATCH 5/7] fix test --- pp/go/cppbridge/primitives_lss_test.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pp/go/cppbridge/primitives_lss_test.go b/pp/go/cppbridge/primitives_lss_test.go index 07918d903..7e43443d3 100644 --- a/pp/go/cppbridge/primitives_lss_test.go +++ b/pp/go/cppbridge/primitives_lss_test.go @@ -3,7 +3,6 @@ package cppbridge_test import ( "context" "runtime" - "sort" "testing" "github.com/prometheus/prometheus/pp/go/model" @@ -414,15 +413,9 @@ func (s *QueryableLSSSuite) TestCopyAddedSeries() { s.lss.CopyAddedSeries(lssCopy) lssCopy.CopyAddedSeries(lssCopyOfCopy) - // lssCopy will contain lexicographically sorted labels with new IDs. - expectedLabelSets := make([]model.LabelSet, len(s.labelSets)) - copy(expectedLabelSets, s.labelSets) - sort.Slice(expectedLabelSets, func(i, j int) bool { - return expectedLabelSets[i].String() < expectedLabelSets[j].String() - }) - // Assert - s.Equal(labelSetToCppBridgeLabels(expectedLabelSets), lssCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) + // !!!ATTENTION!!! When copying the added series, the order in which the series are added is preserved. + s.Equal(labelSetToCppBridgeLabels(s.labelSets), lssCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) s.Equal(emptyLabelsSets, lssCopyOfCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) } @@ -502,14 +495,8 @@ func (s *QueryableLSSSuite) TestCopyAddedSeriesFromSnapshot() { bitsetSeriesCopy := lssCopy.BitsetSeries() snapshotCopy.CopyAddedSeries(bitsetSeriesCopy, lssCopyOfCopy) - // lssCopy will contain lexicographically sorted labels with new IDs. - expectedLabelSets := make([]model.LabelSet, len(s.labelSets)) - copy(expectedLabelSets, s.labelSets) - sort.Slice(expectedLabelSets, func(i, j int) bool { - return expectedLabelSets[i].String() < expectedLabelSets[j].String() - }) - // Assert - s.Equal(labelSetToCppBridgeLabels(expectedLabelSets), lssCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) + // !!!ATTENTION!!! When copying the added series, the order in which the series are added is preserved. + s.Equal(labelSetToCppBridgeLabels(s.labelSets), lssCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) s.Equal(emptyLabelsSets, lssCopyOfCopy.GetLabelSets(s.labelSetIDs).LabelsSets()) } From 962cd8b7db82ce40bae0fa1227fe6b9338d3e202 Mon Sep 17 00:00:00 2001 From: Gleb Shigin Date: Tue, 21 Oct 2025 13:42:38 +0300 Subject: [PATCH 6/7] time optimization --- pp/series_index/queryable_encoding_bimap.h | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pp/series_index/queryable_encoding_bimap.h b/pp/series_index/queryable_encoding_bimap.h index fc81dfe9e..1ce759d57 100644 --- a/pp/series_index/queryable_encoding_bimap.h +++ b/pp/series_index/queryable_encoding_bimap.h @@ -197,18 +197,21 @@ class QueryableEncodingBimapCopier { } void copy_ls_id_set() { - auto cmp = sorting_index_.get_comparator(); - - BareBones::Vector ids_new(destination_.size()); - std::ranges::iota(ids_new, 0u); - - BareBones::Vector ids_old(destination_.size()); - std::ranges::copy(ls_id_range_.begin(), ls_id_range_.end(), ids_old.begin()); + struct id_pair { + uint32_t old_id; + uint32_t new_id; + }; + const auto cmp = sorting_index_.get_comparator(); + + BareBones::Vector vec(destination_.size()); + for (uint32_t new_id = 0; const auto old_id : ls_id_range_) { + vec[new_id] = {old_id, new_id++}; + } - std::ranges::sort(ids_new, [&](auto a, auto b) { return cmp(ids_old[a], ids_old[b]); }); + std::sort(vec.begin(), vec.end(), [&](const id_pair& a, const id_pair& b) { return cmp(a.old_id, b.old_id); }); - for (uint32_t ls_id_new : ids_new) { - destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [](auto, auto) { return true; }, ls_id_new); + for (const auto& p : vec) { + destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [](auto, auto) { return true; }, p.new_id); } } From f849a54786dab2fdd301e2b468f5dee7f245273e Mon Sep 17 00:00:00 2001 From: Gleb Shigin Date: Tue, 21 Oct 2025 16:13:05 +0300 Subject: [PATCH 7/7] move building id map to copy_added_series() --- pp/series_index/queryable_encoding_bimap.h | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pp/series_index/queryable_encoding_bimap.h b/pp/series_index/queryable_encoding_bimap.h index 1ce759d57..b709619ca 100644 --- a/pp/series_index/queryable_encoding_bimap.h +++ b/pp/series_index/queryable_encoding_bimap.h @@ -186,31 +186,25 @@ class QueryableEncodingBimapCopier { } void copy_added_series() { + old_new_ids_.clear(); + old_new_ids_.reserve(source_.size()); + Cache cache; cache.reserve(source_.data().label_name_sets_table.size(), source_.data().label_name_sets_table.data().symbols_table.size(), source_.data().symbols_tables); destination_.reserve(source_); for (const auto ls_id : ls_id_range_) { + old_new_ids_.emplace_back(ls_id, destination_.next_item_index()); destination_.items_.emplace_back(destination_.data_, source_[ls_id], cache); } - } - void copy_ls_id_set() { - struct id_pair { - uint32_t old_id; - uint32_t new_id; - }; const auto cmp = sorting_index_.get_comparator(); + std::sort(old_new_ids_.begin(), old_new_ids_.end(), [&](const id_pair& a, const id_pair& b) { return cmp(a.old_id, b.old_id); }); + } - BareBones::Vector vec(destination_.size()); - for (uint32_t new_id = 0; const auto old_id : ls_id_range_) { - vec[new_id] = {old_id, new_id++}; - } - - std::sort(vec.begin(), vec.end(), [&](const id_pair& a, const id_pair& b) { return cmp(a.old_id, b.old_id); }); - - for (const auto& p : vec) { + void copy_ls_id_set() { + for (const auto& p : old_new_ids_) { destination_.ls_id_set_.emplace_hint_cmp(destination_.ls_id_set_.end(), [](auto, auto) { return true; }, p.new_id); } } @@ -257,9 +251,15 @@ class QueryableEncodingBimapCopier { } private: + struct id_pair { + uint32_t old_id; + uint32_t new_id; + }; + const DecodingTable& source_; const SortingIndex& sorting_index_; QueryableEncodingBimap& destination_; const SeriesIds& ls_id_range_; + BareBones::Vector old_new_ids_; }; } // namespace series_index