aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/persistence_operation_metric_set.h
blob: ea19f77f17ffbeea172f0a7f3a5aef253868cae6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/metrics/metricset.h>
#include <vespa/metrics/countmetric.h>
#include <vespa/metrics/valuemetric.h>
#include <vespa/metrics/summetric.h>
#include <mutex>

namespace storage::api { class ReturnCode; }

namespace storage::distributor {

class PersistenceFailuresMetricSet : public metrics::MetricSet
{
public:
    explicit PersistenceFailuresMetricSet(metrics::MetricSet* owner);
    ~PersistenceFailuresMetricSet() override;

    metrics::SumMetric<metrics::LongCountMetric> sum;
    metrics::LongCountMetric notready;
    metrics::LongCountMetric notconnected;
    metrics::LongCountMetric wrongdistributor;
    metrics::LongCountMetric safe_time_not_reached;
    metrics::LongCountMetric storagefailure;
    metrics::LongCountMetric timeout;
    metrics::LongCountMetric busy;
    metrics::LongCountMetric inconsistent_bucket;
    metrics::LongCountMetric notfound;
    metrics::LongCountMetric concurrent_mutations;
    metrics::LongCountMetric test_and_set_failed;

    MetricSet * clone(std::vector<Metric::UP>& ownerList, CopyType copyType,
                      metrics::MetricSet* owner, bool includeUnused) const override;
};

class PersistenceOperationMetricSet : public metrics::MetricSet
{
    mutable std::mutex _mutex;
public:
    metrics::DoubleAverageMetric latency;
    metrics::LongCountMetric     ok;
    PersistenceFailuresMetricSet failures;

    PersistenceOperationMetricSet(const std::string& name, metrics::MetricSet* owner);
    explicit PersistenceOperationMetricSet(const std::string& name);
    ~PersistenceOperationMetricSet() override;

    MetricSet * clone(std::vector<Metric::UP>& ownerList, CopyType copyType,
                      metrics::MetricSet* owner, bool includeUnused) const override;

    /**
     * Increments appropriate success/failure count metrics based on the return
     * code provided in `result`.
     *
     * Does _not_ update latency metric.
     */
    void updateFromResult(const api::ReturnCode& result);

    class LockWrapper {
        std::unique_lock<std::mutex> _lock;
        PersistenceOperationMetricSet& _self;
    public:
        explicit LockWrapper(PersistenceOperationMetricSet& self)
            : _lock(self._mutex),
              _self(self)
        {}

        PersistenceOperationMetricSet* operator->() noexcept {
            return &_self;
        }
    };
    LockWrapper locked() noexcept {
        return LockWrapper(*this);
    }
};

}