Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
deb76f8
Add ability to filter stats to be flushed to sinks.
pradeepcrao Oct 27, 2021
6215133
Merge remote-tracking branch 'upstream/main' into stats_filter2
pradeepcrao Oct 27, 2021
5c593e3
Merge remote-tracking branch 'upstream/main' into stats_filter2
pradeepcrao Oct 27, 2021
e0f6a99
Add tests for histograms.
pradeepcrao Nov 9, 2021
58d423a
Merge remote-tracking branch 'upstream/main' into stats_filter2
pradeepcrao Nov 9, 2021
d82fb8f
Fix format.
pradeepcrao Nov 9, 2021
b8c7472
Merge remote-tracking branch 'upstream/main' into stats_filter2
pradeepcrao Nov 9, 2021
6f0eecc
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Dec 1, 2021
0a95f77
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Dec 1, 2021
5798431
Fix tests.
pradeepcrao Dec 1, 2021
155447b
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Dec 1, 2021
b430e67
Add tests.
pradeepcrao Dec 2, 2021
2544e4f
Address feedback.
pradeepcrao Jan 4, 2022
2376924
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 4, 2022
560a6f9
Fix test.
pradeepcrao Jan 19, 2022
bb2de6e
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 19, 2022
eb89117
Add method to get sink predicates from StoreRoot.
pradeepcrao Jan 20, 2022
3394bf9
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 20, 2022
9ae13c6
Fix Format.
pradeepcrao Jan 20, 2022
f68aa44
Address feedback.
pradeepcrao Jan 20, 2022
9a85185
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 20, 2022
e05a2af
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Oct 28, 2022
0af4da8
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Oct 28, 2022
8782f8f
Test memory increase for histograms with sink predicates
pradeepcrao Jan 20, 2022
b69e73c
Modify test.
pradeepcrao Nov 1, 2022
240f8d6
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 1, 2022
ea50616
Add runtime feature guard for includeHistograms
pradeepcrao Nov 2, 2022
a367aa6
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 2, 2022
d7363ce
Fix test.
pradeepcrao Nov 4, 2022
14b5b00
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 4, 2022
169d606
Address feedback.
pradeepcrao Nov 9, 2022
8bb64be
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 9, 2022
d73b86a
Address Feedback.
pradeepcrao Nov 10, 2022
41aa92a
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 10, 2022
d6e7ac2
Add release note.
pradeepcrao Nov 10, 2022
d591fe6
Fix CI.
pradeepcrao Nov 10, 2022
179c993
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Nov 10, 2022
68fd78d
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 4, 2023
2b3f79a
Fix failure.
pradeepcrao Jan 6, 2023
9df5736
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 6, 2023
bd123a2
Merge remote-tracking branch 'upstream/main' into histograms
pradeepcrao Jan 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ new_features:
- area: tracing
change: |
added support for setting the hostname used when sending spans to a Datadog collector using the :ref:`collector_hostname <envoy_v3_api_field_config.trace.v3.DatadogConfig.collector_hostname>` field.
- area: stats
change: |
added ``includeHistogram()`` method to ``Stats::SinkPredicates`` to filter histograms to be flushed to stat sinks. Use ``envoy.reloadable_features.enable_include_histograms`` to enable this feature, which is disabled by default.
- area: http
change: |
added support of :ref:`early header mutation <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.early_header_mutation_extensions>` to the HTTP connection manager.
Expand Down
2 changes: 1 addition & 1 deletion envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Instance {
virtual bool enableReusePortDefault() PURE;

/**
* Set predicates for filtering counters, gauges and text readouts to be flushed to sinks.
* Set predicates for filtering stats to be flushed to sinks.
*/
virtual void
setSinkPredicates(std::unique_ptr<Envoy::Stats::SinkPredicates>&& sink_predicates) PURE;
Expand Down
2 changes: 1 addition & 1 deletion envoy/stats/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Allocator {
virtual void forEachSinkedTextReadout(SizeFn f_size, StatFn<TextReadout> f_stat) const PURE;

/**
* Set the predicates to filter counters, gauges and text readouts for sink.
* Set the predicates to filter stats for sink.
*/
virtual void setSinkPredicates(std::unique_ptr<SinkPredicates>&& sink_predicates) PURE;

Expand Down
7 changes: 7 additions & 0 deletions envoy/stats/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class SinkPredicates {
* @return true if @param text_readout needs to be flushed to sinks.
*/
virtual bool includeTextReadout(const TextReadout& text_readout) PURE;

/*
* @return true if @param histogram needs to be flushed to sinks.
* Note that this is used only if runtime flag envoy.reloadable_features.enable_include_histograms
* (which is false by default) is set to true.
*/
virtual bool includeHistogram(const Histogram& histogram) PURE;
};

/**
Expand Down
6 changes: 5 additions & 1 deletion envoy/stats/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <memory>
#include <vector>

#include "envoy/common/optref.h"
#include "envoy/common/pure.h"
#include "envoy/stats/histogram.h"
#include "envoy/stats/scope.h"
Expand Down Expand Up @@ -136,6 +137,7 @@ class Store {
virtual void forEachSinkedCounter(SizeFn f_size, StatFn<Counter> f_stat) const PURE;
virtual void forEachSinkedGauge(SizeFn f_size, StatFn<Gauge> f_stat) const PURE;
virtual void forEachSinkedTextReadout(SizeFn f_size, StatFn<TextReadout> f_stat) const PURE;
virtual void forEachSinkedHistogram(SizeFn f_size, StatFn<ParentHistogram> f_stat) const PURE;

/**
* Calls 'fn' for every stat. Note that in the case of overlapping scopes, the
Expand Down Expand Up @@ -240,12 +242,14 @@ class StoreRoot : public Store {
virtual void mergeHistograms(PostMergeCb merge_complete_cb) PURE;

/**
* Set predicates for filtering counters, gauges and text readouts to be flushed to sinks.
* Set predicates for filtering stats to be flushed to sinks.
* Note that if the sink predicates object is set, we do not send non-sink stats over to the
* child process during hot restart. This will result in the admin stats console being wrong
* during hot restart.
*/
virtual void setSinkPredicates(std::unique_ptr<SinkPredicates>&& sink_predicates) PURE;

virtual OptRef<SinkPredicates> sinkPredicates() PURE;
};

using StoreRootPtr = std::unique_ptr<StoreRoot>;
Expand Down
2 changes: 2 additions & 0 deletions source/common/runtime/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ FALSE_RUNTIME_GUARD(envoy_reloadable_features_runtime_initialized);
FALSE_RUNTIME_GUARD(envoy_reloadable_features_always_use_v6);
// TODO(alyssawilk) remove in Q2.
FALSE_RUNTIME_GUARD(envoy_reloadable_features_no_delay_close_for_upgrades);
// TODO(pradeepcrao) reset this to true after 2 releases (1.27)
FALSE_RUNTIME_GUARD(envoy_reloadable_features_enable_include_histograms);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a FALSE_RUNTIME_GUARD instead of a RUNTIME_GUARD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disables filtering the histograms by default, so envoy users using sink predicates will not experience histograms silently not being flushed to sinks.


// Block of non-boolean flags. These are deprecated. Do not add more.
ABSL_FLAG(uint64_t, envoy_headermap_lazy_map_min_size, 3, ""); // NOLINT
Expand Down
5 changes: 5 additions & 0 deletions source/common/stats/isolated_store_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ class IsolatedStoreImpl : public Store {
forEachTextReadout(f_size, f_stat);
}

void forEachSinkedHistogram(SizeFn f_size, StatFn<ParentHistogram> f_stat) const override {
UNREFERENCED_PARAMETER(f_size);
UNREFERENCED_PARAMETER(f_stat);
}

NullCounterImpl& nullCounter() override { return *null_counter_; }
NullGaugeImpl& nullGauge() override { return *null_gauge_; }

Expand Down
33 changes: 33 additions & 0 deletions source/common/stats/thread_local_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "envoy/stats/stats.h"

#include "source/common/common/lock_guard.h"
#include "source/common/runtime/runtime_features.h"
#include "source/common/stats/histogram_impl.h"
#include "source/common/stats/stats_matcher_impl.h"
#include "source/common/stats/tag_producer_impl.h"
Expand Down Expand Up @@ -95,6 +96,7 @@ void ThreadLocalStoreImpl::setStatsMatcher(StatsMatcherPtr&& stats_matcher) {
for (uint32_t i = first_histogram_index; i < deleted_histograms_.size(); ++i) {
uint32_t erased = histogram_set_.erase(deleted_histograms_[i].get());
ASSERT(erased == 1);
sinked_histograms_.erase(deleted_histograms_[i].get());
}
}
}
Expand Down Expand Up @@ -225,6 +227,7 @@ void ThreadLocalStoreImpl::shutdownThreading() {
histogram->setShuttingDown(true);
}
histogram_set_.clear();
sinked_histograms_.clear();
}

void ThreadLocalStoreImpl::mergeHistograms(PostMergeCb merge_complete_cb) {
Expand Down Expand Up @@ -678,6 +681,10 @@ Histogram& ThreadLocalStoreImpl::ScopeImpl::histogramFromStatNameWithTags(
*buckets, parent_.next_histogram_id_++);
if (!parent_.shutting_down_) {
parent_.histogram_set_.insert(stat.get());
if (parent_.sink_predicates_.has_value() &&
parent_.sink_predicates_->includeHistogram(*stat)) {
parent_.sinked_histograms_.insert(stat.get());
}
}
}
}
Expand Down Expand Up @@ -877,6 +884,7 @@ bool ThreadLocalStoreImpl::decHistogramRefCount(ParentHistogramImpl& hist,
if (!shutting_down_) {
const size_t count = histogram_set_.erase(hist.statName());
ASSERT(shutting_down_ || count == 1);
sinked_histograms_.erase(&hist);
}
return true;
}
Expand Down Expand Up @@ -1034,11 +1042,36 @@ void ThreadLocalStoreImpl::forEachSinkedTextReadout(SizeFn f_size,
alloc_.forEachSinkedTextReadout(f_size, f_stat);
}

void ThreadLocalStoreImpl::forEachSinkedHistogram(SizeFn f_size,
StatFn<ParentHistogram> f_stat) const {
if (sink_predicates_.has_value() &&
Runtime::runtimeFeatureEnabled("envoy.reloadable_features.enable_include_histograms")) {
Thread::LockGuard lock(hist_mutex_);

if (f_size != nullptr) {
f_size(sinked_histograms_.size());
}
for (auto histogram : sinked_histograms_) {
f_stat(*histogram);
}
} else {
forEachHistogram(f_size, f_stat);
}
}

void ThreadLocalStoreImpl::setSinkPredicates(std::unique_ptr<SinkPredicates>&& sink_predicates) {
ASSERT(sink_predicates != nullptr);
if (sink_predicates != nullptr) {
sink_predicates_.emplace(*sink_predicates);
alloc_.setSinkPredicates(std::move(sink_predicates));
// Add histograms to the set of sinked histograms.
Thread::LockGuard lock(hist_mutex_);
sinked_histograms_.clear();
for (auto& histogram : histogram_set_) {
if (sink_predicates_->includeHistogram(*histogram)) {
sinked_histograms_.insert(histogram);
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions source/common/stats/thread_local_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo
void forEachSinkedCounter(SizeFn f_size, StatFn<Counter> f_stat) const override;
void forEachSinkedGauge(SizeFn f_size, StatFn<Gauge> f_stat) const override;
void forEachSinkedTextReadout(SizeFn f_size, StatFn<TextReadout> f_stat) const override;
void forEachSinkedHistogram(SizeFn f_size, StatFn<ParentHistogram> f_stat) const override;

void setSinkPredicates(std::unique_ptr<SinkPredicates>&& sink_predicates) override;
OptRef<SinkPredicates> sinkPredicates() override { return sink_predicates_; }

/**
* @return a thread synchronizer object used for controlling thread behavior in tests.
Expand Down Expand Up @@ -519,6 +521,7 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo

mutable Thread::MutexBasicLockable hist_mutex_;
StatSet<ParentHistogramImpl> histogram_set_ ABSL_GUARDED_BY(hist_mutex_);
StatSet<ParentHistogramImpl> sinked_histograms_ ABSL_GUARDED_BY(hist_mutex_);

// Retain storage for deleted stats; these are no longer in maps because the
// matcher-pattern was established after they were created. Since the stats
Expand Down
2 changes: 1 addition & 1 deletion source/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ MetricSnapshotImpl::MetricSnapshotImpl(Stats::Store& store, TimeSource& time_sou
gauges_.push_back(gauge);
});

store.forEachHistogram(
store.forEachSinkedHistogram(
[this](std::size_t size) {
snapped_histograms_.reserve(size);
histograms_.reserve(size);
Expand Down
1 change: 1 addition & 0 deletions test/common/stats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ envoy_cc_test(
deps = [
":stat_test_utility_lib",
"//source/common/memory:stats_lib",
"//source/common/runtime:runtime_lib",
"//source/common/stats:stats_matcher_lib",
"//source/common/stats:thread_local_store_lib",
"//source/common/thread_local:thread_local_lib",
Expand Down
Loading