diff options
author | HÃ¥vard Pettersen <havardpe@gmail.com> | 2018-10-09 13:34:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-09 13:34:53 +0200 |
commit | f1d5c7a8430878d8dc9463492088072b80e07888 (patch) | |
tree | 6e7c2fbe925319460e9d683d70c59a267e74d4ac /staging_vespalib/src | |
parent | fe7cf83978f086de32a03e88d91e6cc0277394f0 (diff) | |
parent | 37107f146f6b43af19fb3152075b1117f047d592 (diff) |
Merge pull request #7240 from vespa-engine/arnej/lose-awkward-name
Arnej/lose awkward name
Diffstat (limited to 'staging_vespalib/src')
14 files changed, 42 insertions, 76 deletions
diff --git a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp index 7ef57415416..03ed9dc2cf7 100644 --- a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp +++ b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp @@ -15,7 +15,7 @@ using namespace vespalib::metrics; TEST("require that simple metrics gauge merge works") { - MetricPointId id(MetricId(42), Point(17)); + std::pair<MetricId, Point> id(MetricId(42), Point(17)); Gauge::Measurement a1(id, 0.0); Gauge::Measurement b1(id, 7.0); Gauge::Measurement b2(id, 9.0); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt index 5112286b359..6015ea8c621 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt @@ -13,7 +13,6 @@ vespa_add_library(staging_vespalib_vespalib_metrics OBJECT handle.cpp json_formatter.cpp label.cpp - metric_point_id.cpp metric_id.cpp metrics_manager.cpp metric_types.cpp diff --git a/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp b/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp index af942a48fb9..fdca2b1a9cc 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp @@ -14,12 +14,13 @@ mergeFromSamples(const StableStore<typename T::sample_type> &source) { using Aggregator = typename T::aggregator_type; using Sample = typename T::sample_type; - using Map = std::map<MetricPointId, Aggregator>; + using Key = std::pair<MetricId, Point>; + using Map = std::map<Key, Aggregator>; using MapValue = typename Map::value_type; Map map; source.for_each([&map] (const Sample &sample) { - MetricPointId id = sample.idx; + Key id = sample.idx; auto iter_check = map.emplace(id, sample); if (!iter_check.second) { iter_check.first->second.merge(sample); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/bucket.h b/staging_vespalib/src/vespa/vespalib/metrics/bucket.h index e358080b73b..a1d0dff49f3 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/bucket.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/bucket.h @@ -3,7 +3,8 @@ #include <mutex> #include "stable_store.h" -#include "metric_point_id.h" +#include "metric_id.h" +#include "point.h" #include "counter.h" #include "gauge.h" #include "clock.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp b/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp index c04a21a0020..a44fca245eb 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp @@ -10,8 +10,7 @@ void Counter::add(size_t count, Point point) const { if (_manager) { - MetricPointId fullId(_id, point); - _manager->add(Increment(fullId, count)); + _manager->add(Increment(std::make_pair(_id, point), count)); } } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter.h b/staging_vespalib/src/vespa/vespalib/metrics/counter.h index 192a08aba66..18a40b4e344 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter.h @@ -2,7 +2,7 @@ #pragma once #include <memory> -#include "metric_point_id.h" +#include "metric_id.h" #include "point.h" namespace vespalib { @@ -42,10 +42,11 @@ public: // internal struct Increment { - MetricPointId idx; + using Key = std::pair<MetricId, Point>; + Key idx; size_t value; Increment() = delete; - Increment(MetricPointId id, size_t v) : idx(id), value(v) {} + Increment(Key k, size_t v) : idx(k), value(v) {} }; typedef CounterAggregator aggregator_type; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h b/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h index e7f9ab1c9ab..4e3524f9cc8 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h @@ -1,7 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "metric_point_id.h" +#include "metric_id.h" +#include "point.h" #include "counter.h" namespace vespalib { @@ -9,7 +10,7 @@ namespace metrics { // internal struct CounterAggregator { - MetricPointId idx; + std::pair<MetricId, Point> idx; size_t count; CounterAggregator(const Counter::Increment &other); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp b/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp index f2afc87f16f..a1ab9d25078 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp @@ -9,8 +9,7 @@ void Gauge::sample(double value, Point point) const { if (_manager) { - MetricPointId fullId(_id, point); - _manager->sample(Measurement(fullId, value)); + _manager->sample(Measurement(std::make_pair(_id, point), value)); } } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h index c4542ac87e4..7eb223ecf44 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h @@ -2,7 +2,7 @@ #pragma once #include <memory> -#include "metric_point_id.h" +#include "metric_id.h" #include "point.h" namespace vespalib { @@ -32,10 +32,11 @@ public: // internal struct Measurement { - MetricPointId idx; + using Key = std::pair<MetricId, Point>; + Key idx; double value; Measurement() = delete; - Measurement(MetricPointId id, double v) : idx(id), value(v) {} + Measurement(Key k, double v) : idx(k), value(v) {} }; typedef GaugeAggregator aggregator_type; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h b/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h index ae3365bc7f0..980a68899ce 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h @@ -1,7 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "metric_point_id.h" +#include "metric_id.h" +#include "point.h" #include "gauge.h" namespace vespalib { @@ -9,7 +10,7 @@ namespace metrics { // internal struct GaugeAggregator { - MetricPointId idx; + std::pair<MetricId, Point> idx; size_t observedCount; double sumValue; double minValue; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp deleted file mode 100644 index 90ecabdb75f..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "metric_point_id.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h deleted file mode 100644 index f9d788a0f92..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include "metric_id.h" -#include "point.h" -#include <functional> - -namespace vespalib { -namespace metrics { - -/** class to use as a map key, identifying a metric and a point */ -struct MetricPointId { - const MetricId _name; - const Point _point; - - MetricPointId() = delete; - - MetricPointId(MetricId name, Point point) - : _name(name), _point(point) {} - - bool operator< (const MetricPointId &other) const { - if (_name != other._name) { - return _name < other._name; - } - return _point < other._point; - } - bool operator== (const MetricPointId &other) const { - return (_name == other._name && - _point == other._point); - } - - MetricId name() const { return _name; } - Point point() const { return _point; } - -}; - -} // namespace vespalib::metrics -} // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h index 34959146928..537b98a0618 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h @@ -13,7 +13,6 @@ #include "gauge.h" #include "json_formatter.h" #include "label.h" -#include "metric_point_id.h" #include "metric_id.h" #include "metrics_manager.h" #include "point_builder.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp index 50dd30efc5a..85cb1c8c2ca 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -51,19 +51,19 @@ SimpleMetricsManager::createForTest(const SimpleManagerConfig &config, Counter SimpleMetricsManager::counter(const vespalib::string &name, const vespalib::string &) { - MetricId mn = MetricId::from_name(name); - _metricTypes.check(mn.id(), name, MetricTypes::MetricType::COUNTER); - LOG(debug, "counter with metric name %s -> %zu", name.c_str(), mn.id()); - return Counter(shared_from_this(), mn); + MetricId mi = MetricId::from_name(name); + _metricTypes.check(mi.id(), name, MetricTypes::MetricType::COUNTER); + LOG(debug, "counter with metric name %s -> %zu", name.c_str(), mi.id()); + return Counter(shared_from_this(), mi); } Gauge SimpleMetricsManager::gauge(const vespalib::string &name, const vespalib::string &) { - MetricId mn = MetricId::from_name(name); - _metricTypes.check(mn.id(), name, MetricTypes::MetricType::GAUGE); - LOG(debug, "gauge with metric name %s -> %zu", name.c_str(), mn.id()); - return Gauge(shared_from_this(), mn); + MetricId mi = MetricId::from_name(name); + _metricTypes.check(mi.id(), name, MetricTypes::MetricType::GAUGE); + LOG(debug, "gauge with metric name %s -> %zu", name.c_str(), mi.id()); + return Gauge(shared_from_this(), mi); } Bucket @@ -101,10 +101,12 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) size_t max_point_id = 0; for (const CounterAggregator& entry : bucket.counters) { - max_point_id = std::max(max_point_id, entry.idx.point().id()); + Point p = entry.idx.second; + max_point_id = std::max(max_point_id, p.id()); } for (const GaugeAggregator& entry : bucket.gauges) { - max_point_id = std::max(max_point_id, entry.idx.point().id()); + Point p = entry.idx.second; + max_point_id = std::max(max_point_id, p.id()); } Snapshot snap(s, e); { @@ -118,16 +120,18 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) } } for (const CounterAggregator& entry : bucket.counters) { - MetricId mn = entry.idx.name(); - size_t pi = entry.idx.point().id(); - const vespalib::string &name = mn.as_name(); + MetricId mi = entry.idx.first; + Point p = entry.idx.second; + size_t pi = p.id(); + const vespalib::string &name = mi.as_name(); CounterSnapshot val(name, snap.points()[pi], entry); snap.add(val); } for (const GaugeAggregator& entry : bucket.gauges) { - MetricId mn = entry.idx.name(); - size_t pi = entry.idx.point().id(); - const vespalib::string &name = mn.as_name(); + MetricId mi = entry.idx.first; + Point p = entry.idx.second; + size_t pi = p.id(); + const vespalib::string &name = mi.as_name(); GaugeSnapshot val(name, snap.points()[pi], entry); snap.add(val); } |