You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/04/23 02:40:43 UTC
git commit: Added rate limiting to Metrics endpoint.
Repository: mesos
Updated Branches:
refs/heads/master 4e2d39445 -> 188143437
Added rate limiting to Metrics endpoint.
Review: https://reviews.apache.org/r/20539/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/18814343
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/18814343
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/18814343
Branch: refs/heads/master
Commit: 1881434375d66a4e861e110d5c66ec66df5f4ed6
Parents: 4e2d394
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Tue Apr 22 17:40:02 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Apr 22 17:40:06 2014 -0700
----------------------------------------------------------------------
.../libprocess/include/process/metrics/metrics.hpp | 13 ++++++++++---
3rdparty/libprocess/src/metrics/metrics.cpp | 11 +++++++++--
2 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/18814343/3rdparty/libprocess/include/process/metrics/metrics.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/metrics/metrics.hpp b/3rdparty/libprocess/include/process/metrics/metrics.hpp
index ba12727..d5176ee 100644
--- a/3rdparty/libprocess/include/process/metrics/metrics.hpp
+++ b/3rdparty/libprocess/include/process/metrics/metrics.hpp
@@ -5,6 +5,7 @@
#include <process/dispatch.hpp>
#include <process/future.hpp>
+#include <process/limiter.hpp>
#include <process/owned.hpp>
#include <process/process.hpp>
@@ -33,21 +34,27 @@ protected:
private:
static std::string help();
- MetricsProcess() : ProcessBase("metrics") {}
+ MetricsProcess()
+ : ProcessBase("metrics"),
+ limiter(2, Seconds(1))
+ {}
// Non-copyable, non-assignable.
MetricsProcess(const MetricsProcess&);
MetricsProcess& operator = (const MetricsProcess&);
Future<http::Response> snapshot(const http::Request& request);
-
- static Future<http::Response> _snapshot(
+ Future<http::Response> _snapshot(const http::Request& request);
+ static Future<http::Response> __snapshot(
const http::Request& request,
const hashmap<std::string, Future<double> >& metrics,
const hashmap<std::string, Option<Statistics<double> > >& statistics);
// The Owned<Metric> is an explicit copy of the Metric passed to 'add'.
hashmap<std::string, Owned<Metric> > metrics;
+
+ // Used to rate limit the endpoint.
+ RateLimiter limiter;
};
} // namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/18814343/3rdparty/libprocess/src/metrics/metrics.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/metrics/metrics.cpp b/3rdparty/libprocess/src/metrics/metrics.cpp
index aa35605..43c6055 100644
--- a/3rdparty/libprocess/src/metrics/metrics.cpp
+++ b/3rdparty/libprocess/src/metrics/metrics.cpp
@@ -80,6 +80,13 @@ Future<Nothing> MetricsProcess::remove(const std::string& name)
Future<http::Response> MetricsProcess::snapshot(const http::Request& request)
{
+ return limiter.acquire()
+ .then(defer(self(), &Self::_snapshot, request));
+}
+
+
+Future<http::Response> MetricsProcess::_snapshot(const http::Request& request)
+{
hashmap<string, Future<double> > futures;
hashmap<string, Option<Statistics<double> > > statistics;
@@ -91,11 +98,11 @@ Future<http::Response> MetricsProcess::snapshot(const http::Request& request)
}
return await(futures.values())
- .then(lambda::bind(_snapshot, request, futures, statistics));
+ .then(lambda::bind(__snapshot, request, futures, statistics));
}
-Future<http::Response> MetricsProcess::_snapshot(
+Future<http::Response> MetricsProcess::__snapshot(
const http::Request& request,
const hashmap<string, Future<double> >& metrics,
const hashmap<string, Option<Statistics<double> > >& statistics)