aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/documentdb_metrics_updater.h
blob: 069bd47f0e341e57ec60cbbeb96f60518ea27903 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "feed_handler_stats.h"
#include <vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h>
#include <vespa/vespalib/stllike/cache_stats.h>
#include <optional>

namespace proton {

class AttributeUsageFilter;
class DDBState;
class DocumentDBJobTrackers;
class DocumentSubDBCollection;
class ExecutorThreadingService;
class ExecutorThreadingServiceStats;
class FeedHandler;

/**
 * Class used to update metrics for a document db.
 */
class DocumentDBMetricsUpdater {
public:

    struct DocumentStoreCacheStats {
        vespalib::CacheStats readySubDb;
        vespalib::CacheStats notReadySubDb;
        vespalib::CacheStats removedSubDb;
        DocumentStoreCacheStats() : readySubDb(), notReadySubDb(), removedSubDb() {}
    };

private:
    const DocumentSubDBCollection &_subDBs;
    ExecutorThreadingService      &_writeService;
    DocumentDBJobTrackers         &_jobTrackers;
    const AttributeUsageFilter    &_writeFilter;
    FeedHandler                   &_feed_handler;
    // Last updated document store cache statistics. Necessary due to metrics implementation is upside down.
    DocumentStoreCacheStats        _lastDocStoreCacheStats;
    std::optional<FeedHandlerStats> _last_feed_handler_stats;

    void updateMiscMetrics(DocumentDBTaggedMetrics &metrics, const ExecutorThreadingServiceStats &threadingServiceStats);
    void updateAttributeResourceUsageMetrics(DocumentDBTaggedMetrics::AttributeMetrics &metrics);

public:
    DocumentDBMetricsUpdater(const DocumentSubDBCollection &subDBs,
                             ExecutorThreadingService &writeService,
                             DocumentDBJobTrackers &jobTrackers,
                             const AttributeUsageFilter &writeFilter,
                             FeedHandler& feed_handler);
    ~DocumentDBMetricsUpdater();

    void updateMetrics(const metrics::MetricLockGuard & guard, DocumentDBTaggedMetrics &metrics);

};

}